From 84e7b7552657066d0ab7a0a56e12aade57ac94cb Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Thu, 13 Jun 2024 19:53:12 -0500 Subject: [PATCH] wip: mojang mappings --- build.gradle | 6 +- .../com/comphenix/protocol/PacketType.java | 8 +- .../events/SerializedOfflinePlayer.java | 18 +- .../protocol/BukkitInitialization.java | 90 ++++---- .../comphenix/protocol/PacketTypeTest.java | 45 +--- .../protocol/events/PacketContainerTest.java | 205 +++++++++++------- .../injector/EntityUtilitiesTest.java | 23 +- .../channel/ChannelProtocolUtilTest.java | 8 - .../injector/packet/PacketRegistryTests.java | 2 + .../utility/MinecraftReflectionTest.java | 23 +- .../utility/MinecraftReflectionTestUtil.java | 2 +- .../utility/StreamSerializerTest.java | 25 ++- .../protocol/wrappers/AutoWrapperTest.java | 20 +- .../wrappers/BukkitConvertersTest.java | 7 +- .../wrappers/ChunkCoordIntPairTest.java | 10 +- .../protocol/wrappers/EnumWrappersTest.java | 11 +- .../wrappers/WrappedAttributeTest.java | 131 ++++++++--- .../wrappers/WrappedBlockDataTest.java | 7 +- .../wrappers/WrappedComponentStyleTest.java | 6 +- .../wrappers/WrappedDataWatcherTest.java | 4 +- .../wrappers/WrappedLevelChunkDataTest.java | 2 +- .../wrappers/WrappedNumberFormatTest.java | 16 +- .../wrappers/WrappedProfilePublicKeyTest.java | 3 +- .../wrappers/WrappedSaltedSignatureTest.java | 23 +- .../wrappers/WrappedServerPingTest.java | 13 +- .../wrappers/WrappedStreamCodecTests.java | 26 +-- .../wrappers/WrappedTeamParametersTest.java | 29 +-- .../protocol/wrappers/nbt/NbtFactoryTest.java | 16 +- 28 files changed, 428 insertions(+), 351 deletions(-) diff --git a/build.gradle b/build.gradle index 058187d9..80a41941 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ description = 'Provides access to the Minecraft protocol' def isSnapshot = version.endsWith('-SNAPSHOT') repositories { - // mavenLocal() // can speed up build, but may fail in CI + mavenLocal() // can speed up build, but may fail in CI mavenCentral() maven { @@ -35,7 +35,7 @@ repositories { dependencies { implementation 'net.bytebuddy:byte-buddy:1.14.14' compileOnly 'org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT' - compileOnly 'org.spigotmc:spigot:1.21-R0.1-SNAPSHOT' + compileOnly 'org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:remapped-mojang' 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,7 +46,7 @@ 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-R0.1-SNAPSHOT' + testImplementation 'org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:remapped-mojang' testImplementation 'net.kyori:adventure-text-serializer-gson:4.14.0' testImplementation 'net.kyori:adventure-text-serializer-plain:4.14.0' } diff --git a/src/main/java/com/comphenix/protocol/PacketType.java b/src/main/java/com/comphenix/protocol/PacketType.java index 9471674a..b1fe2c3b 100644 --- a/src/main/java/com/comphenix/protocol/PacketType.java +++ b/src/main/java/com/comphenix/protocol/PacketType.java @@ -479,8 +479,12 @@ public class PacketType implements Serializable, Cloneable, Comparable 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() + CloseableResourceManager resourceManager = new MultiPackResourceManager( + PackType.SERVER_DATA, + resourcePackRepository.getAvailablePacks().stream().map(Pack::open).collect(Collectors.toList()) + ); + LayeredRegistryAccess layeredRegistryAccess = RegistryLayer.createRegistryAccess(); + layeredRegistryAccess = WorldLoader.loadAndReplaceLayer(resourceManager, layeredRegistryAccess, RegistryLayer.WORLDGEN, RegistryDataLoader.WORLDGEN_REGISTRIES); + RegistryAccess.Frozen registryCustom = layeredRegistryAccess.compositeAccess().freeze(); - DataPackResources dataPackResources = DataPackResources.a( - resourceManager, - layeredRegistryAccess, - FeatureFlags.d.a() /* REGISTRY.allFlags() */, - CommandDispatcher.ServerType.b /* DEDICATED */, - 0, - MoreExecutors.directExecutor(), - MoreExecutors.directExecutor() + ReloadableServerResources dataPackResources = ReloadableServerResources.loadResources( + resourceManager, + layeredRegistryAccess, + FeatureFlags.REGISTRY.allFlags(), + CommandSelection.DEDICATED, + 0, + MoreExecutors.directExecutor(), + MoreExecutors.directExecutor() ).join(); - dataPackResources.g(); + dataPackResources.updateRegistryTags(); try { - IRegistry.class.getName(); + RegistryAccess.class.getName(); } catch (Throwable ex) { ex.printStackTrace(); } @@ -131,7 +133,7 @@ public class BukkitInitialization { CraftServer mockedServer = mock(CraftServer.class); DedicatedServer mockedGameServer = mock(DedicatedServer.class); - when(mockedGameServer.bc()/*registryAccess*/).thenReturn(registryCustom); + when(mockedGameServer.registryAccess()).thenReturn(registryCustom); when(mockedServer.getLogger()).thenReturn(java.util.logging.Logger.getLogger("Minecraft")); when(mockedServer.getName()).thenReturn("Mock Server"); @@ -144,14 +146,20 @@ public class BukkitInitialization { when(mockedServer.getUnsafe()).thenReturn(CraftMagicNumbers.INSTANCE); when(mockedServer.getLootTable(any())).thenAnswer(invocation -> { NamespacedKey key = invocation.getArgument(0); - return new CraftLootTable(key, dataPackResources.b().b(CraftLootTable.bukkitKeyToMinecraft(key))); - }); - when(mockedServer.getRegistry(any())).thenAnswer(invocation -> { - Class registryType = invocation.getArgument(0); - return CraftRegistry.createRegistry(registryType, registryCustom); + return new CraftLootTable(key, dataPackResources.fullRegistries().getLootTable(CraftLootTable.bukkitKeyToMinecraft(key))); }); - WorldServer nmsWorld = mock(WorldServer.class); + when(mockedServer.getRegistry(any())).thenAnswer(invocation -> { + Class registryType = invocation.getArgument(0); + + try { + return CraftRegistry.createRegistry(registryType, registryCustom); + } catch (Exception ignored) { + return mock(org.bukkit.Registry.class); + } + }); + + ServerLevel nmsWorld = mock(ServerLevel.class); SpigotWorldConfig mockWorldConfig = mock(SpigotWorldConfig.class); try { @@ -172,10 +180,8 @@ public class BukkitInitialization { CraftRegistry.setMinecraftRegistry(registryCustom); // Init Enchantments - Enchantments.A.getClass(); + Enchantments.AQUA_AFFINITY.getClass(); // Enchantment.stopAcceptingRegistrations(); - - initialized = true; } } diff --git a/src/test/java/com/comphenix/protocol/PacketTypeTest.java b/src/test/java/com/comphenix/protocol/PacketTypeTest.java index dd735dfc..0d207fa1 100644 --- a/src/test/java/com/comphenix/protocol/PacketTypeTest.java +++ b/src/test/java/com/comphenix/protocol/PacketTypeTest.java @@ -14,29 +14,22 @@ */ package com.comphenix.protocol; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import com.comphenix.protocol.PacketType.Play.Server; -import com.comphenix.protocol.PacketType.Protocol; -import com.comphenix.protocol.PacketType.Sender; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.injector.packet.PacketRegistry; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.wrappers.WrappedChatComponent; -import net.minecraft.network.protocol.login.PacketLoginInStart; +import net.minecraft.network.protocol.login.ServerboundHelloPacket; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * @author dmulloy2 @@ -260,7 +253,7 @@ public class PacketTypeTest { @Test public void testLoginStart() { // This packet is critical for handleLoin - assertEquals(PacketLoginInStart.class, PacketType.Login.Client.START.getPacketClass()); + assertEquals(ServerboundHelloPacket.class, PacketType.Login.Client.START.getPacketClass()); } @Test @@ -287,24 +280,6 @@ public class PacketTypeTest { } } - @Test - @Disabled // TODO -- lots of constructor parameters :( - public void testCreateMapChunk() { - new PacketContainer(PacketType.Play.Server.MAP_CHUNK); - } - - @Test - @Disabled // TODO -- ScoreboardObjective parameter in constructor is causing this to fail - public void testCreateScoreboardObjective() { - new PacketContainer(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); - } - - @Test - @Disabled // TODO -- Entity parameter in constructor is causing this to fail - public void testCreateEntitySound() { - new PacketContainer(PacketType.Play.Server.ENTITY_SOUND); - } - @Test public void testPacketCreation() { List failed = new ArrayList<>(); @@ -313,12 +288,6 @@ public class PacketTypeTest { continue; } - if (type == PacketType.Play.Server.ENTITY_SOUND - || type == PacketType.Play.Server.SCOREBOARD_OBJECTIVE - || type == PacketType.Play.Server.MAP_CHUNK) { - continue; - } - try { new PacketContainer(type); } catch (Exception ex) { diff --git a/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java b/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java index 96a31daf..d7c0d26a 100644 --- a/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java +++ b/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.EnumSet; +import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -38,7 +39,7 @@ import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.accessors.Accessors; import com.comphenix.protocol.reflect.accessors.FieldAccessor; import com.comphenix.protocol.reflect.cloning.SerializableCloner; -import com.comphenix.protocol.utility.MinecraftMethods; +import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.wrappers.BlockPosition; import com.comphenix.protocol.wrappers.BukkitConverters; @@ -53,11 +54,12 @@ import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory; import com.comphenix.protocol.wrappers.MovingObjectPositionBlock; import com.comphenix.protocol.wrappers.Pair; import com.comphenix.protocol.wrappers.PlayerInfoData; +import com.comphenix.protocol.wrappers.WrappedAttribute; +import com.comphenix.protocol.wrappers.WrappedAttributeModifier; import com.comphenix.protocol.wrappers.WrappedBlockData; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedDataValue; import com.comphenix.protocol.wrappers.WrappedDataWatcher; -import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; import com.comphenix.protocol.wrappers.WrappedEnumEntityUseAction; import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedMessageSignature; @@ -72,18 +74,21 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.hover.content.Text; -import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; +import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange; -import net.minecraft.network.protocol.game.PacketPlayOutUpdateAttributes; -import net.minecraft.network.protocol.game.PacketPlayOutUpdateAttributes.AttributeSnapshot; -import net.minecraft.resources.MinecraftKey; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.game.ClientboundGameEventPacket; +import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket; +import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket.AttributeSnapshot; +import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.effect.MobEffectList; +import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.ai.attributes.AttributeBase; +import net.minecraft.world.entity.ai.attributes.AttributeInstance; import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation; +import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.CatVariant; import net.minecraft.world.entity.animal.FrogVariant; import org.apache.commons.lang.SerializationUtils; @@ -201,7 +206,7 @@ public class PacketContainerTest { } @Test - @Disabled // TODO + @Disabled // TODO ??? public void testGetStringArrays() { PacketContainer packet = new PacketContainer(PacketType.Play.Client.UPDATE_SIGN); this.testObjectArray(packet.getStringArrays(), 0, @@ -337,7 +342,7 @@ public class PacketContainerTest { } @Test - // @Disabled // TODO -- handle type is null + // // @Disabled // TODO -- handle type is null public void testGetDataValueCollectionModifier() { PacketContainer entityMetadata = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); StructureModifier> watchableAccessor = entityMetadata.getDataValueCollectionModifier(); @@ -345,8 +350,8 @@ public class PacketContainerTest { assertEquals(0, watchableAccessor.read(0).size()); List values = Lists.newArrayList( - new WrappedDataValue(0, Registry.get(Byte.class), (byte) 21), - new WrappedDataValue(1, Registry.get(String.class), "World")); + new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 21), + new WrappedDataValue(1, WrappedDataWatcher.Registry.get(String.class), "World")); // Insert and read back watchableAccessor.write(0, values); @@ -374,9 +379,9 @@ public class PacketContainerTest { } @Test - @Disabled // TODO + // @Disabled // TODO public void testSerialization() { - PacketContainer useItem = new PacketContainer(PacketType.Play.Client.USE_ITEM); + PacketContainer useItem = new PacketContainer(PacketType.Play.Client.USE_ITEM_ON); useItem.getMovingBlockPositions().write(0, new MovingObjectPositionBlock( new BlockPosition(0, 1, 0), new Vector(0, 1, 0), @@ -388,7 +393,7 @@ public class PacketContainerTest { PacketContainer copy = (PacketContainer) SerializationUtils.clone(useItem); - assertEquals(PacketType.Play.Client.USE_ITEM, copy.getType()); + assertEquals(PacketType.Play.Client.USE_ITEM_ON, copy.getType()); assertEquals(Hand.MAIN_HAND, copy.getHands().read(0)); assertEquals(5, copy.getIntegers().read(0)); @@ -504,45 +509,66 @@ public class PacketContainerTest { } @Test - @Disabled // TODO -- cloning fails - public void testAttributeList() { - PacketContainer attribute = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES); - attribute.getIntegers().write(0, 123); // Entity ID + public void testAttributeCloning() { + PacketContainer container = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES); - // Initialize some test data - List modifiers = Lists.newArrayList( - new AttributeModifier(MinecraftKey.a("protocollib:test"),10, - AttributeModifier.Operation.a)); + WrappedAttribute attribute = WrappedAttribute.newBuilder() + .attributeKey("generic.max_health") + .baseValue(20.0D) + .modifiers(Lists.newArrayList( + WrappedAttributeModifier.newBuilder() + .name("Test") + .amount(1.0D) + .operation(WrappedAttributeModifier.Operation.ADD_NUMBER) + .build() + )) + .build(); - // Obtain an AttributeSnapshot instance. This is complicated by the fact that AttributeSnapshots - // are inner classes (which is ultimately pointless because AttributeSnapshots don't access any - // members of the packet itself) - PacketPlayOutUpdateAttributes packet = (PacketPlayOutUpdateAttributes) attribute.getHandle(); - IRegistry registry = BuiltInRegistries.s; - AttributeBase base = registry.a(MinecraftKey.a("generic.max_health")); - AttributeSnapshot snapshot = new AttributeSnapshot(Holder.a(base), 20.0D, modifiers); - attribute.getSpecificModifier(List.class).write(0, Lists.newArrayList(snapshot)); + container.getAttributeCollectionModifier().write(0, List.of(attribute)); - PacketContainer cloned = attribute.deepClone(); - AttributeSnapshot - clonedSnapshot = (AttributeSnapshot) cloned.getSpecificModifier(List.class).read(0).get(0); + ClientboundUpdateAttributesPacket packet = (ClientboundUpdateAttributesPacket) container.getHandle(); - // Compare the fields, because apparently the packet is a field in AttributeSnapshot - for (Field field : AttributeSnapshot.class.getDeclaredFields()) { - try { - // Skip the packet - if (field.getType().equals(packet.getClass())) { - continue; - } + PacketContainer cloned = container.deepClone(); + ClientboundUpdateAttributesPacket clonedPacket = (ClientboundUpdateAttributesPacket) cloned.getHandle(); - field.setAccessible(true); - this.testEquality(field.get(snapshot), field.get(clonedSnapshot)); - } catch (AssertionError e) { - throw e; - } catch (Throwable ex) { - ex.printStackTrace(); - } - } + assertNotSame(packet, clonedPacket); + assertNotSame(packet.getValues(), clonedPacket.getValues()); + + List values = packet.getValues(); + List clonedValues = clonedPacket.getValues(); + + assertEquals(values.size(), clonedValues.size()); + assertNotSame(values.get(0), clonedValues.get(0)); + + AttributeSnapshot snapshot = values.get(0); + AttributeSnapshot clonedSnapshot = clonedValues.get(0); + + assertEquals(Attributes.MAX_HEALTH, clonedSnapshot.attribute()); + assertEquals(20.0D, clonedSnapshot.base()); + + assertNotSame(snapshot.modifiers(), clonedSnapshot.modifiers()); + } + + @Test + public void testReadAttributeList() { + AttributeInstance instance = new AttributeInstance(Attributes.MAX_HEALTH, (__) -> {}); + instance.setBaseValue(20.0D); + instance.addTransientModifier(new AttributeModifier(ResourceLocation.parse("protocollib:test"), 1.0, + Operation.ADD_VALUE)); + + ClientboundUpdateAttributesPacket packet = new ClientboundUpdateAttributesPacket(1234, List.of(instance)); + PacketContainer container = PacketContainer.fromPacket(packet); + + List attributes = container.getAttributeCollectionModifier().read(0); + WrappedAttribute attribute = attributes.get(0); + + assertEquals("generic.max_health", attribute.getAttributeKey()); + assertEquals(20.0D, attribute.getBaseValue()); + + WrappedAttributeModifier modifier = attribute.getModifiers().iterator().next(); + assertEquals(1.0D, modifier.getAmount()); + assertEquals("protocollib:test", modifier.getKey().getFullKey()); + assertEquals(WrappedAttributeModifier.Operation.ADD_NUMBER, modifier.getOperation()); } @Test @@ -569,28 +595,30 @@ public class PacketContainerTest { @SuppressWarnings("deprecation") public void testPotionEffect() { PotionEffect effect = new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20 * 60, 1); - MobEffect mobEffect = new MobEffect(MobEffects.l, effect.getDuration(), + MobEffectInstance mobEffect = new MobEffectInstance(MobEffects.FIRE_RESISTANCE, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()); int entityId = 42; + ClientboundUpdateMobEffectPacket packet; + // The constructor we want to call PacketConstructor creator = PacketConstructor.DEFAULT.withPacket( - PacketType.Play.Server.ENTITY_EFFECT, new Class[] { int.class, MobEffect.class, boolean.class }); - PacketContainer packet = creator.createPacket(entityId, mobEffect, true); + PacketType.Play.Server.ENTITY_EFFECT, new Class[] { int.class, MobEffectInstance.class, boolean.class }); + PacketContainer container = creator.createPacket(entityId, mobEffect, true); - assertEquals(entityId, packet.getIntegers().read(0)); - assertEquals(effect.getAmplifier(), packet.getIntegers().read(1)); - assertEquals(effect.getDuration(), packet.getIntegers().read(2)); + assertEquals(entityId, container.getIntegers().read(0)); + assertEquals(effect.getAmplifier(), container.getIntegers().read(1)); + assertEquals(effect.getDuration(), container.getIntegers().read(2)); WrappedRegistry registry = WrappedRegistry.getRegistry(MinecraftReflection.getMobEffectListClass()); - Object effectList = assertInstanceOf( - MobEffectList.class, - packet.getHolders(MobEffectList.class, InternalStructure.CONVERTER).read(0).getHandle() + MobEffect effectList = assertInstanceOf( + MobEffect.class, + container.getHolders(MobEffect.class, InternalStructure.CONVERTER).read(0).getHandle() ); - assertEquals(effect.getType().getId(), registry.getId(effectList) + 1); // +1 is correct, see CraftPotionEffectType + assertTrue(effectList.getDescriptionId().contains("fire_resistance")); byte b = 0; if (effect.isAmbient()) { @@ -605,7 +633,7 @@ public class PacketContainerTest { b |= 8; - assertEquals(b, (byte) packet.getBytes().read(0)); + assertEquals(b, (byte) container.getBytes().read(0)); } @Test @@ -659,6 +687,8 @@ public class PacketContainerTest { @Disabled // TODO -- need a way to create a structure public void testInternalStructures() { PacketContainer container = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM); + container.getModifier().writeDefaults(); + Optional optStruct = container.getOptionalStructures().read(0); assertTrue(optStruct.isPresent()); InternalStructure struct = optStruct.get(); @@ -698,7 +728,7 @@ public class PacketContainerTest { @Test public void testMovingBlockPos() { - PacketContainer container = new PacketContainer(PacketType.Play.Client.USE_ITEM); + PacketContainer container = new PacketContainer(PacketType.Play.Client.USE_ITEM_ON); Vector vector = new Vector(0, 1, 2); BlockPosition position = new BlockPosition(3, 4, 5); @@ -801,7 +831,7 @@ public class PacketContainerTest { } @Test - @Disabled // TODO -- can't create MAP_CHUNK packet + // @Disabled // TODO -- can't create MAP_CHUNK packet public void testMapChunk() { // this is a special case as we are generating a data serializer class (we only need to construct the packet) PacketContainer container = new PacketContainer(PacketType.Play.Server.MAP_CHUNK); @@ -889,17 +919,25 @@ public class PacketContainerTest { } Object buffer = MinecraftReflection.createPacketDataSerializer(0); - MinecraftMethods.getPacketWriteByteBufMethod().invoke(cloned.getHandle(), buffer); + + FuzzyReflection fuzzy = FuzzyReflection.fromClass(constructed.getType().getPacketClass(), false); + FieldAccessor accessor = Accessors.getFieldAccessor(fuzzy.getField(FuzzyFieldContract.newBuilder() + .requireModifier(Modifier.STATIC) + .requireModifier(Modifier.PUBLIC) + .typeDerivedOf(StreamCodec.class) + .build())); + StreamCodec codec = (StreamCodec) accessor.get(cloned.getHandle()); + codec.encode(buffer, cloned.getHandle()); } + private static final Set CLONE_EXPECTED_FAILURES = Set.of(); + @Test @Disabled // TODO -- cloning is borked public void testCloning() { - // Try constructing all the packets + Set failures = new HashSet<>(); for (PacketType type : PacketType.values()) { - // TODO: try to support chat - for now chat contains to many sub classes to properly clone it - if (type.isDeprecated() || !type.isSupported() || type.name().contains("CUSTOM_PAYLOAD") || type.name().contains("CHAT") - || type.name().contains("BUNDLE")) { + if (type.isDeprecated() || !type.isSupported()) { continue; } @@ -911,22 +949,22 @@ public class PacketContainerTest { // Make sure watchable collections can be cloned if (type == PacketType.Play.Server.ENTITY_METADATA) { - IRegistry catVariantRegistry = BuiltInRegistries.ai; + Registry catVariantRegistry = BuiltInRegistries.CAT_VARIANT; constructed.getDataValueCollectionModifier().write(0, Lists.newArrayList( - new WrappedDataValue(0, Registry.get(Byte.class), (byte) 1), - new WrappedDataValue(0, Registry.get(Float.class), 5F), - new WrappedDataValue(0, Registry.get(String.class), "String"), - new WrappedDataValue(0, Registry.get(Boolean.class), true), + new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 1), + new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Float.class), 5F), + new WrappedDataValue(0, WrappedDataWatcher.Registry.get(String.class), "String"), + new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Boolean.class), true), new WrappedDataValue( - 0, - Registry.getChatComponentSerializer(true), + 0, + WrappedDataWatcher.Registry.getChatComponentSerializer(true), Optional.of(ComponentConverter.fromBaseComponent(TEST_COMPONENT).getHandle())), new WrappedDataValue( 0, - Registry.getItemStackSerializer(false), + WrappedDataWatcher.Registry.getItemStackSerializer(false), BukkitConverters.getItemStackConverter().getGeneric(new ItemStack(Material.WOODEN_AXE))), - new WrappedDataValue(0, Registry.get(CatVariant.class), catVariantRegistry.e(CatVariant.e)), - new WrappedDataValue(0, Registry.get(FrogVariant.class), FrogVariant.a) + new WrappedDataValue(0, WrappedDataWatcher.Registry.get(CatVariant.class), catVariantRegistry.get(CatVariant.ALL_BLACK)), + new WrappedDataValue(0, WrappedDataWatcher.Registry.get(FrogVariant.class), FrogVariant.COLD) )); } else if (type == PacketType.Play.Server.CHAT || type == PacketType.Login.Server.DISCONNECT) { constructed.getChatComponents().write(0, ComponentConverter.fromBaseComponent(TEST_COMPONENT)); @@ -935,7 +973,7 @@ public class PacketContainerTest { } else if (type == PacketType.Play.Server.GAME_STATE_CHANGE) { constructed.getStructures().write( 0, - InternalStructure.getConverter().getSpecific(PacketPlayOutGameStateChange.a)); + InternalStructure.getConverter().getSpecific(ClientboundGameEventPacket.ARROW_HIT_PLAYER)); } else if (type == PacketType.Play.Client.USE_ITEM || type == PacketType.Play.Client.BLOCK_PLACE) { constructed.getLongs().write(0, 0L); // timestamp of the packet, not sent over the network } @@ -955,10 +993,13 @@ public class PacketContainerTest { serializedCloned.getLongs().write(0, 0L); } this.assertPacketsEqualAndSerializable(constructed, serializedCloned); - } catch (Throwable t) { - Assertions.fail("Unable to clone " + type, t); + } catch (Throwable ex) { + failures.add(type); + ex.printStackTrace(); } } + + assertEquals(CLONE_EXPECTED_FAILURES, failures); } // Convert to objects that support equals() diff --git a/src/test/java/com/comphenix/protocol/injector/EntityUtilitiesTest.java b/src/test/java/com/comphenix/protocol/injector/EntityUtilitiesTest.java index c759e1c1..a74baf26 100644 --- a/src/test/java/com/comphenix/protocol/injector/EntityUtilitiesTest.java +++ b/src/test/java/com/comphenix/protocol/injector/EntityUtilitiesTest.java @@ -1,25 +1,8 @@ package com.comphenix.protocol.injector; -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.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import static com.comphenix.protocol.utility.TestUtils.setFinalField; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import org.junit.jupiter.api.BeforeAll; public class EntityUtilitiesTest { @@ -28,10 +11,11 @@ public class EntityUtilitiesTest { BukkitInitialization.initializeAll(); } + /* @Test public void testReflection() { CraftWorld bukkit = mock(CraftWorld.class); - WorldServer world = mock(WorldServer.class); + ServerLevel world = mock(ServerLevel.class); when(bukkit.getHandle()).thenReturn(world); ChunkProviderServer provider = mock(ChunkProviderServer.class); @@ -57,4 +41,5 @@ public class EntityUtilitiesTest { .getField(FuzzyFieldContract.newBuilder().typeExact(Int2ObjectMap.class).build()); setFinalField(chunkMap, trackedEntitiesField, trackerMap); } + */ } diff --git a/src/test/java/com/comphenix/protocol/injector/netty/channel/ChannelProtocolUtilTest.java b/src/test/java/com/comphenix/protocol/injector/netty/channel/ChannelProtocolUtilTest.java index f1ddadf1..6da88b6a 100644 --- a/src/test/java/com/comphenix/protocol/injector/netty/channel/ChannelProtocolUtilTest.java +++ b/src/test/java/com/comphenix/protocol/injector/netty/channel/ChannelProtocolUtilTest.java @@ -1,15 +1,7 @@ package com.comphenix.protocol.injector.netty.channel; import com.comphenix.protocol.BukkitInitialization; -import com.comphenix.protocol.PacketType; -import io.netty.channel.Channel; -import io.netty.channel.local.LocalServerChannel; -import net.minecraft.network.EnumProtocol; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.protocol.EnumProtocolDirection; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; public class ChannelProtocolUtilTest { diff --git a/src/test/java/com/comphenix/protocol/injector/packet/PacketRegistryTests.java b/src/test/java/com/comphenix/protocol/injector/packet/PacketRegistryTests.java index 74c45b1e..ea55a350 100644 --- a/src/test/java/com/comphenix/protocol/injector/packet/PacketRegistryTests.java +++ b/src/test/java/com/comphenix/protocol/injector/packet/PacketRegistryTests.java @@ -6,6 +6,8 @@ import java.util.List; import com.comphenix.protocol.BukkitInitialization; import com.comphenix.protocol.PacketType; +import net.minecraft.network.protocol.game.ServerboundUseItemPacket; +import net.minecraft.network.protocol.login.LoginPacketTypes; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java b/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java index 4cfd270a..9c85d736 100644 --- a/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java +++ b/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java @@ -1,16 +1,8 @@ package com.comphenix.protocol.utility; import com.comphenix.protocol.BukkitInitialization; + import com.mojang.authlib.GameProfile; -import net.minecraft.nbt.NBTCompressedStreamTools; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.network.protocol.game.PacketPlayOutUpdateAttributes; -import net.minecraft.network.protocol.status.ServerPing; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.util.MinecraftEncryption; -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; @@ -21,13 +13,9 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import static com.comphenix.protocol.utility.TestUtils.assertItemsEqual; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; public class MinecraftReflectionTest { @@ -64,6 +52,7 @@ public class MinecraftReflectionTest { assertNull(MinecraftReflection.getNullableNMS("ProtocolLib")); } + /* @Test public void testAttributeSnapshot() { assertEquals(PacketPlayOutUpdateAttributes.AttributeSnapshot.class, @@ -124,7 +113,7 @@ public class MinecraftReflectionTest { public void testLoginSignature() { assertEquals(MinecraftEncryption.b.class, MinecraftReflection.getSaltedSignatureClass()); } - +*/ @Test public void testItemStacks() { ItemStack stack = new ItemStack(Material.GOLDEN_SWORD); diff --git a/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTestUtil.java b/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTestUtil.java index 77ce0d78..7fca9746 100644 --- a/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTestUtil.java +++ b/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTestUtil.java @@ -2,7 +2,7 @@ package com.comphenix.protocol.utility; public class MinecraftReflectionTestUtil { - public static final String RELEASE_TARGET = "1.20.6"; + public static final String RELEASE_TARGET = "1.21.0"; public static final String PACKAGE_VERSION = "v1_21_R1"; 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/StreamSerializerTest.java b/src/test/java/com/comphenix/protocol/utility/StreamSerializerTest.java index 1d73f7c2..b77d0268 100644 --- a/src/test/java/com/comphenix/protocol/utility/StreamSerializerTest.java +++ b/src/test/java/com/comphenix/protocol/utility/StreamSerializerTest.java @@ -1,16 +1,15 @@ package com.comphenix.protocol.utility; -import static com.comphenix.protocol.utility.TestUtils.assertItemsEqual; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.comphenix.protocol.BukkitInitialization; -import com.comphenix.protocol.wrappers.nbt.NbtCompound; -import com.comphenix.protocol.wrappers.nbt.NbtFactory; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; + +import com.comphenix.protocol.BukkitInitialization; +import com.comphenix.protocol.wrappers.nbt.NbtCompound; +import com.comphenix.protocol.wrappers.nbt.NbtFactory; + import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -19,6 +18,11 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static com.comphenix.protocol.utility.TestUtils.assertItemsEqual; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class StreamSerializerTest { @BeforeAll @@ -35,7 +39,10 @@ public class StreamSerializerTest { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); serializer.serializeString(new DataOutputStream(buffer), initial); - DataInputStream input = new DataInputStream(new ByteArrayInputStream(buffer.toByteArray())); + byte[] bytes = buffer.toByteArray(); + assertTrue(bytes.length >= initial.length()); + + DataInputStream input = new DataInputStream(new ByteArrayInputStream(bytes)); String deserialized = serializer.deserializeString(input, 50); assertEquals(initial, deserialized); @@ -60,7 +67,7 @@ public class StreamSerializerTest { } @Test - @Disabled // TODO -- replaced with registry friendly bytebuf + @Disabled // TODO -- replaced with stream codecs public void testItems() throws IOException { StreamSerializer serializer = new StreamSerializer(); ItemStack initial = new ItemStack(Material.STRING); @@ -72,7 +79,7 @@ public class StreamSerializerTest { } @Test - @Disabled // TODO -- replaced with registry friendly bytebuf + @Disabled // TODO -- replaced with stream codecs public void testItemMeta() throws IOException { StreamSerializer serializer = new StreamSerializer(); ItemStack initial = new ItemStack(Material.BLUE_WOOL, 2); diff --git a/src/test/java/com/comphenix/protocol/wrappers/AutoWrapperTest.java b/src/test/java/com/comphenix/protocol/wrappers/AutoWrapperTest.java index 63819951..c146f574 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/AutoWrapperTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/AutoWrapperTest.java @@ -2,24 +2,24 @@ package com.comphenix.protocol.wrappers; import java.util.Optional; +import static com.comphenix.protocol.utility.MinecraftReflection.getMinecraftClass; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; + import com.comphenix.protocol.BukkitInitialization; import com.comphenix.protocol.utility.MinecraftReflection; -import net.minecraft.advancements.AdvancementDisplay; -import net.minecraft.advancements.AdvancementFrameType; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.network.chat.contents.LiteralContents; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static com.comphenix.protocol.utility.MinecraftReflection.getMinecraftClass; - -import static org.junit.jupiter.api.Assertions.*; - public class AutoWrapperTest { + /* @BeforeAll public static void initializeBukkit() { BukkitInitialization.initializeAll(); @@ -60,7 +60,7 @@ public class AutoWrapperTest { (net.minecraft.world.item.ItemStack)MinecraftReflection.getMinecraftItemStack(new ItemStack(Material.ENDER_EYE)), IChatBaseComponent.b("Test123"), IChatBaseComponent.b("Test567"), - Optional.of(net.minecraft.resources.MinecraftKey.a("minecraft", "test")), + Optional.of(new net.minecraft.resources.MinecraftKey("minecraft", "test")), AdvancementFrameType.b, true, false, @@ -117,5 +117,5 @@ public class AutoWrapperTest { public boolean hidden; public float x; public float y; - } + }*/ } diff --git a/src/test/java/com/comphenix/protocol/wrappers/BukkitConvertersTest.java b/src/test/java/com/comphenix/protocol/wrappers/BukkitConvertersTest.java index 46fd4a80..c2586f69 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/BukkitConvertersTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/BukkitConvertersTest.java @@ -1,11 +1,14 @@ package com.comphenix.protocol.wrappers; +import java.util.Random; + import com.comphenix.protocol.BukkitInitialization; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.EquivalentConverter; import com.comphenix.protocol.utility.TestUtils; import com.comphenix.protocol.wrappers.Either.Left; + import org.apache.commons.lang.builder.EqualsBuilder; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -17,8 +20,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import java.util.Random; - import static org.junit.jupiter.api.Assertions.*; public class BukkitConvertersTest { @@ -29,7 +30,7 @@ public class BukkitConvertersTest { } @Test - @Disabled // TODO -- enchantment cannot be applied to this itemstack(???) + // @Disabled // TODO -- enchantment cannot be applied to this itemstack(???) public void testItemStacks() { ItemStack item = new ItemStack(Material.DIAMOND_SWORD, 16); item.addEnchantment(Enchantment.SHARPNESS, 4); diff --git a/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java b/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java index 32013d34..45a546c3 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java @@ -15,17 +15,17 @@ public class ChunkCoordIntPairTest { @Test public void test() { - net.minecraft.world.level.ChunkCoordIntPair pair = new net.minecraft.world.level.ChunkCoordIntPair(1, 2); + net.minecraft.world.level.ChunkPos pair = new net.minecraft.world.level.ChunkPos(1, 2); ChunkCoordIntPair specific = ChunkCoordIntPair.getConverter().getSpecific(pair); assertEquals(1, specific.getChunkX()); assertEquals(2, specific.getChunkZ()); - net.minecraft.world.level.ChunkCoordIntPair roundtrip = - (net.minecraft.world.level.ChunkCoordIntPair) ChunkCoordIntPair.getConverter(). + net.minecraft.world.level.ChunkPos roundtrip = + (net.minecraft.world.level.ChunkPos) ChunkCoordIntPair.getConverter(). getGeneric(specific); - assertEquals(1, roundtrip.e); - assertEquals(2, roundtrip.f); + assertEquals(1, roundtrip.x); + assertEquals(2, roundtrip.z); } } diff --git a/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java b/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java index 4f733395..7743597b 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java @@ -31,8 +31,8 @@ public class EnumWrappersTest { public void validateAllEnumFieldsAreWrapped() { Map, EquivalentConverter> nativeEnums = EnumWrappers.getFromNativeMap(); for (Entry, EquivalentConverter> entry : nativeEnums.entrySet()) { - for (Object nativeConstant : entry.getKey().getEnumConstants()) { - try { + try { + for (Object nativeConstant : entry.getKey().getEnumConstants()) { // yay, generics EquivalentConverter converter = (EquivalentConverter) entry.getValue(); @@ -44,16 +44,15 @@ public class EnumWrappersTest { assertNotNull(unwrappedValue); assertEquals(nativeConstant, unwrappedValue); - } catch (Exception ex) { - fail(ex); - // ex.printStackTrace(); } + } catch (Exception ex) { + fail(ex); } } } @Test public void testValidity() { - assertEquals(EnumWrappers.INVALID, KNOWN_INVALID); + assertEquals(KNOWN_INVALID, EnumWrappers.INVALID); } } diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java index e388ea0d..a293e88d 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java @@ -2,20 +2,22 @@ package com.comphenix.protocol.wrappers; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import com.comphenix.protocol.BukkitInitialization; -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.reflect.cloning.BukkitCloner; import com.comphenix.protocol.wrappers.WrappedAttributeModifier.Operation; import com.google.common.collect.Lists; import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; +import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.protocol.game.PacketPlayOutUpdateAttributes.AttributeSnapshot; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.world.entity.ai.attributes.AttributeBase; +import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket.AttributeSnapshot; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.entity.ai.attributes.Attributes; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,27 +37,94 @@ public class WrappedAttributeTest { @BeforeEach public void setUp() { - // Create a couple of modifiers - this.doubleModifier = - WrappedAttributeModifier.newBuilder(). - name("Double Damage"). - amount(1). - operation(Operation.ADD_PERCENTAGE). - build(); - this.constantModifier = - WrappedAttributeModifier.newBuilder(). - name("Damage Bonus"). - amount(5). - operation(Operation.ADD_NUMBER). - build(); + this.doubleModifier = WrappedAttributeModifier.newBuilder() + .key("protocollib", "double_damage") + .amount(1.0D) + .operation(Operation.ADD_PERCENTAGE) + .build(); - // Create attribute - this.attribute = WrappedAttribute.newBuilder(). - attributeKey("generic.attackDamage"). - baseValue(2). - packet(new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES)). - modifiers(Lists.newArrayList(this.constantModifier, this.doubleModifier)). - build(); + this.constantModifier = WrappedAttributeModifier.newBuilder() + .key("protocollib", "damage_bonus") + .amount(5.0D) + .operation(Operation.ADD_NUMBER) + .build(); + + this.attribute = WrappedAttribute.newBuilder() + .attributeKey("generic.attackDamage") + .baseValue(2.0D) + .modifiers(Lists.newArrayList(this.constantModifier, this.doubleModifier)) + .build(); + } + + @Test + public void testCreateHandle() { + WrappedAttribute wrapper = WrappedAttribute.newBuilder() + .baseValue(2.0) + .attributeKey("generic.attackDamage") + .modifiers(List.of(constantModifier, doubleModifier)) + .build(); + + AttributeSnapshot handle = (AttributeSnapshot) wrapper.getHandle(); + assertNotNull(handle); + assertEquals(2.0D, handle.base()); + + Attribute attribute = handle.attribute().value(); + assertEquals("attribute.name.generic.attack_damage", attribute.getDescriptionId()); + + Map modifiers = handle.modifiers().stream().collect(Collectors.toMap(m -> m.id(), m -> m)); + AttributeModifier modifier1 = modifiers.get(ResourceLocation.parse("protocollib:double_damage")); + AttributeModifier modifier2 = modifiers.get(ResourceLocation.parse("protocollib:damage_bonus")); + + assertEquals(1.0D, modifier1.amount()); + assertEquals(AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL, modifier1.operation()); + + assertEquals(5.0D, modifier2.amount()); + assertEquals(AttributeModifier.Operation.ADD_VALUE, modifier2.operation()); + } + + @Test + public void testFromHandle() { + AttributeSnapshot handle = new AttributeSnapshot( + Attributes.ATTACK_SPEED, + 5.0D, + List.of(new AttributeModifier(ResourceLocation.parse("protocollib:test"), + 1.0D, AttributeModifier.Operation.ADD_VALUE)) + ); + WrappedAttribute wrapper = WrappedAttribute.fromHandle(handle); + assertEquals("generic.attack_speed", wrapper.getAttributeKey()); + assertEquals(5.0D, wrapper.getBaseValue()); + WrappedAttributeModifier modifier = wrapper.getModifiers().iterator().next(); + assertEquals(1.0D, modifier.getAmount()); + assertEquals("protocollib:test", modifier.getKey().getFullKey()); + assertEquals(Operation.ADD_NUMBER, modifier.getOperation()); + } + + @Test + public void testCloning() { + AttributeModifier modifier = new AttributeModifier( + ResourceLocation.parse("protocollib:test"), + 1.0D, + AttributeModifier.Operation.ADD_VALUE + ); + + AttributeSnapshot handle = new AttributeSnapshot( + Attributes.ATTACK_SPEED, + 5.0D, + List.of(modifier) + ); + + AttributeSnapshot clone = (AttributeSnapshot) new BukkitCloner().clone(handle); + assertNotSame(handle, clone); + + assertEquals(handle.base(), clone.base()); + assertEquals(handle.attribute(), clone.attribute()); + + assertNotSame(handle.modifiers(), clone.modifiers()); + + assertEquals(1, clone.modifiers().size()); + + AttributeModifier cloneModifier = clone.modifiers().iterator().next(); + assertSame(modifier, cloneModifier); } @Test @@ -94,17 +163,17 @@ public class WrappedAttributeTest { modifiers.add((AttributeModifier) wrapper.getHandle()); } - IRegistry registry = BuiltInRegistries.s; + Registry registry = BuiltInRegistries.ATTRIBUTE; String attributeKey = attribute.getAttributeKey(); - MinecraftKey key = MinecraftKey.a(attributeKey); - AttributeBase base = registry.a(key); - Holder holder = registry.e(base); + ResourceLocation key = ResourceLocation.tryParse(attributeKey); + Attribute base = registry.get(key); + Holder holder = registry.wrapAsHolder(base); return new AttributeSnapshot(holder, attribute.getBaseValue(), modifiers); } private AttributeModifier getModifierCopy(WrappedAttributeModifier modifier) { AttributeModifier.Operation operation = AttributeModifier.Operation.values()[modifier.getOperation().getId()]; - return new AttributeModifier((MinecraftKey) com.comphenix.protocol.wrappers.MinecraftKey.getConverter().getGeneric(modifier.getKey()), + return new AttributeModifier(ResourceLocation.parse(modifier.getKey().getFullKey()), modifier.getAmount(), operation); } } diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedBlockDataTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedBlockDataTest.java index c5da56ca..eaae4545 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedBlockDataTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedBlockDataTest.java @@ -15,7 +15,8 @@ package com.comphenix.protocol.wrappers; import com.comphenix.protocol.BukkitInitialization; -import net.minecraft.world.level.block.state.IBlockData; + +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.block.data.type.GlassPane; @@ -56,14 +57,14 @@ public class WrappedBlockDataTest { @Test public void testDataCreation() { - IBlockData nmsData = CraftMagicNumbers.getBlock(Material.CYAN_STAINED_GLASS_PANE).o(); + BlockState nmsData = CraftMagicNumbers.getBlock(Material.CYAN_STAINED_GLASS_PANE).defaultBlockState(); GlassPane data = (GlassPane) CraftBlockData.fromData(nmsData); data.setFace(BlockFace.EAST, true); WrappedBlockData wrapper = WrappedBlockData.createData(data); assertEquals(wrapper.getType(), Material.CYAN_STAINED_GLASS_PANE); - GlassPane back = new CraftStainedGlassPane((IBlockData) wrapper.getHandle()); + GlassPane back = new CraftStainedGlassPane((BlockState) wrapper.getHandle()); assertEquals(back.hasFace(BlockFace.EAST), data.hasFace(BlockFace.EAST)); assertEquals(back.hasFace(BlockFace.SOUTH), data.hasFace(BlockFace.SOUTH)); } diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedComponentStyleTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedComponentStyleTest.java index d0ff9d4b..85e9ab0c 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedComponentStyleTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedComponentStyleTest.java @@ -1,13 +1,13 @@ package com.comphenix.protocol.wrappers; import com.comphenix.protocol.BukkitInitialization; + import com.google.gson.JsonElement; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.format.TextDecoration; -import net.minecraft.EnumChatFormat; -import net.minecraft.network.chat.ChatModifier; +import net.minecraft.ChatFormatting; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -22,7 +22,7 @@ public class WrappedComponentStyleTest { @Test public void testComponentStyle() { - ChatModifier style = ChatModifier.a.b(EnumChatFormat.m).a(true); + Object style = net.minecraft.network.chat.Style.EMPTY.applyFormat(ChatFormatting.RED).withBold(true); WrappedComponentStyle wrapped = new WrappedComponentStyle(style); JsonElement json = wrapped.getJson(); assertEquals("{\"color\":\"red\",\"bold\":true}", json.toString()); diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java index 39d2a9b2..94bf99cd 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java @@ -25,7 +25,7 @@ import com.comphenix.protocol.wrappers.nbt.NbtBase; import com.comphenix.protocol.wrappers.nbt.NbtCompound; import com.comphenix.protocol.wrappers.nbt.NbtFactory; -import net.minecraft.world.entity.projectile.EntityEgg; +import net.minecraft.world.entity.projectile.ThrownEgg; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.craftbukkit.v1_21_R1.entity.CraftEgg; @@ -46,7 +46,7 @@ public class WrappedDataWatcherTest { public static void prepare() { BukkitInitialization.initializeAll(); - EntityEgg nmsEgg = new EntityEgg(null, 0, 0, 0); + ThrownEgg nmsEgg = new ThrownEgg(null, 0, 0, 0); mockEntity = new CraftEgg(null, nmsEgg); } diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedLevelChunkDataTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedLevelChunkDataTest.java index 932015f7..818da1c9 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedLevelChunkDataTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedLevelChunkDataTest.java @@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Etrayed */ -@Disabled // todo: figure this registry update out +// @Disabled // todo: figure this registry update out public class WrappedLevelChunkDataTest { @BeforeAll diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedNumberFormatTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedNumberFormatTest.java index c8b417f8..44d3730a 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedNumberFormatTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedNumberFormatTest.java @@ -1,9 +1,10 @@ package com.comphenix.protocol.wrappers; import com.comphenix.protocol.BukkitInitialization; -import net.minecraft.EnumChatFormat; -import net.minecraft.network.chat.ChatModifier; -import net.minecraft.network.chat.IChatBaseComponent; + +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; import net.minecraft.network.chat.numbers.BlankFormat; import net.minecraft.network.chat.numbers.FixedFormat; import net.minecraft.network.chat.numbers.StyledFormat; @@ -22,13 +23,13 @@ public class WrappedNumberFormatTest { @Test void testBlankFormat() { - assertInstanceOf(WrappedNumberFormat.Blank.class, WrappedNumberFormat.fromHandle(BlankFormat.a)); - assertEquals(BlankFormat.a, WrappedNumberFormat.blank().getHandle()); + assertInstanceOf(WrappedNumberFormat.Blank.class, WrappedNumberFormat.fromHandle(BlankFormat.INSTANCE)); + assertEquals(BlankFormat.INSTANCE, WrappedNumberFormat.blank().getHandle()); } @Test void testFixedFormat() { - IChatBaseComponent content = IChatBaseComponent.a("Fixed"); + Component content = Component.literal("Fixed"); WrappedNumberFormat wrappedHandle = WrappedNumberFormat.fromHandle(new FixedFormat(content)); assertInstanceOf(WrappedNumberFormat.Fixed.class, wrappedHandle); assertEquals(content, ((WrappedNumberFormat.Fixed) wrappedHandle).getContent().getHandle()); @@ -39,7 +40,8 @@ public class WrappedNumberFormatTest { @Test void testStyledFormat() { - ChatModifier style = ChatModifier.a.b(EnumChatFormat.g); + Style style = Style.EMPTY.applyFormat(ChatFormatting.AQUA); + // ChatModifier style = ChatModifier.a.b(EnumChatFormat.g); WrappedNumberFormat wrappedHandle = WrappedNumberFormat.fromHandle(new StyledFormat(style)); assertInstanceOf(WrappedNumberFormat.Styled.class, wrappedHandle); assertEquals(style, ((WrappedNumberFormat.Styled) wrappedHandle).getStyle().getHandle()); diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedProfilePublicKeyTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedProfilePublicKeyTest.java index 1a268c6a..ab07361d 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedProfilePublicKeyTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedProfilePublicKeyTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test; public class WrappedProfilePublicKeyTest { + /* private static KeyPair generateKeyPair() throws Exception { KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); generator.initialize(2048); @@ -79,5 +80,5 @@ public class WrappedProfilePublicKeyTest { assertEquals(keyData.getKey(), wrappedKeyData.getKey()); assertEquals(keyData.getExpireTime(), wrappedKeyData.getExpireTime()); assertArrayEquals(keyData.getSignature(), wrappedKeyData.getSignature()); - } + }*/ } diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedSaltedSignatureTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedSaltedSignatureTest.java index 92fd7bee..f7ccc416 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedSaltedSignatureTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedSaltedSignatureTest.java @@ -4,7 +4,7 @@ import com.comphenix.protocol.BukkitInitialization; import java.util.concurrent.ThreadLocalRandom; -import net.minecraft.util.MinecraftEncryption; +import net.minecraft.util.Crypt; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -28,11 +28,11 @@ class WrappedSaltedSignatureTest { WrappedSaltedSignature loginSignature = new WrappedSaltedSignature(salt, signature); Object handle = loginSignature.getHandle(); - MinecraftEncryption.b data = assertInstanceOf(MinecraftEncryption.b.class, handle); + Crypt.SaltSignaturePair data = assertInstanceOf(Crypt.SaltSignaturePair.class, handle); - assertTrue(data.a()); - assertArrayEquals(signature, data.d()); - assertEquals(salt, data.c()); + assertTrue(data.isValid()); + assertArrayEquals(signature, data.signature()); + assertEquals(salt, data.salt()); // test key data unwrapping WrappedSaltedSignature unwrapped = BukkitConverters.getWrappedSignatureConverter().getSpecific(data); @@ -44,14 +44,15 @@ class WrappedSaltedSignatureTest { // test key data wrapping Object wrappedData = BukkitConverters.getWrappedSignatureConverter().getGeneric(loginSignature); - MinecraftEncryption.b wrapped = assertInstanceOf(MinecraftEncryption.b.class, wrappedData); + Crypt.SaltSignaturePair wrapped = assertInstanceOf(Crypt.SaltSignaturePair.class, wrappedData); - assertTrue(wrapped.a()); - assertEquals(loginSignature.getSalt(), wrapped.c()); - assertArrayEquals(loginSignature.getSignature(), wrapped.d()); - assertArrayEquals(loginSignature.getSaltBytes(), wrapped.b()); + assertTrue(wrapped.isValid()); + assertEquals(loginSignature.getSalt(), wrapped.salt()); + assertArrayEquals(loginSignature.getSignature(), wrapped.signature()); + assertArrayEquals(loginSignature.getSaltBytes(), wrapped.saltAsBytes()); } + /* @Test void testSignedMessageWithoutSignature() { long salt = ThreadLocalRandom.current().nextLong(); @@ -83,5 +84,5 @@ class WrappedSaltedSignatureTest { assertEquals(loginSignature.getSalt(), wrapped.c()); assertArrayEquals(loginSignature.getSignature(), wrapped.d()); assertArrayEquals(loginSignature.getSaltBytes(), wrapped.b()); - } + }*/ } diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedServerPingTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedServerPingTest.java index 1bd94b17..a56070e8 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedServerPingTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedServerPingTest.java @@ -1,17 +1,16 @@ package com.comphenix.protocol.wrappers; import java.io.IOException; -import java.util.Optional; import com.comphenix.protocol.BukkitInitialization; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.utility.MinecraftProtocolVersion; import com.comphenix.protocol.wrappers.WrappedServerPing.CompressedImage; + import com.google.common.io.Resources; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; @@ -25,21 +24,13 @@ public class WrappedServerPingTest { } @Test - @Disabled // TODO MotD is null public void fullTest() throws IOException { PacketContainer packet = new PacketContainer(PacketType.Status.Server.SERVER_INFO); - Optional optionalPing = packet.getServerPings().optionRead(0); - assertTrue(optionalPing.isPresent()); - - WrappedServerPing serverPing = optionalPing.get(); - assertNotNull(serverPing.getMotD()); - assertNotNull(serverPing.getFavicon()); - assertNotNull(serverPing.getPlayers()); - assertNotNull(serverPing.getVersionName()); CompressedImage tux = CompressedImage.fromPng(Resources.getResource("tux.png").openStream()); byte[] original = tux.getDataCopy(); + WrappedServerPing serverPing = new WrappedServerPing(); serverPing.setMotD("Hello, this is a test."); serverPing.setPlayersOnline(5); serverPing.setPlayersMaximum(10); diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedStreamCodecTests.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedStreamCodecTests.java index d5bdca4f..8016d679 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedStreamCodecTests.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedStreamCodecTests.java @@ -3,12 +3,12 @@ package com.comphenix.protocol.wrappers; import com.comphenix.protocol.BukkitInitialization; import io.netty.buffer.Unpooled; -import net.minecraft.network.PacketDataSerializer; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; -import net.minecraft.network.protocol.game.PacketPlayOutOpenBook; -import net.minecraft.network.protocol.game.PacketPlayOutSetSlot; -import net.minecraft.world.EnumHand; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenBookPacket; +import net.minecraft.world.InteractionHand; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_21_R1.CraftRegistry; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; @@ -26,29 +26,29 @@ public class WrappedStreamCodecTests { @Test public void testWithItemStack() { - StreamCodec nmsCodec = PacketPlayOutSetSlot.a; + StreamCodec nmsCodec = ClientboundContainerSetSlotPacket.STREAM_CODEC; WrappedStreamCodec codec = new WrappedStreamCodec(nmsCodec); RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), CraftRegistry.getMinecraftRegistry()); - PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(1, 2, 3, CraftItemStack.asNMSCopy(new ItemStack(Material.GOLDEN_SHOVEL))); + ClientboundContainerSetSlotPacket packet = new ClientboundContainerSetSlotPacket(1, 2, 3, CraftItemStack.asNMSCopy(new ItemStack(Material.GOLDEN_SHOVEL))); codec.encode(buf, packet); - PacketPlayOutSetSlot roundTrip = (PacketPlayOutSetSlot) codec.decode(buf); + ClientboundContainerSetSlotPacket roundTrip = (ClientboundContainerSetSlotPacket) codec.decode(buf); - assertEquals(Material.GOLDEN_SHOVEL, CraftItemStack.asBukkitCopy(roundTrip.f()).getType()); + assertEquals(Material.GOLDEN_SHOVEL, CraftItemStack.asBukkitCopy(roundTrip.getItem()).getType()); } @Test public void testWithStandardSerializer() { - StreamCodec nmsCodec = PacketPlayOutOpenBook.a; + StreamCodec nmsCodec = ClientboundOpenBookPacket.STREAM_CODEC; WrappedStreamCodec codec = new WrappedStreamCodec(nmsCodec); - PacketDataSerializer buf = new PacketDataSerializer(Unpooled.buffer()); - PacketPlayOutOpenBook packet = new PacketPlayOutOpenBook(EnumHand.a); + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); + ClientboundOpenBookPacket packet = new ClientboundOpenBookPacket(InteractionHand.OFF_HAND); codec.encode(buf, packet); - PacketPlayOutOpenBook roundTrip = (PacketPlayOutOpenBook) codec.decode(buf); + ClientboundOpenBookPacket roundTrip = (ClientboundOpenBookPacket) codec.decode(buf); - assertEquals(EnumHand.a, roundTrip.b()); + assertEquals(InteractionHand.OFF_HAND, roundTrip.getHand()); } } diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedTeamParametersTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedTeamParametersTest.java index c8f371fb..4851e429 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedTeamParametersTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedTeamParametersTest.java @@ -1,9 +1,10 @@ package com.comphenix.protocol.wrappers; import com.comphenix.protocol.BukkitInitialization; -import net.minecraft.EnumChatFormat; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.network.protocol.game.PacketPlayOutScoreboardTeam; + +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -17,9 +18,9 @@ public class WrappedTeamParametersTest { @Test void testTeamParameters() { - IChatBaseComponent displayName = IChatBaseComponent.b("display name"); - IChatBaseComponent prefix = IChatBaseComponent.b("prefix"); - IChatBaseComponent suffix = IChatBaseComponent.b("suffix"); + Component displayName = Component.literal("display name"); + Component prefix = Component.literal("prefix"); + Component suffix = Component.literal("suffix"); String nametagVisibility = "always"; String collisionRule = "never"; @@ -41,13 +42,13 @@ public class WrappedTeamParametersTest { assertEquals(EnumWrappers.ChatFormatting.RED, wrapped.getColor()); assertEquals(1, wrapped.getOptions()); - PacketPlayOutScoreboardTeam.b handle = (PacketPlayOutScoreboardTeam.b) wrapped.getHandle(); - assertEquals(handle.a(), displayName); - assertEquals(handle.f(), prefix); - assertEquals(handle.g(), suffix); - assertEquals(handle.d(), nametagVisibility); - assertEquals(handle.e(), collisionRule); - assertEquals(handle.c(), EnumChatFormat.m); - assertEquals(handle.b(), 1); + ClientboundSetPlayerTeamPacket.Parameters handle = (ClientboundSetPlayerTeamPacket.Parameters) wrapped.getHandle(); + assertEquals(handle.getDisplayName(), displayName); + assertEquals(handle.getPlayerPrefix(), prefix); + assertEquals(handle.getPlayerSuffix(), suffix); + assertEquals(handle.getNametagVisibility(), nametagVisibility); + assertEquals(handle.getCollisionRule(), collisionRule); + assertEquals(handle.getColor(), ChatFormatting.RED); + assertEquals(handle.getOptions(), 1); } } diff --git a/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java b/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java index 4c1058ea..38ca4e93 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java @@ -17,23 +17,25 @@ package com.comphenix.protocol.wrappers.nbt; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.comphenix.protocol.BukkitInitialization; -import com.comphenix.protocol.utility.MinecraftReflection; -import com.comphenix.protocol.wrappers.nbt.io.NbtBinarySerializer; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInput; import java.io.DataInputStream; import java.io.DataOutput; import java.io.DataOutputStream; + +import com.comphenix.protocol.BukkitInitialization; +import com.comphenix.protocol.utility.MinecraftReflection; +import com.comphenix.protocol.wrappers.nbt.io.NbtBinarySerializer; + import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class NbtFactoryTest { @BeforeAll @@ -64,9 +66,9 @@ public class NbtFactoryTest { } @Test - @Disabled // TODO + @Disabled // TODO -- item stacks don't have tags anymore public void testItemTag() { - ItemStack test = new ItemStack(Items.L); + ItemStack test = new ItemStack(Items.ACACIA_DOOR); org.bukkit.inventory.ItemStack craftTest = MinecraftReflection.getBukkitItemStack(test); NbtCompound compound = NbtFactory.ofCompound("tag");