diff --git a/pom.xml b/pom.xml index ac466b8f..778cc60d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ uk.antiperson.stackmob StackMob - 5.8.8 + 5.8.9 src/main/java @@ -123,19 +123,19 @@ io.papermc.paper paper-api - 1.20.2-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT provided dev.folia folia-api - 1.20.1-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT provided org.spigotmc spigot - 1.20.2-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT provided diff --git a/src/main/java/uk/antiperson/stackmob/packets/NMSHelper.java b/src/main/java/uk/antiperson/stackmob/packets/NMSHelper.java index 013d7be6..4f46d193 100644 --- a/src/main/java/uk/antiperson/stackmob/packets/NMSHelper.java +++ b/src/main/java/uk/antiperson/stackmob/packets/NMSHelper.java @@ -1,30 +1,15 @@ package uk.antiperson.stackmob.packets; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; import net.minecraft.world.entity.EntityLiving; import net.minecraft.world.entity.boss.wither.EntityWither; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; -import org.bukkit.entity.Entity; +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftLivingEntity; import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; - -import java.util.Collections; public class NMSHelper { - public static void sendVisibilityPacket(Player player, Entity entity, boolean tagVisible) { - DataWatcher.b af = DataWatcher.b.a(new DataWatcherObject<>(3, DataWatcherRegistry.k), tagVisible); - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(entity.getEntityId(), Collections.singletonList(af)); - ((CraftPlayer) player).getHandle().c.a(packetPlayOutEntityMetadata); - } - public static boolean canCreateWitherRose(LivingEntity entity) { EntityLiving entityLiving = ((CraftLivingEntity) entity).getHandle(); // EntityLiving#getKillCredit - return entityLiving.eK() instanceof EntityWither; + return entityLiving.eL() instanceof EntityWither; } } diff --git a/src/main/java/uk/antiperson/stackmob/packets/NmsFakeArmorStand.java b/src/main/java/uk/antiperson/stackmob/packets/NmsFakeArmorStand.java deleted file mode 100644 index 2e905272..00000000 --- a/src/main/java/uk/antiperson/stackmob/packets/NmsFakeArmorStand.java +++ /dev/null @@ -1,75 +0,0 @@ -package uk.antiperson.stackmob.packets; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport; -import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -public class NmsFakeArmorStand implements FakeArmorStand { - - private EntityArmorStand entityArmorStand; - private int id; - private final Player player; - - public NmsFakeArmorStand(Player player) { - this.player = player; - } - - public void spawnFakeArmorStand(Entity owner, Location location, Component name, double offset) { - // spawn armor stand - Location adjusted = adjustLocation(owner, offset); - entityArmorStand = (EntityArmorStand) ((CraftWorld) location.getWorld()).createEntity(adjusted, ArmorStand.class); - // Entity#getId - id = Bukkit.getUnsafe().nextEntityId(); - // metadata for armour stand - // send spawn packet - PacketPlayOutSpawnEntity packetPlayOutSpawn = new PacketPlayOutSpawnEntity(entityArmorStand); - ((CraftPlayer) player).getHandle().c.a(packetPlayOutSpawn); - DataWatcher.b ab = DataWatcher.b.a(new DataWatcherObject<>(0, DataWatcherRegistry.a), (byte) 0x20); - DataWatcher.b> ac = DataWatcher.b.a(new DataWatcherObject<>(2, DataWatcherRegistry.g), Optional.of(IChatBaseComponent.ChatSerializer.a(GsonComponentSerializer.gson().serializeToTree(name)))); - DataWatcher.b ad = DataWatcher.b.a(new DataWatcherObject<>(3, DataWatcherRegistry.k), true); - DataWatcher.b ae = DataWatcher.b.a(new DataWatcherObject<>(5, DataWatcherRegistry.k), true); - DataWatcher.b af = DataWatcher.b.a(new DataWatcherObject<>(15, DataWatcherRegistry.a), (byte) 0x10); - // send metadata packet for armor stand - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(id, List.of(ab, ac, ad, ae, af)); - ((CraftPlayer) player).getHandle().c.a(packetPlayOutEntityMetadata); - } - - @Override - public void updateName(Component newName) { - DataWatcher.b> ad = DataWatcher.b.a(new DataWatcherObject<>(2, DataWatcherRegistry.g), Optional.of(IChatBaseComponent.ChatSerializer.a(GsonComponentSerializer.gson().serializeToTree(newName)))); - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(id, Collections.singletonList(ad)); - ((CraftPlayer) player).getHandle().c.a(packetPlayOutEntityMetadata); - } - - public void teleport(Entity entity, double offset) { - Location adjusted = adjustLocation(entity, offset); - entityArmorStand.b(adjusted.getX(), adjusted.getY(), adjusted.getZ()); - PacketPlayOutEntityTeleport teleport = new PacketPlayOutEntityTeleport(entityArmorStand); - ((CraftPlayer) player).getHandle().c.a(teleport); - } - - public void removeFakeArmorStand() { - PacketPlayOutEntityDestroy entityDestroy = new PacketPlayOutEntityDestroy(id); - ((CraftPlayer) player).getHandle().c.a(entityDestroy); - } - -} \ No newline at end of file diff --git a/src/main/java/uk/antiperson/stackmob/packets/TagHandler.java b/src/main/java/uk/antiperson/stackmob/packets/TagHandler.java index 394df1b9..2e30c3ab 100644 --- a/src/main/java/uk/antiperson/stackmob/packets/TagHandler.java +++ b/src/main/java/uk/antiperson/stackmob/packets/TagHandler.java @@ -6,7 +6,6 @@ import uk.antiperson.stackmob.StackMob; import uk.antiperson.stackmob.entity.StackEntity; import uk.antiperson.stackmob.hook.hooks.ProtocolLibHook; -import uk.antiperson.stackmob.utils.Utilities; public class TagHandler { @@ -24,12 +23,8 @@ public TagHandler(StackMob sm, Player player, StackEntity stackEntity) { } public void init() { - // TODO Temporary workaround! - if (Utilities.getMinecraftVersion() != Utilities.NMS_VERSION || true) { - this.fakeArmorStand = new ProtocolLibFakeArmorStand(sm, player); - return; - } - this.fakeArmorStand = new NmsFakeArmorStand(player); + // Force protocollib for 1.20.2+ + this.fakeArmorStand = new ProtocolLibFakeArmorStand(sm, player); } public void newlyInRange() { @@ -75,15 +70,11 @@ public void playerOutRange() { } private void sendPacket(Entity entity, Player player, boolean tagVisible) { - if (Utilities.getMinecraftVersion() != Utilities.NMS_VERSION) { - ProtocolLibHook protocolLibHook = sm.getHookManager().getProtocolLibHook(); - if (protocolLibHook == null) { - return; - } - protocolLibHook.sendPacket(player, entity, tagVisible); + ProtocolLibHook protocolLibHook = sm.getHookManager().getProtocolLibHook(); + if (protocolLibHook == null) { return; } - NMSHelper.sendVisibilityPacket(player, entity, tagVisible); + protocolLibHook.sendPacket(player, entity, tagVisible); } public boolean isTagVisible() { diff --git a/src/main/java/uk/antiperson/stackmob/utils/Utilities.java b/src/main/java/uk/antiperson/stackmob/utils/Utilities.java index 57174ebf..96056fe9 100644 --- a/src/main/java/uk/antiperson/stackmob/utils/Utilities.java +++ b/src/main/java/uk/antiperson/stackmob/utils/Utilities.java @@ -189,7 +189,8 @@ public enum MinecraftVersion { V1_19_R2("v1_19_R2"), V1_19_R3("v1_19_R3"), V1_20_R1("v1_20_R1"), - V1_20_R2("v1_20_R2");; + V1_20_R2("v1_20_R2"), + V1_20_R3("v1_20_R3"); final String internalName;