diff --git a/build.gradle.kts b/build.gradle.kts index 924d32f..a835108 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,7 +39,7 @@ repositories { dependencies { // Nicko - compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") + compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT") compileOnly("com.github.dmulloy2:ProtocolLib:master-SNAPSHOT") compileOnly("me.clip:placeholderapi:2.11.5") compileOnly("net.kyori:adventure-api:4.17.0") @@ -128,9 +128,14 @@ tasks { downloadPlugins { url("https://download.luckperms.net/1554/bukkit/loader/LuckPerms-Bukkit-5.4.139.jar") - url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar") + + // 1.20 - 1.20.4 testing + url("https://github.com/dmulloy2/ProtocolLib/releases/download/5.2.0/ProtocolLib.jar") + + // 1.20.5 - latest testing + //url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar") } - minecraftVersion("1.21.1") + minecraftVersion("1.20.4") } } \ No newline at end of file diff --git a/src/main/java/xyz/ineanto/nicko/appearance/AppearanceManager.java b/src/main/java/xyz/ineanto/nicko/appearance/AppearanceManager.java index 3355aa9..66f020e 100644 --- a/src/main/java/xyz/ineanto/nicko/appearance/AppearanceManager.java +++ b/src/main/java/xyz/ineanto/nicko/appearance/AppearanceManager.java @@ -151,7 +151,7 @@ public class AppearanceManager { respawn.setGameMode(player.getGameMode()); respawn.setPreviousGameMode(player.getGameMode()); respawn.setCopyMetadata(true); - //respawn.sendPacket(player); + respawn.sendPacket(player); player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN); player.setAllowFlight(wasAllowedToFly); player.setFlying(wasFlying); diff --git a/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerRespawn.java b/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerRespawn.java index 44aa02a..bcb4ad6 100644 --- a/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerRespawn.java +++ b/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerRespawn.java @@ -3,9 +3,10 @@ package xyz.ineanto.nicko.wrapper; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.InternalStructure; import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.reflect.accessors.Accessors; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftVersion; -import com.comphenix.protocol.wrappers.BukkitConverters; import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.MinecraftKey; import com.google.common.hash.Hashing; @@ -23,32 +24,53 @@ import org.bukkit.World; public class WrapperPlayServerRespawn extends AbstractPacket { public static final PacketType TYPE = PacketType.Play.Server.RESPAWN; - private final InternalStructure spawnInfoStructure; + private InternalStructure spawnInfoStructure = null; public WrapperPlayServerRespawn() { super(new PacketContainer(TYPE), TYPE); handle.getModifier().writeDefaults(); - spawnInfoStructure = handle.getStructures().readSafely(0); + if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { + spawnInfoStructure = handle.getStructures().read(0); + } } public void setDimension(World value) { - if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { - // 1.20 to 1.20.1 (by lukalt) - final InternalStructure dimensionType = handle.getStructures().read(0); + final MinecraftVersion v1_20_5 = new MinecraftVersion(1, 20, 5); + + if (!MinecraftVersion.getCurrentVersion().isAtLeast(v1_20_5)) { + // 1.20.1 - 1.20.4 + final StructureModifier structureModifier = spawnInfoStructure == null ? + handle.getStructures() : spawnInfoStructure.getStructures(); + + final StructureModifier worldStructureModifier = spawnInfoStructure == null ? + handle.getWorldKeys() : spawnInfoStructure.getWorldKeys(); + + final InternalStructure dimensionType = structureModifier.read(0); dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type")); dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld")); - handle.getStructures().writeSafely(0, dimensionType); - handle.getWorldKeys().writeSafely(0, value); - return; - } + structureModifier.writeSafely(0, dimensionType); + worldStructureModifier.writeSafely(0, value); + } else { + // 1.20.5 to 1.21.1 + + // why is life so hard? + // Get the key from that class + final MinecraftKey key = MinecraftKey.fromHandle( + Accessors.getFieldAccessor( + TYPE.getPacketClass(), + MinecraftReflection.getResourceKey(), + true + ) + .get(spawnInfoStructure)); + + // Set the key + Accessors.getFieldAccessor( + spawnInfoStructure.getClass(), + MinecraftReflection.getResourceKey(), + true + ) + .set(spawnInfoStructure, key); - // 1.20.2 to 1.21 - if (MinecraftVersion.TRAILS_AND_TAILS.atOrAbove() && !MinecraftVersion.v1_21_0.atOrAbove()) { - spawnInfoStructure.getHolders( - MinecraftReflection.getDimensionManager(), - BukkitConverters.getDimensionConverter() - ).write(0, value); - spawnInfoStructure.getWorldKeys().writeSafely(0, value); handle.getStructures().writeSafely(0, spawnInfoStructure); } }