From a98d5a75bdc30686d9def1551c3322d6ccbb0ca8 Mon Sep 17 00:00:00 2001 From: ineanto Date: Tue, 20 Aug 2024 22:44:15 +0200 Subject: [PATCH] feat(wrapper): only support 1.20/1.21 (not working for >1.20.2?) --- .../java/xyz/ineanto/nicko/NickoBukkit.java | 3 +- .../nicko/appearance/AppearanceManager.java | 2 +- .../wrapper/WrapperPlayServerRespawn.java | 90 +++++++++---------- src/main/resources/plugin.yml | 2 +- 4 files changed, 45 insertions(+), 52 deletions(-) diff --git a/src/main/java/xyz/ineanto/nicko/NickoBukkit.java b/src/main/java/xyz/ineanto/nicko/NickoBukkit.java index 2ec8bc6..3073e52 100644 --- a/src/main/java/xyz/ineanto/nicko/NickoBukkit.java +++ b/src/main/java/xyz/ineanto/nicko/NickoBukkit.java @@ -64,8 +64,9 @@ public class NickoBukkit extends JavaPlugin { dataStore = new PlayerDataStore(mojangAPI, getNickoConfig()); - if (!MinecraftVersion.WILD_UPDATE.atOrAbove()) { + if (!MinecraftVersion.TRAILS_AND_TAILS.atOrAbove()) { getLogger().severe("This version (" + MinecraftVersion.getCurrentVersion().getVersion() + ") is not supported by Nicko!"); + getLogger().severe("As of version 1.0.7, Nicko only supports the latest two majors Minecraft versions. (Currently 1.20.X-1.21.X)"); dataStore.getStorage().setError(true); Bukkit.getPluginManager().disablePlugin(this); } diff --git a/src/main/java/xyz/ineanto/nicko/appearance/AppearanceManager.java b/src/main/java/xyz/ineanto/nicko/appearance/AppearanceManager.java index 66f020e..3355aa9 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 f24fed9..44aa02a 100644 --- a/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerRespawn.java +++ b/src/main/java/xyz/ineanto/nicko/wrapper/WrapperPlayServerRespawn.java @@ -3,95 +3,87 @@ 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.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftVersion; -import com.comphenix.protocol.wrappers.*; +import com.comphenix.protocol.wrappers.BukkitConverters; +import com.comphenix.protocol.wrappers.EnumWrappers; +import com.comphenix.protocol.wrappers.MinecraftKey; import com.google.common.hash.Hashing; import org.bukkit.GameMode; import org.bukkit.World; /** - * PacketPlayServerRespawn Wrapper class (1.19 to 1.21 (one day)) - * - * @author ineanto, based on work from dmulloy2 and Kristian S. Strangeland + * PacketPlayServerRespawn Wrapper class (1.20.X to 1.21.X) *

- * In 1.20.2, all the fields were replaced with a - * single "CommonPlayerSpawnInfo" record object. + * In 1.20.2, all the fields were merged inside a + * single "CommonPlayerSpawnInfo" record. + * + * @author inenato (w/ additional help from lukalt), based on work from dmulloy2 and Kristian S. Strangeland */ public class WrapperPlayServerRespawn extends AbstractPacket { public static final PacketType TYPE = PacketType.Play.Server.RESPAWN; - private final InternalStructure commonPlayerSpawnInfoStructure; + private final InternalStructure spawnInfoStructure; public WrapperPlayServerRespawn() { super(new PacketContainer(TYPE), TYPE); handle.getModifier().writeDefaults(); - commonPlayerSpawnInfoStructure = handle.getStructures().readSafely(0); + spawnInfoStructure = handle.getStructures().readSafely(0); } public void setDimension(World value) { - if (commonPlayerSpawnInfoStructure == null) { - System.out.println("cPSIS null"); - // 1.19 to 1.20.1, props to lukalt for helping me figure this out. - writeDimensionToStructure(value, handle.getStructures(), handle.getWorldKeys()); + if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { + // 1.20 to 1.20.1 (by lukalt) + final InternalStructure dimensionType = handle.getStructures().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; } // 1.20.2 to 1.21 - writeDimensionToStructure(value, commonPlayerSpawnInfoStructure.getStructures(), commonPlayerSpawnInfoStructure.getWorldKeys()); + 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); + } } public void setGameMode(GameMode value) { - if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { - commonPlayerSpawnInfoStructure.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value)); + if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { + // 1.20 to 1.20.1 + handle.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value)); return; } - handle.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value)); + + spawnInfoStructure.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value)); } public void setPreviousGameMode(GameMode value) { - if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { - commonPlayerSpawnInfoStructure.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value)); + if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { + // 1.20 to 1.20.1 + handle.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value)); return; } - handle.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value)); + + spawnInfoStructure.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value)); } public void setCopyMetadata(boolean value) { - if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) return; - if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { - handle.getBytes().writeSafely(0, ((byte) (value ? 0x01 : 0x00))); - } else { - handle.getBooleans().writeSafely(0, value); - } + if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) return; + + // 1.20 to 1.20.1 + handle.getBooleans().writeSafely(0, value); } public void setSeed(long value) { - if (MinecraftVersion.WILD_UPDATE.atOrAbove() && !MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { + if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { + // 1.20 to 1.20.1 handle.getLongs().writeSafely(0, Hashing.sha256().hashLong(value).asLong()); } } - - private void writeDimensionToStructure(World value, StructureModifier structures, StructureModifier worldKeys) { - if (MinecraftVersion.TRAILS_AND_TAILS.atOrAbove() && !MinecraftVersion.v1_20_5.atOrAbove()) { - final InternalStructure dimensionType = structures.readSafely(0); - if (dimensionType != null) { - // 1.20.2 to 1.20.5 - dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type")); - dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld")); - structures.writeSafely(0, dimensionType); - } - } else { - // 1.20.5/6 to 1.21 - final StructureModifier worldHolder = commonPlayerSpawnInfoStructure.getHolders( - MinecraftReflection.getDimensionManager(), - Converters.holder(BukkitConverters.getDimensionConverter(), - WrappedRegistry.getDimensionRegistry()) - ); - worldHolder.writeSafely(0, value); - } - - worldKeys.writeSafely(0, value); - } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6ccf67a..7adaa7e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ main: xyz.ineanto.nicko.NickoBukkit version: ${version} author: Ineanto description: "The feature packed, next generation disguise plugin for Minecraft." -api-version: 1.19 +api-version: 1.20 softdepend: [ PlaceholderAPI ] depend: - ProtocolLib