From 6845acd89d98986f4951a84c63ff9b878d2651ae Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sat, 26 Oct 2024 15:21:23 -0500 Subject: [PATCH] Update to 1.21.3 --- build.gradle | 12 +- .../com/comphenix/protocol/PacketType.java | 319 +++++++++--------- .../protocol/utility/MinecraftVersion.java | 7 +- .../protocol/wrappers/EnumWrappers.java | 9 +- .../protocol/wrappers/PlayerInfoData.java | 108 ++++-- .../protocol/wrappers/WrappedParticle.java | 120 ++++--- .../protocol/BukkitInitialization.java | 77 ++--- .../protocol/events/PacketContainerTest.java | 6 +- .../injector/EntityUtilitiesTest.java | 13 +- .../utility/MinecraftReflectionTest.java | 2 +- .../utility/MinecraftReflectionTestUtil.java | 2 +- .../utility/MinecraftVersionTest.java | 2 +- .../wrappers/ChunkCoordIntPairTest.java | 9 +- .../wrappers/WrappedAttributeTest.java | 2 +- .../wrappers/WrappedBlockDataTest.java | 8 +- .../wrappers/WrappedDataWatcherTest.java | 4 +- .../wrappers/WrappedStreamCodecTests.java | 4 +- 17 files changed, 386 insertions(+), 318 deletions(-) diff --git a/build.gradle b/build.gradle index d02c2981..4ea2ef8e 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'com.comphenix.protocol' -version = '5.3.0' +version = '5.4.0-SNAPSHOT' description = 'Provides access to the Minecraft protocol' def isSnapshot = version.endsWith('-SNAPSHOT') @@ -34,8 +34,8 @@ repositories { dependencies { implementation 'net.bytebuddy:byte-buddy:1.15.1' - compileOnly 'org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT' - compileOnly 'org.spigotmc:spigot:1.21.1-R0.1-SNAPSHOT' + compileOnly 'org.spigotmc:spigot-api:1.21.3-R0.1-SNAPSHOT' + compileOnly 'org.spigotmc:spigot:1.21.3-R0.1-SNAPSHOT' compileOnly 'io.netty:netty-all:4.0.23.Final' compileOnly 'net.kyori:adventure-text-serializer-gson:4.14.0' compileOnly 'com.googlecode.json-simple:json-simple:1.1.1' @@ -46,14 +46,14 @@ dependencies { testImplementation 'org.mockito:mockito-core:5.6.0' testImplementation 'io.netty:netty-common:4.1.97.Final' testImplementation 'io.netty:netty-transport:4.1.97.Final' - testImplementation 'org.spigotmc:spigot:1.21.1-R0.1-SNAPSHOT' + testImplementation 'org.spigotmc:spigot:1.21.3-R0.1-SNAPSHOT' testImplementation 'net.kyori:adventure-text-serializer-gson:4.14.0' testImplementation 'net.kyori:adventure-text-serializer-plain:4.14.0' } java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 withJavadocJar() withSourcesJar() diff --git a/src/main/java/com/comphenix/protocol/PacketType.java b/src/main/java/com/comphenix/protocol/PacketType.java index 9471674a..42ca24fa 100644 --- a/src/main/java/com/comphenix/protocol/PacketType.java +++ b/src/main/java/com/comphenix/protocol/PacketType.java @@ -139,100 +139,105 @@ public class PacketType implements Serializable, Cloneable, Comparable, Serializable { + /** + * Version 1.21.2 - the bundles of bravery drop + */ + public static final MinecraftVersion v1_21_2 = new MinecraftVersion("1.21.2"); + /** * Version 1.21.0 - the tricky trials update */ @@ -149,7 +154,7 @@ public final class MinecraftVersion implements Comparable, Ser /** * The latest release version of minecraft. */ - public static final MinecraftVersion LATEST = v1_21_0; + public static final MinecraftVersion LATEST = v1_21_2; // used when serializing private static final long serialVersionUID = -8695133558996459770L; diff --git a/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java b/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java index c848d004..8096dac5 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java +++ b/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java @@ -11,10 +11,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import org.apache.commons.lang.Validate; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; - import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType.Protocol; import com.comphenix.protocol.ProtocolLogger; @@ -27,6 +23,10 @@ import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftVersion; +import org.apache.commons.lang.Validate; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; + /** * Represents a generic enum converter. * @author Kristian @@ -140,6 +140,7 @@ public abstract class EnumWrappers { UPDATE_LISTED, UPDATE_LATENCY, UPDATE_DISPLAY_NAME, + UPDATE_LIST_ORDER, /** * @deprecated Removed in 1.19.3 */ diff --git a/src/main/java/com/comphenix/protocol/wrappers/PlayerInfoData.java b/src/main/java/com/comphenix/protocol/wrappers/PlayerInfoData.java index f339a2f0..d0ed0991 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/PlayerInfoData.java +++ b/src/main/java/com/comphenix/protocol/wrappers/PlayerInfoData.java @@ -16,12 +16,12 @@ */ package com.comphenix.protocol.wrappers; -import com.comphenix.protocol.wrappers.WrappedProfilePublicKey.WrappedProfileKeyData; import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.UUID; +import javax.annotation.Nullable; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.reflect.EquivalentConverter; @@ -29,8 +29,7 @@ import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftVersion; import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; - -import javax.annotation.Nullable; +import com.comphenix.protocol.wrappers.WrappedProfilePublicKey.WrappedProfileKeyData; /** * Represents an immutable PlayerInfoData in the PLAYER_INFO packet. @@ -41,6 +40,7 @@ public class PlayerInfoData { private final UUID profileId; private final int latency; + private final int listOrder = 0; private final boolean listed; private final NativeGameMode gameMode; private final WrappedGameProfile profile; @@ -202,7 +202,9 @@ public class PlayerInfoData { * @return A new converter. */ public static EquivalentConverter getConverter() { - return new EquivalentConverter() { + return new EquivalentConverter<>() { + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + @Override public Object getGeneric(PlayerInfoData specific) { if (constructor == null) { @@ -225,13 +227,17 @@ public class PlayerInfoData { args.add(EnumWrappers.getGameModeClass()); args.add(MinecraftReflection.getIChatBaseComponentClass()); + if (MinecraftVersion.v1_21_2.atOrAbove()) { + args.add(int.class); + } + if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { args.add(MinecraftReflection.getRemoteChatSessionDataClass()); } else if (MinecraftVersion.WILD_UPDATE.atOrAbove()) { args.add(MinecraftReflection.getProfilePublicKeyDataClass()); } - constructor = MinecraftReflection.getPlayerInfoDataClass().getConstructor(args.toArray(new Class[0])); + constructor = MinecraftReflection.getPlayerInfoDataClass().getConstructor(args.toArray(EMPTY_CLASS_ARRAY)); } catch (Exception e) { throw new RuntimeException("Cannot find PlayerInfoData constructor.", e); } @@ -242,30 +248,58 @@ public class PlayerInfoData { try { Object gameMode = EnumWrappers.getGameModeConverter().getGeneric(specific.gameMode); Object displayName = specific.displayName != null ? specific.displayName.handle : null; - Object profile = specific.profile != null ? specific.profile.handle : null; - if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { - return constructor.newInstance( - specific.profileId, - profile, - specific.listed, - specific.latency, - gameMode, - displayName, - specific.remoteChatSessionData != null ? BukkitConverters.getWrappedRemoteChatSessionDataConverter().getGeneric(specific.remoteChatSessionData) : null - ); + Object remoteChatSessionData = specific.remoteChatSessionData != null ? BukkitConverters.getWrappedRemoteChatSessionDataConverter().getGeneric(specific.remoteChatSessionData) : null; + + Object[] args; + + if (MinecraftVersion.v1_21_2.atOrAbove()) { + args = new Object[] { + specific.profileId, + profile, + specific.listed, + specific.latency, + gameMode, + displayName, + specific.listOrder, + remoteChatSessionData + }; + } else if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { + args = new Object[] { + specific.profileId, + profile, + specific.listed, + specific.latency, + gameMode, + displayName, + remoteChatSessionData + }; } else if (MinecraftVersion.WILD_UPDATE.atOrAbove()) { - return constructor.newInstance( - profile, - specific.latency, - gameMode, - displayName, - specific.profileKeyData == null ? null : specific.profileKeyData.handle); + args = new Object[] { + profile, + specific.latency, + gameMode, + displayName, + specific.profileKeyData == null ? null : specific.profileKeyData.handle + }; } else if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) { - return constructor.newInstance(profile, specific.latency, gameMode, displayName); + args = new Object[] { + profile, + specific.latency, + gameMode, + displayName + }; } else { - return constructor.newInstance(null, profile, specific.latency, gameMode, displayName); + args = new Object[] { + null, + profile, + specific.latency, + gameMode, + displayName + }; } + + return constructor.newInstance(args); } catch (Exception e) { throw new RuntimeException("Failed to construct PlayerInfoData.", e); } @@ -275,37 +309,37 @@ public class PlayerInfoData { public PlayerInfoData getSpecific(Object generic) { if (MinecraftReflection.isPlayerInfoData(generic)) { StructureModifier modifier = new StructureModifier<>(generic.getClass(), null, false) - .withTarget(generic); + .withTarget(generic); StructureModifier gameProfiles = modifier.withType( - MinecraftReflection.getGameProfileClass(), BukkitConverters.getWrappedGameProfileConverter()); + MinecraftReflection.getGameProfileClass(), BukkitConverters.getWrappedGameProfileConverter()); WrappedGameProfile gameProfile = gameProfiles.read(0); StructureModifier ints = modifier.withType(int.class); int latency = ints.read(0); StructureModifier gameModes = modifier.withType( - EnumWrappers.getGameModeClass(), EnumWrappers.getGameModeConverter()); + EnumWrappers.getGameModeClass(), EnumWrappers.getGameModeConverter()); NativeGameMode gameMode = gameModes.read(0); StructureModifier displayNames = modifier.withType( - MinecraftReflection.getIChatBaseComponentClass(), BukkitConverters.getWrappedChatComponentConverter()); + MinecraftReflection.getIChatBaseComponentClass(), BukkitConverters.getWrappedChatComponentConverter()); WrappedChatComponent displayName = displayNames.read(0); - if(MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { + if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { return new PlayerInfoData(modifier.withType(UUID.class).read(0), - latency, - modifier.withType(boolean.class).read(0), - gameMode, - gameProfile, - displayName, - modifier.withType(MinecraftReflection.getRemoteChatSessionDataClass(), BukkitConverters.getWrappedRemoteChatSessionDataConverter()).read(0) - ); + latency, + modifier.withType(boolean.class).read(0), + gameMode, + gameProfile, + displayName, + modifier.withType(MinecraftReflection.getRemoteChatSessionDataClass(), BukkitConverters.getWrappedRemoteChatSessionDataConverter()).read(0) + ); } WrappedProfileKeyData key = null; if (MinecraftVersion.WILD_UPDATE.atOrAbove()) { StructureModifier keyData = modifier.withType( - MinecraftReflection.getProfilePublicKeyDataClass(), BukkitConverters.getWrappedPublicKeyDataConverter()); + MinecraftReflection.getProfilePublicKeyDataClass(), BukkitConverters.getWrappedPublicKeyDataConverter()); key = keyData.read(0); } diff --git a/src/main/java/com/comphenix/protocol/wrappers/WrappedParticle.java b/src/main/java/com/comphenix/protocol/wrappers/WrappedParticle.java index eeef01b4..e7b7c157 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/WrappedParticle.java +++ b/src/main/java/com/comphenix/protocol/wrappers/WrappedParticle.java @@ -183,59 +183,80 @@ public class WrappedParticle { } private static Object getRedstone(Object handle) { - int r, g, b; - float size; + Color color; + float scale; - if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { - StructureModifier modifier = new StructureModifier<>(handle.getClass()).withTarget(handle); + StructureModifier modifier = new StructureModifier<>(handle.getClass()).withTarget(handle); + + if (MinecraftVersion.v1_21_2.atOrAbove()) { + int rgb = (int) modifier.withType(int.class).read(0); + color = Color.fromRGB(rgb); + scale = (float) modifier.withType(float.class).read(0); + } else if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { org.joml.Vector3f rgb = (org.joml.Vector3f) modifier.withType(org.joml.Vector3f.class).read(0); - r = (int) (rgb.x() * 255); - g = (int) (rgb.y() * 255); - b = (int) (rgb.z() * 255); - size = (float) modifier.withType(float.class).read(0); + int red = (int) (rgb.x() * 255); + int green = (int) (rgb.y() * 255); + int blue = (int) (rgb.z() * 255); + + color = Color.fromRGB(red, green, blue); + scale = (float) modifier.withType(float.class).read(0); } else if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) { if (VECTOR_3FA == null) { VECTOR_3FA = MinecraftReflection.getLibraryClass("com.mojang.math.Vector3fa"); } - StructureModifier modifier = new StructureModifier<>(handle.getClass()).withTarget(handle); - Object rgb = modifier.withType(VECTOR_3FA).read(0); StructureModifier rgbModifier = new StructureModifier<>(VECTOR_3FA).withTarget(rgb); - r = (int) (rgbModifier.withType(float.class).read(0) * 255); - g = (int) (rgbModifier.withType(float.class).read(1) * 255); - b = (int) (rgbModifier.withType(float.class).read(2) * 255); - size = (float) modifier.withType(float.class).read(0); + int red = (int) (rgbModifier.withType(float.class).read(0) * 255); + int green = (int) (rgbModifier.withType(float.class).read(1) * 255); + int blue = (int) (rgbModifier.withType(float.class).read(2) * 255); + + color = Color.fromRGB(red, green, blue); + scale = (float) modifier.withType(float.class).read(0); } else { - StructureModifier modifier = new StructureModifier<>(handle.getClass()).withTarget(handle).withType(float.class); - r = (int) (modifier.read(0) * 255); - g = (int) (modifier.read(1) * 255); - b = (int) (modifier.read(2) * 255); - size = modifier.read(3); + StructureModifier floatModifier = modifier.withType(float.class); + + int red = (int) (floatModifier.read(0) * 255); + int green = (int) (floatModifier.read(1) * 255); + int blue = (int) (floatModifier.read(2) * 255); + + color = Color.fromRGB(red, green, blue); + scale = floatModifier.read(3); } - return new Particle.DustOptions(Color.fromRGB(r, g, b), size); + return new Particle.DustOptions(color, scale); } private static Object getDustTransition(Object handle) { - int fromR, fromG, fromB, toR, toG, toB; - float size; + Color fromColor, toColor; + float scale; - if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { + if (MinecraftVersion.v1_21_2.atOrAbove()) { + StructureModifier modifier = new StructureModifier<>(handle.getClass()).withTarget(handle); + int fromRgb = (int) modifier.withType(int.class).read(0); + fromColor = Color.fromRGB(fromRgb); + + int toRgb = (int) modifier.withType(int.class).read(1); + toColor = Color.fromRGB(toRgb); + + scale = (float) modifier.withType(float.class).read(0); + } else if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { StructureModifier modifier = new StructureModifier<>(handle.getClass()).withTarget(handle); org.joml.Vector3f toRGB = (org.joml.Vector3f) modifier.withType(org.joml.Vector3f.class).read(1); org.joml.Vector3f fromRGB = (org.joml.Vector3f) modifier.withType(org.joml.Vector3f.class).read(0); - size = (float) modifier.withType(float.class).read(0); + scale = (float) modifier.withType(float.class).read(0); - fromR = (int) (fromRGB.x() * 255); - fromG = (int) (fromRGB.y() * 255); - fromB = (int) (fromRGB.z() * 255); + int fromR = (int) (fromRGB.x() * 255); + int fromG = (int) (fromRGB.y() * 255); + int fromB = (int) (fromRGB.z() * 255); + fromColor = Color.fromRGB(fromR, fromG, fromB); - toR = (int) (toRGB.x() * 255); - toG = (int) (toRGB.y() * 255); - toB = (int) (toRGB.z() * 255); + int toR = (int) (toRGB.x() * 255); + int toG = (int) (toRGB.y() * 255); + int toB = (int) (toRGB.z() * 255); + toColor = Color.fromRGB(toR, toG, toB); } else if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) { if (VECTOR_3FA == null) { VECTOR_3FA = MinecraftReflection.getLibraryClass("com.mojang.math.Vector3fa"); @@ -245,37 +266,42 @@ public class WrappedParticle { Object toRGB = modifier.withType(VECTOR_3FA).read(0); Object fromRGB = modifier.withType(VECTOR_3FA).read(1); - size = (float) modifier.withType(float.class).read(0); + scale = (float) modifier.withType(float.class).read(0); StructureModifier rgbModifier = new StructureModifier<>(VECTOR_3FA).withTarget(fromRGB); StructureModifier rgbModifier2 = new StructureModifier<>(VECTOR_3FA).withTarget(toRGB); - fromR = (int) (rgbModifier.withType(float.class).read(0) * 255); - fromG = (int) (rgbModifier.withType(float.class).read(1) * 255); - fromB = (int) (rgbModifier.withType(float.class).read(2) * 255); + int fromR = (int) (rgbModifier.withType(float.class).read(0) * 255); + int fromG = (int) (rgbModifier.withType(float.class).read(1) * 255); + int fromB = (int) (rgbModifier.withType(float.class).read(2) * 255); + fromColor = Color.fromRGB(fromR, fromG, fromB); - toR = (int) (rgbModifier2.withType(float.class).read(0) * 255); - toG = (int) (rgbModifier2.withType(float.class).read(1) * 255); - toB = (int) (rgbModifier2.withType(float.class).read(2) * 255); + int toR = (int) (rgbModifier2.withType(float.class).read(0) * 255); + int toG = (int) (rgbModifier2.withType(float.class).read(1) * 255); + int toB = (int) (rgbModifier2.withType(float.class).read(2) * 255); + toColor = Color.fromRGB(toR, toG, toB); } else { StructureModifier modifier = new StructureModifier<>(handle.getClass()).withTarget(handle).withType(float.class); - toR = (int) (modifier.read(0) * 255); - toG = (int) (modifier.read(1) * 255); - toB = (int) (modifier.read(2) * 255); - size = modifier.read(3); - fromR = (int) (modifier.read(4) * 255); - fromG = (int) (modifier.read(5) * 255); - fromB = (int) (modifier.read(6) * 255); + int toR = (int) (modifier.read(0) * 255); + int toG = (int) (modifier.read(1) * 255); + int toB = (int) (modifier.read(2) * 255); + toColor = Color.fromRGB(toR, toG, toB); + + scale = modifier.read(3); + + int fromR = (int) (modifier.read(4) * 255); + int fromG = (int) (modifier.read(5) * 255); + int fromB = (int) (modifier.read(6) * 255); + fromColor = Color.fromRGB(fromR, fromG, fromB); } - return new Particle.DustTransition(Color.fromRGB(fromR, fromG, fromB), Color.fromRGB(toR, toG, toB), size); + return new Particle.DustTransition(fromColor, toColor, scale); } public static WrappedParticle create(Particle particle, T data) { ensureMethods(); Object bukkitData = data; - if (data instanceof WrappedBlockData) { - WrappedBlockData blockData = (WrappedBlockData) data; + if (data instanceof WrappedBlockData blockData) { bukkitData = toCraftData.invoke(null, blockData.getHandle()); } diff --git a/src/test/java/com/comphenix/protocol/BukkitInitialization.java b/src/test/java/com/comphenix/protocol/BukkitInitialization.java index 3b300919..76d2d5d2 100644 --- a/src/test/java/com/comphenix/protocol/BukkitInitialization.java +++ b/src/test/java/com/comphenix/protocol/BukkitInitialization.java @@ -13,7 +13,8 @@ import com.comphenix.protocol.utility.MinecraftReflectionTestUtil; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.MoreExecutors; import net.minecraft.SharedConstants; -import net.minecraft.commands.CommandDispatcher; +import net.minecraft.commands.CommandDispatcher.ServerType; +import net.minecraft.core.HolderLookup; import net.minecraft.core.IRegistry; import net.minecraft.core.IRegistryCustom; import net.minecraft.core.LayeredRegistryAccess; @@ -24,14 +25,15 @@ import net.minecraft.resources.RegistryDataLoader; import net.minecraft.server.DataPackResources; import net.minecraft.server.DispenserRegistry; import net.minecraft.server.RegistryLayer; -import net.minecraft.server.WorldLoader; import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.server.level.WorldServer; import net.minecraft.server.packs.EnumResourcePackType; import net.minecraft.server.packs.repository.ResourcePackLoader; import net.minecraft.server.packs.repository.ResourcePackRepository; import net.minecraft.server.packs.repository.ResourcePackSourceVanilla; +import net.minecraft.server.packs.resources.IResourceManager; import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.tags.TagDataPack; import net.minecraft.tags.TagKey; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.flag.FeatureFlags; @@ -45,18 +47,18 @@ import org.bukkit.Keyed; import org.bukkit.NamespacedKey; import org.bukkit.Registry; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_21_R1.CraftLootTable; -import org.bukkit.craftbukkit.v1_21_R1.CraftRegistry; -import org.bukkit.craftbukkit.v1_21_R1.CraftServer; -import org.bukkit.craftbukkit.v1_21_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemFactory; -import org.bukkit.craftbukkit.v1_21_R1.tag.CraftBlockTag; -import org.bukkit.craftbukkit.v1_21_R1.tag.CraftEntityTag; -import org.bukkit.craftbukkit.v1_21_R1.tag.CraftFluidTag; -import org.bukkit.craftbukkit.v1_21_R1.tag.CraftItemTag; -import org.bukkit.craftbukkit.v1_21_R1.util.CraftMagicNumbers; -import org.bukkit.craftbukkit.v1_21_R1.util.CraftNamespacedKey; -import org.bukkit.craftbukkit.v1_21_R1.util.Versioning; +import org.bukkit.craftbukkit.v1_21_R2.CraftLootTable; +import org.bukkit.craftbukkit.v1_21_R2.CraftRegistry; +import org.bukkit.craftbukkit.v1_21_R2.CraftServer; +import org.bukkit.craftbukkit.v1_21_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemFactory; +import org.bukkit.craftbukkit.v1_21_R2.tag.CraftBlockTag; +import org.bukkit.craftbukkit.v1_21_R2.tag.CraftEntityTag; +import org.bukkit.craftbukkit.v1_21_R2.tag.CraftFluidTag; +import org.bukkit.craftbukkit.v1_21_R2.tag.CraftItemTag; +import org.bukkit.craftbukkit.v1_21_R2.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.v1_21_R2.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.v1_21_R2.util.Versioning; import org.jetbrains.annotations.NotNull; import org.spigotmc.SpigotWorldConfig; @@ -110,30 +112,19 @@ public class BukkitInitialization { instance.setPackage(); - // Minecraft Data Init - SharedConstants.a(); // .tryDetectVersion() - DispenserRegistry.a(); // .bootStrap() - - ResourcePackRepository resourcePackRepository = ResourcePackSourceVanilla.c(); // .createVanillaTrustedRepository() - resourcePackRepository.a(); // .reload() - - ResourceManager resourceManager = new ResourceManager( - EnumResourcePackType.b /* SERVER_DATA */, - resourcePackRepository.c() /* getAvailablePacks() */ .stream().map(ResourcePackLoader::f /* openFull() */).collect(Collectors.toList())); - LayeredRegistryAccess layeredRegistryAccess = RegistryLayer.a(); // .createRegistryAccess() - layeredRegistryAccess = WorldLoader.b(resourceManager, layeredRegistryAccess, RegistryLayer.b /* WORLDGEN */, RegistryDataLoader.a /* WORLDGEN_REGISTRIES */); // .loadAndReplaceLayer() - IRegistryCustom.Dimension registryCustom = layeredRegistryAccess.a().d(); // .compositeAccess().freeze() - // IRegistryCustom.Dimension registryCustom = layeredRegistryAccess.a().c(); // .compositeAccess().freeze() - - DataPackResources dataPackResources = DataPackResources.a( - resourceManager, - layeredRegistryAccess, - FeatureFlags.d.a() /* REGISTRY.allFlags() */, - CommandDispatcher.ServerType.b /* DEDICATED */, - 0, - MoreExecutors.directExecutor(), - MoreExecutors.directExecutor() - ).join(); + SharedConstants.a(); + DispenserRegistry.a(); + ResourcePackRepository resourcePackRepository = ResourcePackSourceVanilla.c(); + resourcePackRepository.a(); + IResourceManager resourceManager = new ResourceManager(EnumResourcePackType.b, resourcePackRepository.d().stream().map(ResourcePackLoader::f).collect(Collectors.toList())); + LayeredRegistryAccess layeredregistryaccess = RegistryLayer.a(); + List> list = TagDataPack.a(resourceManager, layeredregistryaccess.a(RegistryLayer.a)); + IRegistryCustom.Dimension frozen1 = layeredregistryaccess.b(RegistryLayer.b); + List> list1 = TagDataPack.a(frozen1, list); + IRegistryCustom.Dimension frozen2 = RegistryDataLoader.a(resourceManager, list1, RegistryDataLoader.a); + LayeredRegistryAccess layers = layeredregistryaccess.a(RegistryLayer.b, frozen2); + IRegistryCustom.Dimension registryCustom = layers.a().e(); + DataPackResources dataPackResources = DataPackResources.a(resourceManager, layers, list, FeatureFlags.f.a(), ServerType.b, 0, MoreExecutors.directExecutor(), MoreExecutors.directExecutor()).join(); dataPackResources.g(); try { @@ -149,7 +140,7 @@ public class BukkitInitialization { CraftServer mockedServer = mock(CraftServer.class); DedicatedServer mockedGameServer = mock(DedicatedServer.class); - when(mockedGameServer.bc()/*registryAccess*/).thenReturn(registryCustom); + when(mockedGameServer.ba()/*registryAccess*/).thenReturn(registryCustom); when(mockedServer.getLogger()).thenReturn(java.util.logging.Logger.getLogger("Minecraft")); when(mockedServer.getName()).thenReturn("Mock Server"); @@ -185,28 +176,28 @@ public class BukkitInitialization { case org.bukkit.Tag.REGISTRY_BLOCKS -> { Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Block namespace must have block type"); TagKey blockTagKey = TagKey.a(Registries.f, key); - if (BuiltInRegistries.e.b(blockTagKey).isPresent()) { + if (BuiltInRegistries.e.a(blockTagKey).isPresent()) { return new CraftBlockTag(BuiltInRegistries.e, blockTagKey); } } case org.bukkit.Tag.REGISTRY_ITEMS -> { Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Item namespace must have item type"); TagKey itemTagKey = TagKey.a(Registries.K, key); - if (BuiltInRegistries.g.b(itemTagKey).isPresent()) { + if (BuiltInRegistries.g.a(itemTagKey).isPresent()) { return new CraftItemTag(BuiltInRegistries.g, itemTagKey); } } case org.bukkit.Tag.REGISTRY_FLUIDS -> { Preconditions.checkArgument(clazz == org.bukkit.Fluid.class, "Fluid namespace must have fluid type"); TagKey fluidTagKey = TagKey.a(Registries.D, key); - if (BuiltInRegistries.c.b(fluidTagKey).isPresent()) { + if (BuiltInRegistries.c.a(fluidTagKey).isPresent()) { return new CraftFluidTag(BuiltInRegistries.c, fluidTagKey); } } case org.bukkit.Tag.REGISTRY_ENTITY_TYPES -> { Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace must have entity type"); TagKey> entityTagKey = TagKey.a(Registries.z, key); - if (BuiltInRegistries.f.b(entityTagKey).isPresent()) { + if (BuiltInRegistries.f.a(entityTagKey).isPresent()) { return new CraftEntityTag(BuiltInRegistries.f, entityTagKey); } } diff --git a/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java b/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java index 96a31daf..8826101b 100644 --- a/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java +++ b/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java @@ -182,13 +182,13 @@ public class PacketContainerTest { this.testPrimitive(updateTime.getLongs(), 0, (long) 0, (long) 1); } - @Test + // @Test // TODO: Explosion no longer contains floats public void testGetFloat() { PacketContainer explosion = new PacketContainer(PacketType.Play.Server.EXPLOSION); this.testPrimitive(explosion.getFloat(), 0, (float) 0, (float) 0.8); } - @Test + // @Test // TODO: Explosion no longer contains doubles public void testGetDoubles() { PacketContainer explosion = new PacketContainer(PacketType.Play.Server.EXPLOSION); this.testPrimitive(explosion.getDoubles(), 0, (double) 0, 0.8); @@ -318,7 +318,7 @@ public class PacketContainerTest { assertEquals(packet.getEntityTypeModifier().read(0), EntityType.ARROW); } - @Test + // @Test // TODO: explosion no longer contains block position list public void testGetPositionCollectionModifier() { PacketContainer explosionPacket = new PacketContainer(PacketType.Play.Server.EXPLOSION); StructureModifier> positionAccessor = explosionPacket.getBlockPositionCollectionModifier(); diff --git a/src/test/java/com/comphenix/protocol/injector/EntityUtilitiesTest.java b/src/test/java/com/comphenix/protocol/injector/EntityUtilitiesTest.java index c759e1c1..218cdf5d 100644 --- a/src/test/java/com/comphenix/protocol/injector/EntityUtilitiesTest.java +++ b/src/test/java/com/comphenix/protocol/injector/EntityUtilitiesTest.java @@ -5,19 +5,22 @@ import java.lang.reflect.Field; import com.comphenix.protocol.BukkitInitialization; import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + import net.minecraft.server.level.ChunkProviderServer; import net.minecraft.server.level.PlayerChunkMap; import net.minecraft.server.level.PlayerChunkMap.EntityTracker; import net.minecraft.server.level.WorldServer; import net.minecraft.world.entity.Entity; -import org.bukkit.craftbukkit.v1_21_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_21_R1.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_21_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_21_R2.entity.CraftEntity; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + import static com.comphenix.protocol.utility.TestUtils.setFinalField; + import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -35,7 +38,7 @@ public class EntityUtilitiesTest { when(bukkit.getHandle()).thenReturn(world); ChunkProviderServer provider = mock(ChunkProviderServer.class); - when(world.l()).thenReturn(provider); + when(world.m()).thenReturn(provider); PlayerChunkMap chunkMap = mock(PlayerChunkMap.class); Field chunkMapField = FuzzyReflection.fromClass(ChunkProviderServer.class, true) diff --git a/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java b/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java index 4cfd270a..ee143089 100644 --- a/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java +++ b/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java @@ -13,7 +13,7 @@ import net.minecraft.world.level.ChunkCoordIntPair; import net.minecraft.world.level.block.state.IBlockData; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack; import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.AfterAll; diff --git a/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTestUtil.java b/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTestUtil.java index 77ce0d78..d90fa9a8 100644 --- a/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTestUtil.java +++ b/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTestUtil.java @@ -3,7 +3,7 @@ package com.comphenix.protocol.utility; public class MinecraftReflectionTestUtil { public static final String RELEASE_TARGET = "1.20.6"; - public static final String PACKAGE_VERSION = "v1_21_R1"; + public static final String PACKAGE_VERSION = "v1_21_R2"; public static final String NMS = "net.minecraft"; public static final String OBC = "org.bukkit.craftbukkit." + PACKAGE_VERSION; diff --git a/src/test/java/com/comphenix/protocol/utility/MinecraftVersionTest.java b/src/test/java/com/comphenix/protocol/utility/MinecraftVersionTest.java index afca8950..c87bc4c5 100644 --- a/src/test/java/com/comphenix/protocol/utility/MinecraftVersionTest.java +++ b/src/test/java/com/comphenix/protocol/utility/MinecraftVersionTest.java @@ -48,7 +48,7 @@ class MinecraftVersionTest { @Test void testCurrent() { - assertEquals(MinecraftVersion.v1_21_0, MinecraftVersion.getCurrentVersion()); + assertEquals(MinecraftVersion.v1_21_2, MinecraftVersion.getCurrentVersion()); } @Test diff --git a/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java b/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java index 32013d34..0882cb26 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java @@ -1,11 +1,12 @@ package com.comphenix.protocol.wrappers; -import static org.junit.jupiter.api.Assertions.assertEquals; - import com.comphenix.protocol.BukkitInitialization; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ChunkCoordIntPairTest { @BeforeAll @@ -25,7 +26,7 @@ public class ChunkCoordIntPairTest { (net.minecraft.world.level.ChunkCoordIntPair) ChunkCoordIntPair.getConverter(). getGeneric(specific); - assertEquals(1, roundtrip.e); - assertEquals(2, roundtrip.f); + assertEquals(1, roundtrip.h); + assertEquals(2, roundtrip.i); } } diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java index e388ea0d..4a532e17 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java @@ -51,7 +51,7 @@ public class WrappedAttributeTest { // Create attribute this.attribute = WrappedAttribute.newBuilder(). - attributeKey("generic.attackDamage"). + attributeKey("attack_damage"). baseValue(2). packet(new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES)). modifiers(Lists.newArrayList(this.constantModifier, this.doubleModifier)). diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedBlockDataTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedBlockDataTest.java index c5da56ca..60e64429 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedBlockDataTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedBlockDataTest.java @@ -19,9 +19,9 @@ import net.minecraft.world.level.block.state.IBlockData; import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.block.data.type.GlassPane; -import org.bukkit.craftbukkit.v1_21_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R1.block.impl.CraftStainedGlassPane; -import org.bukkit.craftbukkit.v1_21_R1.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.v1_21_R2.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_21_R2.block.impl.CraftStainedGlassPane; +import org.bukkit.craftbukkit.v1_21_R2.util.CraftMagicNumbers; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -56,7 +56,7 @@ public class WrappedBlockDataTest { @Test public void testDataCreation() { - IBlockData nmsData = CraftMagicNumbers.getBlock(Material.CYAN_STAINED_GLASS_PANE).o(); + IBlockData nmsData = CraftMagicNumbers.getBlock(Material.CYAN_STAINED_GLASS_PANE).m(); GlassPane data = (GlassPane) CraftBlockData.fromData(nmsData); data.setFace(BlockFace.EAST, true); diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java index 39d2a9b2..cd7c9e29 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java @@ -28,7 +28,7 @@ import com.comphenix.protocol.wrappers.nbt.NbtFactory; import net.minecraft.world.entity.projectile.EntityEgg; import org.bukkit.Material; import org.bukkit.Particle; -import org.bukkit.craftbukkit.v1_21_R1.entity.CraftEgg; +import org.bukkit.craftbukkit.v1_21_R2.entity.CraftEgg; import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.BeforeAll; @@ -46,7 +46,7 @@ public class WrappedDataWatcherTest { public static void prepare() { BukkitInitialization.initializeAll(); - EntityEgg nmsEgg = new EntityEgg(null, 0, 0, 0); + EntityEgg nmsEgg = new EntityEgg(null, 0, 0, 0, net.minecraft.world.item.ItemStack.j); mockEntity = new CraftEgg(null, nmsEgg); } diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedStreamCodecTests.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedStreamCodecTests.java index d5bdca4f..b05e3f15 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedStreamCodecTests.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedStreamCodecTests.java @@ -10,8 +10,8 @@ import net.minecraft.network.protocol.game.PacketPlayOutOpenBook; import net.minecraft.network.protocol.game.PacketPlayOutSetSlot; import net.minecraft.world.EnumHand; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_21_R1.CraftRegistry; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R2.CraftRegistry; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test;