From 85ccd119044a749e984887c57f153bfe0c443848 Mon Sep 17 00:00:00 2001 From: NK Date: Sun, 25 Dec 2022 02:17:35 +0000 Subject: [PATCH] moving back to 1.19.2 as 1.19.3 is not needed --- src/main/java/IDEAS => IDEAS | 0 pom.xml | 10 ++--- .../{Main.java => NullValkyrie.java} | 3 +- .../nullvalkyrie/commands/BetaCommand.java | 4 +- .../nullvalkyrie/commands/VanishCommand.java | 6 +-- .../entities/holograms/PerPlayerHologram.java | 4 +- .../entities/items/CustomItemManager.java | 6 +-- .../entities/miners/CryptoMiner.java | 11 ++++-- .../entities/npcs/NPCManager.java | 26 +++++++------ .../nullvalkyrie/entities/pets/ZombiePet.java | 4 +- .../events/listeners/CustomItemEvents.java | 6 +-- .../events/listeners/DamageEffectEvents.java | 4 +- .../events/listeners/NPCEvents.java | 2 +- .../packets/handle/PacketHandler.java | 37 +++++++++++++++++-- .../packets/protocol/Channel.java | 2 +- .../PacketPlayOutBlockBreakAnimation.java | 2 +- .../protocol/PacketPlayOutEntityMetadata.java | 8 ++-- .../protocol/PacketPlayOutSpawnEntity.java | 2 +- .../ui/inventory/InventoryListener.java | 6 +-- .../ui/player/SideBarManager.java | 4 +- .../java/me/night/nullvalkyrie/util/Skin.java | 2 +- 21 files changed, 92 insertions(+), 57 deletions(-) rename src/main/java/IDEAS => IDEAS (100%) rename src/main/java/me/night/nullvalkyrie/{Main.java => NullValkyrie.java} (96%) diff --git a/src/main/java/IDEAS b/IDEAS similarity index 100% rename from src/main/java/IDEAS rename to IDEAS diff --git a/pom.xml b/pom.xml index 66ae92e..271636c 100644 --- a/pom.xml +++ b/pom.xml @@ -67,9 +67,9 @@ remap-obf - org.spigotmc:minecraft-server:1.19.3-R0.1-SNAPSHOT:txt:maps-mojang + org.spigotmc:minecraft-server:1.19.2-R0.1-SNAPSHOT:txt:maps-mojang true - org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT:jar:remapped-mojang + org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT:jar:remapped-mojang true remapped-obf @@ -82,8 +82,8 @@ remap-spigot ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.19.3-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT:jar:remapped-obf + org.spigotmc:minecraft-server:1.19.2-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT:jar:remapped-obf @@ -115,7 +115,7 @@ org.spigotmc spigot - 1.19.3-R0.1-SNAPSHOT + 1.19.2-R0.1-SNAPSHOT remapped-mojang provided diff --git a/src/main/java/me/night/nullvalkyrie/Main.java b/src/main/java/me/night/nullvalkyrie/NullValkyrie.java similarity index 96% rename from src/main/java/me/night/nullvalkyrie/Main.java rename to src/main/java/me/night/nullvalkyrie/NullValkyrie.java index d20e8ec..92504c1 100644 --- a/src/main/java/me/night/nullvalkyrie/Main.java +++ b/src/main/java/me/night/nullvalkyrie/NullValkyrie.java @@ -13,8 +13,7 @@ import org.bukkit.*; import org.bukkit.plugin.java.JavaPlugin; -public final class Main extends JavaPlugin { - +public final class NullValkyrie extends JavaPlugin { @Override public void onEnable() { EnchantmentManager.register(); diff --git a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java index 0497b85..ae19d50 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java @@ -1,10 +1,9 @@ package me.night.nullvalkyrie.commands; -import me.night.nullvalkyrie.entities.npcs.NPCManager; import me.night.nullvalkyrie.entities.pets.ZombiePet; import org.bukkit.Material; import org.bukkit.command.CommandSender; -import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -34,7 +33,6 @@ public class BetaCommand extends Command { itemMeta2.setCustomModelData(1010101); item2.setItemMeta(itemMeta2); player.getInventory().addItem(item2); - NPCManager.createNPC(player, args[0]); } } diff --git a/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java b/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java index cceb3c9..7310f4a 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java @@ -1,6 +1,6 @@ package me.night.nullvalkyrie.commands; -import me.night.nullvalkyrie.Main; +import me.night.nullvalkyrie.NullValkyrie; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -23,13 +23,13 @@ public class VanishCommand extends Command { if (vanished.contains(player.getUniqueId())) { vanished.remove(player.getUniqueId()); for (Player target : Bukkit.getOnlinePlayers()) { - target.showPlayer(Main.getPlugin(Main.class), player); + target.showPlayer(NullValkyrie.getPlugin(NullValkyrie.class), player); } player.sendMessage(ChatColor.GREEN + "You are now seen by people"); } else { vanished.add(player.getUniqueId()); for (Player target : Bukkit.getOnlinePlayers()) { - target.hidePlayer(Main.getPlugin(Main.class), player); + target.hidePlayer(NullValkyrie.getPlugin(NullValkyrie.class), player); } player.sendMessage(ChatColor.GREEN + "You are now vanished"); } diff --git a/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java b/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java index bf4d458..a5712ea 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java +++ b/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java @@ -8,7 +8,7 @@ import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.decoration.ArmorStand; -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import java.util.Optional; @@ -29,6 +29,6 @@ public class PerPlayerHologram { SynchedEntityData watcher = stand.getEntityData(); watcher.set(new EntityDataAccessor<>(2, EntityDataSerializers.OPTIONAL_COMPONENT), Optional.of(Component.nullToEmpty(line))); watcher.set(new EntityDataAccessor<>(3, EntityDataSerializers.BOOLEAN), true); - new PacketPlayOutEntityMetadata(player, stand, watcher.getNonDefaultValues()); + new PacketPlayOutEntityMetadata(player, stand, watcher); } } diff --git a/src/main/java/me/night/nullvalkyrie/entities/items/CustomItemManager.java b/src/main/java/me/night/nullvalkyrie/entities/items/CustomItemManager.java index 405bf7e..a3cff44 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/items/CustomItemManager.java +++ b/src/main/java/me/night/nullvalkyrie/entities/items/CustomItemManager.java @@ -1,6 +1,6 @@ package me.night.nullvalkyrie.entities.items; -import me.night.nullvalkyrie.Main; +import me.night.nullvalkyrie.NullValkyrie; import me.night.nullvalkyrie.database.CustomWeaponsDataManager; import me.night.nullvalkyrie.enums.Rarity; import me.night.nullvalkyrie.util.Util; @@ -84,7 +84,7 @@ public class CustomItemManager { HashMap pdcdata = (HashMap) weapon.get("PDC"); for (String key : pdcdata.keySet()) { PersistentDataContainer container = itemMeta.getPersistentDataContainer(); - NamespacedKey key1 = new NamespacedKey(Main.getPlugin(Main.class), key); + NamespacedKey key1 = new NamespacedKey(NullValkyrie.getPlugin(NullValkyrie.class), key); keys.put(Rarity.getRarity((String) weapon.get("Rarity")).getColor() + weapon.get("Name") + "." + key, key1); container.set(key1, PersistentDataType.INTEGER, (int) pdcdata.get(key)); } @@ -103,7 +103,7 @@ public class CustomItemManager { } public static void setItemRecipe(String key, ItemStack i, List shapes, HashMap ingredients, int amount) { - NamespacedKey nsk = new NamespacedKey(Main.getPlugin(Main.class), key.replaceAll("\\s", "")); + NamespacedKey nsk = new NamespacedKey(NullValkyrie.getPlugin(NullValkyrie.class), key.replaceAll("\\s", "")); ShapedRecipe recipe = new ShapedRecipe(nsk, i); recipe.shape(shapes.get(0), shapes.get(1), shapes.get(2)); List abcs = List.of('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'); diff --git a/src/main/java/me/night/nullvalkyrie/entities/miners/CryptoMiner.java b/src/main/java/me/night/nullvalkyrie/entities/miners/CryptoMiner.java index fe0403a..486d7b7 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/miners/CryptoMiner.java +++ b/src/main/java/me/night/nullvalkyrie/entities/miners/CryptoMiner.java @@ -6,16 +6,19 @@ import com.mojang.authlib.properties.Property; import me.night.nullvalkyrie.enums.MinerType; import me.night.nullvalkyrie.util.Skin; import me.night.nullvalkyrie.util.Util; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; 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.craftbukkit.v1_19_R2.CraftServer; -import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.CraftServer; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -136,7 +139,9 @@ public class CryptoMiner { gameProfile.getProperties().put("textures", new Property("textures", skin[0], skin[1])); MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); ServerLevel w = ((CraftWorld) player.getLocation().getWorld()).getHandle(); - ServerPlayer miner = new ServerPlayer(server, w, gameProfile); + ServerPlayer miner = new ServerPlayer(server, w, gameProfile, null); + ServerGamePacketListenerImpl pc = ((CraftPlayer) player).getHandle().connection; + pc.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, miner)); World world = miner.getBukkitEntity().getWorld(); List locs = new ArrayList<>(); for (int x = (int) stand.getLocation().getX() - 3; x <= stand.getLocation().getX() + 2; x++) { diff --git a/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java b/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java index 38a62a5..d5cd093 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java +++ b/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java @@ -3,9 +3,9 @@ package me.night.nullvalkyrie.entities.npcs; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.datafixers.util.Pair; +import me.night.nullvalkyrie.NullValkyrie; import me.night.nullvalkyrie.database.NPCDataManager; import me.night.nullvalkyrie.packets.protocol.PacketPlayOutEntityMetadata; -import me.night.nullvalkyrie.packets.protocol.PacketPlayOutSpawnEntity; import me.night.nullvalkyrie.util.*; import net.minecraft.network.protocol.game.*; import net.minecraft.network.syncher.*; @@ -17,10 +17,10 @@ import net.minecraft.world.entity.EquipmentSlot; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_19_R2.CraftServer; -import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_19_R1.CraftServer; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -43,7 +43,7 @@ public class NPCManager { GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color(name)); String[] skin = Skin.getSkin(player); gameProfile.getProperties().put("textures", new Property("textures", skin[0], skin[1])); - ServerPlayer npc = new ServerPlayer(server, level, gameProfile); + ServerPlayer npc = new ServerPlayer(server, level, gameProfile, null); Location location = player.getLocation(); npc.setPos(location.getX(), location.getY(), location.getZ()); addNPCPacket(npc); @@ -53,11 +53,13 @@ public class NPCManager { public static void addNPCPacket(ServerPlayer npc) { for (Player player : Bukkit.getOnlinePlayers()) { ServerGamePacketListenerImpl pc = ((CraftPlayer) player).getHandle().connection; - new PacketPlayOutSpawnEntity(player, npc); + pc.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, npc)); + pc.send(new ClientboundAddPlayerPacket(npc)); pc.send(new ClientboundRotateHeadPacket(npc, (byte) (npc.getBukkitYaw() * 256 / 360))); SynchedEntityData watcher = npc.getEntityData(); watcher.set(new EntityDataAccessor<>(17, EntityDataSerializers.BYTE), (byte) 127); - new PacketPlayOutEntityMetadata(player, npc, watcher.getNonDefaultValues()); + new PacketPlayOutEntityMetadata(player, npc, watcher); + Bukkit.getScheduler().runTaskLaterAsynchronously(NullValkyrie.getPlugin(NullValkyrie.class), () -> pc.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, npc)), 50); ItemStack netheriteAxe = new ItemStack(Material.NETHERITE_AXE); ItemStack anotherAxe = new ItemStack(Material.NETHERITE_INGOT); List> itemList = new ArrayList<>(); @@ -70,11 +72,13 @@ public class NPCManager { public static void addJoinPacket(Player player) { for (ServerPlayer npc : NPCs) { ServerGamePacketListenerImpl pc = ((CraftPlayer) player).getHandle().connection; - new PacketPlayOutSpawnEntity(player, npc); + pc.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, npc)); + pc.send(new ClientboundAddPlayerPacket(npc)); pc.send(new ClientboundRotateHeadPacket(npc, (byte) (npc.getBukkitYaw() * 256 / 360))); SynchedEntityData watcher = npc.getEntityData(); watcher.set(new EntityDataAccessor<>(17, EntityDataSerializers.BYTE), (byte) 127); - new PacketPlayOutEntityMetadata(player, npc, watcher.getNonDefaultValues()); + new PacketPlayOutEntityMetadata(player, npc, watcher); + Bukkit.getScheduler().runTaskLaterAsynchronously(NullValkyrie.getPlugin(NullValkyrie.class), () -> pc.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, npc)), 50); ItemStack netheriteAxe = new ItemStack(Material.NETHERITE_AXE); ItemStack anotherAxe = new ItemStack(Material.NETHERITE_INGOT); List> itemList = new ArrayList<>(); @@ -90,7 +94,7 @@ public class NPCManager { gameProfile.getProperties().put("textures", new Property("textures", (String) npc.get("texture"), (String) npc.get("signature"))); MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); ServerLevel w = ((CraftWorld) location.getWorld()).getHandle(); - ServerPlayer ep = new ServerPlayer(server, w, gameProfile); + ServerPlayer ep = new ServerPlayer(server, w, gameProfile, null); ep.setPos(location.getX(), location.getY(), location.getZ()); // NMS: 1.19.2 https://nms.screamingsandals.org/1.19.2/net/minecraft/world/entity/Entity.html absMoveTo addNPCPacket(ep); NPCs.add(ep); diff --git a/src/main/java/me/night/nullvalkyrie/entities/pets/ZombiePet.java b/src/main/java/me/night/nullvalkyrie/entities/pets/ZombiePet.java index c2fb0de..966fed1 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/pets/ZombiePet.java +++ b/src/main/java/me/night/nullvalkyrie/entities/pets/ZombiePet.java @@ -7,8 +7,8 @@ import net.minecraft.world.entity.ai.goal.FloatGoal; import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal; import net.minecraft.world.entity.monster.Zombie; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityTargetEvent; diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java index ca04bf0..ea5a3ae 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java @@ -3,7 +3,7 @@ package me.night.nullvalkyrie.events.listeners; import me.night.nullvalkyrie.entities.items.CustomItemManager; import me.night.nullvalkyrie.entities.items.Pickaxe; import me.night.nullvalkyrie.enums.Rarity; -import me.night.nullvalkyrie.Main; +import me.night.nullvalkyrie.NullValkyrie; import me.night.nullvalkyrie.packets.protocol.PacketPlayOutBlockBreakAnimation; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -245,7 +245,7 @@ public class CustomItemEvents implements Listener { // player.setHealth(20); // player.teleport(generateRandomCoord(9, Bukkit.getWorld("world"))); // } -// }.runTaskLater(Main.getPlugin(Main.class), 100L); +// }.runTaskLater(NullValkyrie.getPlugin(NullValkyrie.class), 100L); // countDown(player, new int[]{5}); // } } @@ -255,7 +255,7 @@ public class CustomItemEvents implements Listener { private int taskID; public void countDown(Player player, int[] a) { - taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getPlugin(Main.class), () -> { + taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(NullValkyrie.getPlugin(NullValkyrie.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) { diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/DamageEffectEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/DamageEffectEvents.java index cd0fde4..cc76540 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/DamageEffectEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/DamageEffectEvents.java @@ -1,6 +1,6 @@ package me.night.nullvalkyrie.events.listeners; -import me.night.nullvalkyrie.Main; +import me.night.nullvalkyrie.NullValkyrie; import me.night.nullvalkyrie.util.Util; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -60,7 +60,7 @@ public class DamageEffectEvents implements Listener { } removal.forEach(stands::remove); } - }.runTaskTimer(Main.getPlugin(Main.class), 0L, 1L); + }.runTaskTimer(NullValkyrie.getPlugin(NullValkyrie.class), 0L, 1L); } public boolean isSpawnable(Location loc) { diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java index 407a40f..db695b6 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java @@ -7,7 +7,7 @@ import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; import net.minecraft.server.network.ServerGamePacketListenerImpl; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; diff --git a/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java b/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java index 2864884..8cb4dec 100644 --- a/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java +++ b/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java @@ -3,18 +3,26 @@ package me.night.nullvalkyrie.packets.handle; import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; -import me.night.nullvalkyrie.Main; +import me.night.nullvalkyrie.NullValkyrie; 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.ClientboundSetEntityDataPacket; import net.minecraft.network.protocol.game.ServerboundInteractPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.level.ServerPlayer; import org.bukkit.Bukkit; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; public class PacketHandler extends ChannelDuplexHandler { private final Player player; @@ -25,6 +33,29 @@ public class PacketHandler extends ChannelDuplexHandler { @Override public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception { + if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayOutEntityMetadat")) { + ClientboundSetEntityDataPacket pk = (ClientboundSetEntityDataPacket) packet; + int entityID = pk.getId(); + final Entity[] entity = {null}; + // get entity from id + new BukkitRunnable() { + @Override + public void run() { + for (Entity e : Bukkit.getWorld("world").getEntities()) { + if (e.getEntityId() == entityID && e.getType() == EntityType.PLAYER) { + entity[0] = e; + } + } + } + }.runTaskLater(NullValkyrie.getPlugin(NullValkyrie.class), 0); + if (entity[0] == null) return; + List> list = pk.getUnpackedData(); + SynchedEntityData.DataItem value = (SynchedEntityData.DataItem) list.get(9); + System.out.println(value.getAccessor()); + ThreadLocalRandom random = ThreadLocalRandom.current(); + float health = random.nextFloat(5F,20F); + list.set(9, new SynchedEntityData.DataItem<>(new EntityDataAccessor<>(value.getAccessor().getId(), EntityDataSerializers.FLOAT), health)); + } super.write(ctx, packet, promise); } @@ -34,7 +65,7 @@ public class PacketHandler extends ChannelDuplexHandler { ServerboundInteractPacket pk = (ServerboundInteractPacket) packet; int entityID = (int) Util.getFieldValue(packet, "a"); boolean sneak = (boolean) Util.getFieldValue(packet, "c"); - Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), () -> { + Bukkit.getScheduler().scheduleSyncDelayedTask(NullValkyrie.getPlugin(NullValkyrie.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)); @@ -50,7 +81,7 @@ public class PacketHandler extends ChannelDuplexHandler { //Right Click for (ServerPlayer npcs : NPCManager.getNPCs()) { if (npcs.getBukkitEntity().getEntityId() == entityID && sneak) { - Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), () -> Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npcs)), 0); + Bukkit.getScheduler().scheduleSyncDelayedTask(NullValkyrie.getPlugin(NullValkyrie.class), () -> Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npcs)), 0); } } diff --git a/src/main/java/me/night/nullvalkyrie/packets/protocol/Channel.java b/src/main/java/me/night/nullvalkyrie/packets/protocol/Channel.java index b771540..11b5fea 100644 --- a/src/main/java/me/night/nullvalkyrie/packets/protocol/Channel.java +++ b/src/main/java/me/night/nullvalkyrie/packets/protocol/Channel.java @@ -1,6 +1,6 @@ package me.night.nullvalkyrie.packets.protocol; -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; public class Channel { diff --git a/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutBlockBreakAnimation.java b/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutBlockBreakAnimation.java index e1d22fb..767c49f 100644 --- a/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutBlockBreakAnimation.java +++ b/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutBlockBreakAnimation.java @@ -3,7 +3,7 @@ package me.night.nullvalkyrie.packets.protocol; import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; public class PacketPlayOutBlockBreakAnimation implements Packet { diff --git a/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutEntityMetadata.java b/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutEntityMetadata.java index da8bda5..f07a4e1 100644 --- a/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutEntityMetadata.java +++ b/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutEntityMetadata.java @@ -3,13 +3,11 @@ package me.night.nullvalkyrie.packets.protocol; import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.world.entity.Entity; -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.util.List; - public class PacketPlayOutEntityMetadata implements Packet { - public PacketPlayOutEntityMetadata(Player player, Entity entity, List> list) { - ((CraftPlayer) player).getHandle().connection.send(new ClientboundSetEntityDataPacket(entity.getBukkitEntity().getEntityId(), list)); + public PacketPlayOutEntityMetadata(Player player, Entity entity, SynchedEntityData entityData) { + ((CraftPlayer) player).getHandle().connection.send(new ClientboundSetEntityDataPacket(entity.getBukkitEntity().getEntityId(), entityData, true)); } } diff --git a/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutSpawnEntity.java b/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutSpawnEntity.java index d79e3d4..7fb2cbc 100644 --- a/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutSpawnEntity.java +++ b/src/main/java/me/night/nullvalkyrie/packets/protocol/PacketPlayOutSpawnEntity.java @@ -2,7 +2,7 @@ package me.night.nullvalkyrie.packets.protocol; import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; import net.minecraft.world.entity.Entity; -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; public class PacketPlayOutSpawnEntity implements Packet { diff --git a/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java b/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java index 20f2a3d..29b560f 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java +++ b/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java @@ -1,6 +1,6 @@ package me.night.nullvalkyrie.ui.inventory; -import me.night.nullvalkyrie.Main; +import me.night.nullvalkyrie.NullValkyrie; import me.night.nullvalkyrie.database.UserDataManager; import me.night.nullvalkyrie.enums.Items; import me.night.nullvalkyrie.util.RandomCollection; @@ -142,7 +142,7 @@ public class InventoryListener implements Listener { ii++; time++; } - }.runTaskTimer(Main.getPlugin(Main.class), 1L, 5L); + }.runTaskTimer(NullValkyrie.getPlugin(NullValkyrie.class), 1L, 5L); new BukkitRunnable() { @Override public void run() { @@ -184,7 +184,7 @@ public class InventoryListener implements Listener { player.getInventory().addItem(item); } else player.closeInventory(); } - }.runTaskLater(Main.getPlugin(Main.class), 5L * 20L); + }.runTaskLater(NullValkyrie.getPlugin(NullValkyrie.class), 5L * 20L); } } diff --git a/src/main/java/me/night/nullvalkyrie/ui/player/SideBarManager.java b/src/main/java/me/night/nullvalkyrie/ui/player/SideBarManager.java index 8951407..8f99970 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/player/SideBarManager.java +++ b/src/main/java/me/night/nullvalkyrie/ui/player/SideBarManager.java @@ -1,6 +1,6 @@ package me.night.nullvalkyrie.ui.player; -import me.night.nullvalkyrie.Main; +import me.night.nullvalkyrie.NullValkyrie; import me.night.nullvalkyrie.database.UserDataManager; import me.night.nullvalkyrie.util.Util; import org.bukkit.Bukkit; @@ -50,7 +50,7 @@ public class SideBarManager { public void start(Player player) { board = new AnimatedSideBar(player.getUniqueId()); - taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getPlugin(Main.class), new Runnable() { + taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(NullValkyrie.getPlugin(NullValkyrie.class), new Runnable() { int count = 0; public void animate(String str) { diff --git a/src/main/java/me/night/nullvalkyrie/util/Skin.java b/src/main/java/me/night/nullvalkyrie/util/Skin.java index 62b7bcb..0239bdb 100644 --- a/src/main/java/me/night/nullvalkyrie/util/Skin.java +++ b/src/main/java/me/night/nullvalkyrie/util/Skin.java @@ -4,7 +4,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import java.io.InputStreamReader;