always day, formatting
This commit is contained in:
parent
569f14bc39
commit
5bbf15458c
17 changed files with 108 additions and 102 deletions
|
@ -2,10 +2,8 @@ package me.night.nullvalkyrie;
|
|||
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import io.github.cdimascio.dotenv.Dotenv;
|
||||
import me.night.nullvalkyrie.events.listeners.CustomItemEvents;
|
||||
import me.night.nullvalkyrie.events.listeners.DamageEffectEvents;
|
||||
import me.night.nullvalkyrie.events.listeners.NPCEvents;
|
||||
import me.night.nullvalkyrie.events.listeners.ServerEvents;
|
||||
import me.night.nullvalkyrie.events.listeners.*;
|
||||
import me.night.nullvalkyrie.tasks.AlwaysDayTask;
|
||||
import me.night.nullvalkyrie.ui.inventory.InventoryListener;
|
||||
import me.night.nullvalkyrie.database.NPCDataManager;
|
||||
import me.night.nullvalkyrie.discord.DiscordClientManager;
|
||||
|
@ -17,6 +15,7 @@ import me.night.nullvalkyrie.database.DatabaseManager;
|
|||
import org.bukkit.*;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
public final class Main extends JavaPlugin {
|
||||
public static Dotenv env;
|
||||
public static MongoDatabase database;
|
||||
|
@ -30,11 +29,12 @@ public final class Main extends JavaPlugin {
|
|||
new CommandManager();
|
||||
Bukkit.getPluginManager().registerEvents(new ServerEvents(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new InventoryListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new CustomItemEvents(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new DamageEffectEvents(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ScoreboardListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new CustomItemEvents(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new DamageEffectEvents(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new NPCEvents(), this);
|
||||
new DiscordClientManager();
|
||||
NPCDataManager.reloadNPC();
|
||||
new AlwaysDayTask().runTaskTimer(this, 0, 100);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ public class BetaCommand extends Command {
|
|||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player player) {
|
||||
// TODO: how to make a armor stand turn
|
||||
CryptoMiner.spawn(player, args[0], "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,25 +6,33 @@ import org.bson.Document;
|
|||
|
||||
public class DatabaseManager {
|
||||
public static MongoDatabase database;
|
||||
|
||||
public DatabaseManager() {
|
||||
database = MongoClients.create(Main.env.get("MONGODB_URI")).getDatabase("NullValkyrie");
|
||||
}
|
||||
|
||||
public static MongoCollection<Document> getMinersDB() {
|
||||
return database.getCollection("miners");
|
||||
}
|
||||
|
||||
public static MongoCollection<Document> getShopsDB() {
|
||||
return database.getCollection("shops");
|
||||
}
|
||||
|
||||
public static MongoCollection<Document> getRanksDB() {
|
||||
return database.getCollection("ranks");
|
||||
}
|
||||
|
||||
public static MongoCollection<Document> getNPCsDB() {
|
||||
return database.getCollection("npcs");
|
||||
}
|
||||
|
||||
public static MongoCollection<Document> getUsersDB() {
|
||||
return database.getCollection("users");
|
||||
}
|
||||
|
||||
public static MongoCollection<Document> getCustomWeaponsDB() {
|
||||
return database.getCollection("custom_weapons");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package me.night.nullvalkyrie.database;
|
||||
|
||||
import com.mongodb.client.MongoCursor;
|
||||
import com.mongodb.client.model.Filters;
|
||||
import me.night.nullvalkyrie.enums.Rank;
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
|
@ -15,7 +14,7 @@ import static me.night.nullvalkyrie.ui.player.ScoreboardListener.nameTagManager;
|
|||
public class RankDataManager {
|
||||
public static void setRank(UUID uuid, Rank rank) {
|
||||
Document document = DatabaseManager.getRanksDB().find(new Document("UUID", uuid.toString())).first();
|
||||
if(document != null) {
|
||||
if (document != null) {
|
||||
Bson updated = new Document("Rank", rank.name());
|
||||
Bson update = new Document("$set", updated);
|
||||
DatabaseManager.getRanksDB().updateOne(document, update);
|
||||
|
@ -25,15 +24,16 @@ public class RankDataManager {
|
|||
newDocument.put("Rank", rank.name());
|
||||
DatabaseManager.getRanksDB().insertOne(newDocument);
|
||||
}
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
if(player.hasPlayedBefore()) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (player.hasPlayedBefore()) {
|
||||
nameTagManager.removeTag(player);
|
||||
nameTagManager.newTag(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Rank getRank(UUID uuid) {
|
||||
try (MongoCursor<Document> cursor = DatabaseManager.getRanksDB().find(Filters.eq("UUID", uuid.toString())).cursor()) {
|
||||
try (MongoCursor<Document> cursor = DatabaseManager.getRanksDB().find(new Document("UUID", uuid.toString())).cursor()) {
|
||||
while (cursor.hasNext()) {
|
||||
Document doc = cursor.next();
|
||||
for (String key : doc.keySet()) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package me.night.nullvalkyrie.entities.miners;
|
|||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import me.night.nullvalkyrie.util.Skin;
|
||||
import me.night.nullvalkyrie.util.Util;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo;
|
||||
|
@ -15,21 +16,24 @@ import org.apache.commons.codec.binary.Base64;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
|
||||
public class CryptoMiner {
|
||||
protected String name;
|
||||
protected Material type;
|
||||
|
@ -103,29 +107,30 @@ public class CryptoMiner {
|
|||
stand.setVisible(true);
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
|
||||
SkullMeta meta = (SkullMeta) head.getItemMeta();
|
||||
if (meta == null) return;
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
|
||||
byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
|
||||
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
|
||||
Field profileField;
|
||||
try {
|
||||
profileField = meta.getClass().getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(meta, profile);
|
||||
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
|
||||
e1.printStackTrace();
|
||||
Util.setFieldValue(meta, "profile", profile);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
head.setItemMeta(meta);
|
||||
|
||||
ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE);
|
||||
LeatherArmorMeta chestdata = (LeatherArmorMeta) chest.getItemMeta();
|
||||
if (chestdata == null) return;
|
||||
chestdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58));
|
||||
chest.setItemMeta(chestdata);
|
||||
ItemStack leg = new ItemStack(Material.LEATHER_LEGGINGS);
|
||||
LeatherArmorMeta legdata = (LeatherArmorMeta) leg.getItemMeta();
|
||||
if (legdata == null) return;
|
||||
legdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58));
|
||||
leg.setItemMeta(legdata);
|
||||
ItemStack boot = new ItemStack(Material.LEATHER_BOOTS);
|
||||
LeatherArmorMeta bootdata = (LeatherArmorMeta) boot.getItemMeta();
|
||||
if (bootdata == null) return;
|
||||
bootdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58));
|
||||
boot.setItemMeta(bootdata);
|
||||
ItemStack pick = new ItemStack(Material.GOLDEN_PICKAXE);
|
||||
|
@ -137,14 +142,19 @@ public class CryptoMiner {
|
|||
list.add(new Pair<>(EnumItemSlot.f, CraftItemStack.asNMSCopy(head)));
|
||||
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color(name));
|
||||
String[] skin = Skin.getSkin("Shiba_");
|
||||
gameProfile.getProperties().put("textures", new Property("textures", skin[0], skin[1]));
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
WorldServer w = ((CraftWorld) player.getLocation().getWorld()).getHandle();
|
||||
EntityPlayer miner = new EntityPlayer(server, w, gameProfile, null);
|
||||
// set the icon to the tab list
|
||||
|
||||
|
||||
// TODO: remove the icon from tablist
|
||||
// TODO: how to make a armor stand turn
|
||||
PlayerConnection pc = ((org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer) player).getHandle().b;
|
||||
pc.a(new PacketPlayOutEntityEquipment(stand.getEntityId(), list));
|
||||
pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, miner));
|
||||
double radius = 3;
|
||||
World world = miner.getBukkitEntity().getWorld();
|
||||
// write a loop to get nearby 24 blocks using radius 2
|
||||
int x, y, z = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,25 @@
|
|||
package me.night.nullvalkyrie.enums;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public enum Rarity {
|
||||
COMMON(ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON", ChatColor.WHITE.toString()),
|
||||
UNCOMMON(net.md_5.bungee.api.ChatColor.of("#31ff09").toString() + ChatColor.BOLD + "UNCOMMON", net.md_5.bungee.api.ChatColor.of("#31ff09").toString()),
|
||||
RARE(net.md_5.bungee.api.ChatColor.of("#2f57ae").toString() + ChatColor.BOLD + "RARE", net.md_5.bungee.api.ChatColor.of("#2f57ae").toString()),
|
||||
EPIC(net.md_5.bungee.api.ChatColor.of("#b201b2").toString() + ChatColor.BOLD + "EPIC", net.md_5.bungee.api.ChatColor.of("#b201b2").toString()),
|
||||
LEGENDARY(net.md_5.bungee.api.ChatColor.of("#ffa21b").toString() + ChatColor.BOLD + "LEGENDARY", net.md_5.bungee.api.ChatColor.of("#ffa21b").toString()),
|
||||
MYTHIC(net.md_5.bungee.api.ChatColor.of("#ff23ff").toString() + ChatColor.BOLD + "MYTHIC", net.md_5.bungee.api.ChatColor.of("#ff23ff").toString()),
|
||||
ULTRA(ChatColor.RED.toString() + ChatColor.BOLD + "ULTRA", ChatColor.RED.toString()),
|
||||
GRAND(net.md_5.bungee.api.ChatColor.of("#00fdff").toString() + ChatColor.BOLD + "GRAND", net.md_5.bungee.api.ChatColor.of("#00fdff").toString());
|
||||
COMMON(ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON", ChatColor.WHITE.toString()), UNCOMMON(net.md_5.bungee.api.ChatColor.of("#31ff09").toString() + ChatColor.BOLD + "UNCOMMON", net.md_5.bungee.api.ChatColor.of("#31ff09").toString()), RARE(net.md_5.bungee.api.ChatColor.of("#2f57ae").toString() + ChatColor.BOLD + "RARE", net.md_5.bungee.api.ChatColor.of("#2f57ae").toString()), EPIC(net.md_5.bungee.api.ChatColor.of("#b201b2").toString() + ChatColor.BOLD + "EPIC", net.md_5.bungee.api.ChatColor.of("#b201b2").toString()), LEGENDARY(net.md_5.bungee.api.ChatColor.of("#ffa21b").toString() + ChatColor.BOLD + "LEGENDARY", net.md_5.bungee.api.ChatColor.of("#ffa21b").toString()), MYTHIC(net.md_5.bungee.api.ChatColor.of("#ff23ff").toString() + ChatColor.BOLD + "MYTHIC", net.md_5.bungee.api.ChatColor.of("#ff23ff").toString()), ULTRA(ChatColor.RED.toString() + ChatColor.BOLD + "ULTRA", ChatColor.RED.toString()), GRAND(net.md_5.bungee.api.ChatColor.of("#00fdff").toString() + ChatColor.BOLD + "GRAND", net.md_5.bungee.api.ChatColor.of("#00fdff").toString());
|
||||
private final String display;
|
||||
private final String color;
|
||||
|
||||
Rarity(String display, String color) {
|
||||
this.display = display;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getDisplay() {
|
||||
return display;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public static Rarity getRarity(String str) {
|
||||
return switch (str) {
|
||||
case "UNCOMMON" -> UNCOMMON;
|
||||
|
|
|
@ -30,12 +30,6 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.util.*;
|
||||
|
||||
public class CustomItemEvents implements Listener {
|
||||
private final Main main;
|
||||
|
||||
public CustomItemEvents(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
|
||||
if (e.getDamager().getType().equals(EntityType.SNOWBALL)) {
|
||||
|
@ -257,7 +251,7 @@ public class CustomItemEvents implements Listener {
|
|||
// player.setHealth(20);
|
||||
// player.teleport(generateRandomCoord(9, Bukkit.getWorld("world")));
|
||||
// }
|
||||
// }.runTaskLater(main, 100L);
|
||||
// }.runTaskLater(Main.getPlugin(Main.class), 100L);
|
||||
// countDown(player, new int[]{5});
|
||||
// }
|
||||
}
|
||||
|
@ -267,7 +261,7 @@ public class CustomItemEvents implements Listener {
|
|||
private int taskID;
|
||||
|
||||
public void countDown(Player player, int[] a) {
|
||||
taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(main, () -> {
|
||||
taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getPlugin(Main.class), () -> {
|
||||
player.sendTitle(ChatColor.RED + "YOU DIED!", ChatColor.GREEN + "You will revive in " + a[0] + " seconds", 0, 20, 0);
|
||||
a[0]--;
|
||||
if (a[0] == 0) {
|
||||
|
@ -309,8 +303,10 @@ public class CustomItemEvents implements Listener {
|
|||
p.openMerchant(merchant, true);
|
||||
}
|
||||
}
|
||||
|
||||
private final HashMap<Location, Integer> blockStages = new HashMap<>();
|
||||
private final HashMap<UUID, Long> miningCooldown = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onAnimationEvent(PlayerAnimationEvent e) { //Material blockType, int mineInterval, Pickaxe x
|
||||
Player player = e.getPlayer();
|
||||
|
@ -338,6 +334,7 @@ public class CustomItemEvents implements Listener {
|
|||
block.breakNaturally();
|
||||
}
|
||||
}
|
||||
|
||||
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
public void sendBlockDamage(Player player, Block block) {
|
||||
|
|
|
@ -18,12 +18,6 @@ import java.text.DecimalFormat;
|
|||
import java.util.*;
|
||||
|
||||
public class DamageEffectEvents implements Listener {
|
||||
private final Main main;
|
||||
|
||||
public DamageEffectEvents(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
public World world = Bukkit.getWorld("world");
|
||||
public final Map<Entity, Integer> indicators = new HashMap<>();
|
||||
private final DecimalFormat formatter = new DecimalFormat("#");
|
||||
|
@ -65,7 +59,7 @@ public class DamageEffectEvents implements Listener {
|
|||
}
|
||||
removal.forEach(stands::remove);
|
||||
}
|
||||
}.runTaskTimer(main, 0L, 1L);
|
||||
}.runTaskTimer(Main.getPlugin(Main.class), 0L, 1L);
|
||||
}
|
||||
|
||||
public static boolean isSpawnable(Location loc) {
|
||||
|
|
|
@ -5,13 +5,12 @@ import me.night.nullvalkyrie.packets.PacketInjector;
|
|||
import me.night.nullvalkyrie.util.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.boss.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
@ -46,4 +45,8 @@ public class ServerEvents implements Listener {
|
|||
// TODO: change hologram things
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onWeatherChange(WeatherChangeEvent e) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import me.night.nullvalkyrie.Main;
|
|||
import me.night.nullvalkyrie.entities.npcs.NPCManager;
|
||||
import me.night.nullvalkyrie.events.custom.InteractHologramEvent;
|
||||
import me.night.nullvalkyrie.events.custom.RightClickNPCEvent;
|
||||
import me.night.nullvalkyrie.util.Util;
|
||||
import net.minecraft.network.protocol.game.PacketPlayInUseEntity;
|
||||
import net.minecraft.server.level.EntityPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -15,8 +16,6 @@ import org.bukkit.entity.Entity;
|
|||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class PacketHandler extends ChannelDuplexHandler {
|
||||
private final Player player;
|
||||
|
||||
|
@ -33,40 +32,26 @@ public class PacketHandler extends ChannelDuplexHandler {
|
|||
public void channelRead(ChannelHandlerContext c, Object packet) throws Exception {
|
||||
if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) {
|
||||
PacketPlayInUseEntity pk = (PacketPlayInUseEntity) packet;
|
||||
int entityID = (int) PacketInjector.getFieldValue(packet, "a");
|
||||
boolean sneak = (boolean) PacketInjector.getFieldValue(packet, "c");
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Entity entity : Bukkit.getWorld("world").getEntities()) {
|
||||
if (entity.getEntityId() == entityID && entity.getType() == EntityType.ARMOR_STAND){
|
||||
Bukkit.getPluginManager().callEvent(new InteractHologramEvent(player, (ArmorStand) entity));
|
||||
}
|
||||
int entityID = (int) Util.getFieldValue(packet, "a");
|
||||
boolean sneak = (boolean) Util.getFieldValue(packet, "c");
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), () -> {
|
||||
for (Entity entity : Bukkit.getWorld("world").getEntities()) {
|
||||
if (entity.getEntityId() == entityID && entity.getType() == EntityType.ARMOR_STAND) {
|
||||
Bukkit.getPluginManager().callEvent(new InteractHologramEvent(player, (ArmorStand) entity));
|
||||
}
|
||||
}
|
||||
}, 0);
|
||||
|
||||
Field type = pk.getClass().getDeclaredField("b");
|
||||
type.setAccessible(true);
|
||||
Object data = type.get(pk);
|
||||
Object data = Util.getFieldValue(pk, "b");
|
||||
if (data.toString().split("\\$")[1].charAt(0) == 'e') {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Field hand = data.getClass().getDeclaredField("a");
|
||||
hand.setAccessible(true);
|
||||
if (!hand.get(data).toString().equals("MAIN_HAND")) {
|
||||
return;
|
||||
}
|
||||
Object hand = Util.getFieldValue(data, "a");
|
||||
if (!hand.toString().equals("MAIN_HAND")) return;
|
||||
//Right Click
|
||||
for (EntityPlayer npcs : NPCManager.getNPCs()) {
|
||||
if (npcs.ae() == entityID && sneak) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npcs));
|
||||
}
|
||||
}, 0);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), () -> Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npcs)), 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,11 @@ import net.minecraft.server.level.EntityPlayer;
|
|||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class PacketInjector {
|
||||
public void addPlayer(Player p) {
|
||||
try {
|
||||
Channel ch = nms(p).b.b.m;
|
||||
if(ch.pipeline().get("PacketInjector") == null) {
|
||||
if (ch.pipeline().get("PacketInjector") == null) {
|
||||
PacketHandler h = new PacketHandler(p);
|
||||
ch.pipeline().addBefore("packet_handler", "PacketInjector", h);
|
||||
}
|
||||
|
@ -23,18 +21,14 @@ public class PacketInjector {
|
|||
public void removePlayer(Player p) {
|
||||
try {
|
||||
Channel ch = nms(p).b.b.m;
|
||||
if(ch.pipeline().get("PacketInjector") != null) {
|
||||
if (ch.pipeline().get("PacketInjector") != null) {
|
||||
ch.pipeline().remove("PacketInjector");
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static Object getFieldValue(Object instance, String fieldName) throws Exception {
|
||||
Field field = instance.getClass().getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field.get(instance);
|
||||
}
|
||||
|
||||
public static EntityPlayer nms(Player p) {
|
||||
return ((CraftPlayer) p).getHandle();
|
||||
}
|
||||
|
|
13
src/main/java/me/night/nullvalkyrie/tasks/AlwaysDayTask.java
Normal file
13
src/main/java/me/night/nullvalkyrie/tasks/AlwaysDayTask.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package me.night.nullvalkyrie.tasks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class AlwaysDayTask extends BukkitRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
World world = Bukkit.getServer().getWorld("world");
|
||||
if (world != null) world.setTime(0L);
|
||||
}
|
||||
}
|
|
@ -2,17 +2,13 @@ package me.night.nullvalkyrie.ui.player;
|
|||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Criteria;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.*;
|
||||
|
||||
public class BelowNameManager {
|
||||
public void setBelowName(Player player) {
|
||||
Scoreboard board = player.getScoreboard();
|
||||
Objective obj = board.registerNewObjective("HealthBar", Criteria.DUMMY, ChatColor.RED.toString());
|
||||
Objective obj = board.registerNewObjective("HealthBar", Criteria.create("CustomHealth"), ChatColor.RED.toString() + player.getHealth() + "❤");
|
||||
obj.setDisplaySlot(DisplaySlot.BELOW_NAME);
|
||||
obj.setDisplayName(ChatColor.RED.toString() + player.getHealth() + "❤");
|
||||
player.setScoreboard(board);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package me.night.nullvalkyrie.ui.player;
|
||||
|
||||
import me.night.nullvalkyrie.Main;
|
||||
import me.night.nullvalkyrie.database.RankDataManager;
|
||||
import me.night.nullvalkyrie.enums.Rank;
|
||||
import me.night.nullvalkyrie.entities.npcs.NPCManager;
|
||||
|
@ -21,9 +20,9 @@ public class ScoreboardListener implements Listener {
|
|||
public static SideBarManager sideBarManager;
|
||||
private final BelowNameManager belowNameManager;
|
||||
|
||||
public ScoreboardListener(Main main) {
|
||||
public ScoreboardListener() {
|
||||
nameTagManager = new NameTagManager();
|
||||
sideBarManager = new SideBarManager(main);
|
||||
sideBarManager = new SideBarManager();
|
||||
belowNameManager = new BelowNameManager();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,13 +13,8 @@ import java.util.UUID;
|
|||
|
||||
public class SideBarManager {
|
||||
private int taskID;
|
||||
private final Main main;
|
||||
public AnimatedSideBar board = null;
|
||||
|
||||
public SideBarManager(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
public void setSideBar(Player player) {
|
||||
Scoreboard board = player.getScoreboard();
|
||||
Objective obj;
|
||||
|
@ -55,7 +50,7 @@ public class SideBarManager {
|
|||
|
||||
public void start(Player player) {
|
||||
board = new AnimatedSideBar(player.getUniqueId());
|
||||
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(main, new Runnable() {
|
||||
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getPlugin(Main.class), new Runnable() {
|
||||
int count = 0;
|
||||
|
||||
public void animate(String str) {
|
||||
|
|
|
@ -15,17 +15,18 @@ public class Skin {
|
|||
try {
|
||||
URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);
|
||||
InputStreamReader reader = new InputStreamReader(url.openStream());
|
||||
String uuid = new JsonParser().parse(reader).getAsJsonObject().get("id").getAsString();
|
||||
String uuid = JsonParser.parseReader(reader).getAsJsonObject().get("id").getAsString();
|
||||
URL url2 = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
|
||||
InputStreamReader reader2 = new InputStreamReader(url2.openStream());
|
||||
JsonObject properties = new JsonParser().parse(reader2).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
|
||||
JsonObject properties = JsonParser.parseReader(reader2).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
|
||||
String texture = properties.get("value").getAsString();
|
||||
String signature = properties.get("signature").getAsString();
|
||||
return new String[] {texture, signature};
|
||||
return new String[]{texture, signature};
|
||||
} catch (Exception e) {
|
||||
return new String[]{};
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] getSkin(Player player) {
|
||||
try {
|
||||
GameProfile profile = ((CraftPlayer) player).getProfile();
|
||||
|
|
|
@ -2,6 +2,8 @@ package me.night.nullvalkyrie.util;
|
|||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class Util {
|
||||
public static String centerText(String text, int lineLength) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
@ -22,4 +24,16 @@ public class Util {
|
|||
if (str == null || str.length() == 0) return str;
|
||||
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||
}
|
||||
|
||||
public static Object getFieldValue(Object instance, String fieldName) throws Exception {
|
||||
Field field = instance.getClass().getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field.get(instance);
|
||||
}
|
||||
|
||||
public static void setFieldValue(Object instance, String fieldName, Object value) throws Exception {
|
||||
Field field = instance.getClass().getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
field.set(instance, value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue