From b0662b05c5c76279e51e43b244e7242bbe23b446 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sat, 7 Mar 2015 17:57:47 -0500 Subject: [PATCH] Initial update to 1.8.3 --- ProtocolLib/pom.xml | 4 +-- .../protocol/utility/MinecraftReflection.java | 30 +++++++------------ .../protocol/BukkitInitialization.java | 11 ++++--- .../protocol/events/PacketContainerTest.java | 22 ++++++++++---- .../utility/MinecraftReflectionTest.java | 14 ++++----- .../utility/StreamSerializerTest.java | 4 +-- .../wrappers/ChunkCoordIntPairTest.java | 8 ++--- .../protocol/wrappers/EnumWrappersTest.java | 12 ++++---- .../wrappers/WrappedAttributeTest.java | 23 +++++++++----- .../wrappers/WrappedWatchableObjectTest.java | 2 +- .../protocol/wrappers/nbt/NbtFactoryTest.java | 2 +- 11 files changed, 69 insertions(+), 63 deletions(-) diff --git a/ProtocolLib/pom.xml b/ProtocolLib/pom.xml index 89b83100..65af8f85 100644 --- a/ProtocolLib/pom.xml +++ b/ProtocolLib/pom.xml @@ -240,13 +240,13 @@ org.spigotmc spigot-api - 1.8-R0.1-SNAPSHOT + 1.8.3-R0.1-SNAPSHOT provided org.spigotmc spigot - 1.8-R0.1-SNAPSHOT + 1.8.3-R0.1-SNAPSHOT provided diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java index 06158db5..30961354 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java @@ -781,28 +781,18 @@ public class MinecraftReflection { */ public static Class getChatSerializerClass() { try { - return getMinecraftClass("ChatSerializer"); + return getMinecraftClass("IChatBaseComponent.ChatSerializer"); } catch (RuntimeException e) { - // Analyse the ASM + // ChatSerializer was moved into IChatBaseComponent in 1.8.3, + // but it was independent in 1.7-1.8 try { - List methodCalls = ClassAnalyser.getDefault().getMethodCalls( - PacketType.Play.Server.CHAT.getPacketClass(), - MinecraftMethods.getPacketReadByteBufMethod() - ); - Class packetSerializer = getPacketDataSerializerClass(); - - for (AsmMethod method : methodCalls) { - Class owner = method.getOwnerClass(); - - if (isMinecraftClass(owner) && !owner.equals(packetSerializer)) { - return setMinecraftClass("ChatSerializer", owner); - } - } - } catch (Exception e1) { - throw new IllegalStateException("Cannot find ChatSerializer class.", e); + return getMinecraftClass("ChatSerializer"); + } catch (RuntimeException e1) { + // TODO: Figure out a good fallback } + + throw new IllegalStateException("Could not find ChatSerializer class.", e); } - throw new IllegalStateException("Cannot find ChatSerializer class."); } /** @@ -840,7 +830,7 @@ public class MinecraftReflection { throw new IllegalStateException("ServerPingServerData is only supported in 1.7.2."); try { - return getMinecraftClass("ServerPingServerData"); + return getMinecraftClass("ServerPing.ServerData"); } catch (RuntimeException e) { Class serverPing = getServerPingClass(); @@ -863,7 +853,7 @@ public class MinecraftReflection { throw new IllegalStateException("ServerPingPlayerSample is only supported in 1.7.2."); try { - return getMinecraftClass("ServerPingPlayerSample"); + return getMinecraftClass("ServerPing.ServerPingPlayerSample"); } catch (RuntimeException e) { Class serverPing = getServerPingClass(); diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java b/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java index d8eb58d5..d2ee34f7 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java @@ -3,21 +3,20 @@ package com.comphenix.protocol; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import net.minecraft.server.v1_8_R1.Block; -import net.minecraft.server.v1_8_R1.Item; -import net.minecraft.server.v1_8_R1.StatisticList; +import net.minecraft.server.v1_8_R2.Block; +import net.minecraft.server.v1_8_R2.Item; +import net.minecraft.server.v1_8_R2.StatisticList; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Server; -import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemFactory; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemFactory; import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.meta.ItemMeta; import com.comphenix.protocol.reflect.FieldUtils; import com.comphenix.protocol.utility.Constants; import com.comphenix.protocol.utility.MinecraftReflection; -// Will have to be updated for every version though /** * Used to ensure that ProtocolLib and Bukkit is prepared to be tested. @@ -39,7 +38,7 @@ public class BukkitInitialization { initializePackage(); try { - Block.R(); // Block.register(); + Block.S(); // Block.register(); Item.t(); // Item.register(); StatisticList.a(); // StatisticList.register(); } catch (Throwable ex) { diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java index c2478971..b52fd39b 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java @@ -21,12 +21,13 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import java.util.Collection; import java.util.List; import java.util.UUID; -import net.minecraft.server.v1_8_R1.AttributeModifier; -import net.minecraft.server.v1_8_R1.AttributeSnapshot; -import net.minecraft.server.v1_8_R1.PacketPlayOutUpdateAttributes; +import net.minecraft.server.v1_8_R2.AttributeModifier; +import net.minecraft.server.v1_8_R2.PacketPlayOutUpdateAttributes; +import net.minecraft.server.v1_8_R2.PacketPlayOutUpdateAttributes.AttributeSnapshot; import org.apache.commons.lang.SerializationUtils; import org.apache.commons.lang.builder.ToStringBuilder; @@ -34,7 +35,7 @@ import org.apache.commons.lang.builder.ToStringStyle; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.WorldType; -import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemFactory; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemFactory; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.junit.BeforeClass; @@ -366,8 +367,17 @@ public class PacketContainerTest { // Initialize some test data List modifiers = Lists.newArrayList( new AttributeModifier(UUID.randomUUID(), "Unknown synced attribute modifier", 10, 0)); - AttributeSnapshot snapshot = new AttributeSnapshot( - (PacketPlayOutUpdateAttributes) attribute.getHandle(), "generic.Maxhealth", 20.0, modifiers); + + // TODO This is hopefully just a temporary solution, + // but situations like this might be issues elsewhere + class PacketAccessor extends PacketPlayOutUpdateAttributes { + + public AttributeSnapshot attributeSnapshot(String string, double d, Collection coll) { + return new AttributeSnapshot(string, d, coll); + } + }; + + AttributeSnapshot snapshot = new PacketAccessor().attributeSnapshot("generic.Maxhealth", 20.0, modifiers); attribute.getSpecificModifier(List.class).write(0, Lists.newArrayList(snapshot)); PacketContainer cloned = attribute.deepClone(); diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java index d2c79311..8bdc5b47 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/utility/MinecraftReflectionTest.java @@ -4,12 +4,12 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import net.minecraft.server.v1_8_R1.ChatComponentText; -import net.minecraft.server.v1_8_R1.ChatSerializer; -import net.minecraft.server.v1_8_R1.IChatBaseComponent; -import net.minecraft.server.v1_8_R1.ServerPing; -import net.minecraft.server.v1_8_R1.ServerPingPlayerSample; -import net.minecraft.server.v1_8_R1.ServerPingServerData; +import net.minecraft.server.v1_8_R2.ChatComponentText; +import net.minecraft.server.v1_8_R2.IChatBaseComponent; +import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer; +import net.minecraft.server.v1_8_R2.ServerPing; +import net.minecraft.server.v1_8_R2.ServerPing.ServerData; +import net.minecraft.server.v1_8_R2.ServerPing.ServerPingPlayerSample; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -96,7 +96,7 @@ public class MinecraftReflectionTest { @Test public void testServerPingServerData() { - assertEquals(ServerPingServerData.class, MinecraftReflection.getServerPingServerDataClass()); + assertEquals(ServerData.class, MinecraftReflection.getServerPingServerDataClass()); } // @Test diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/utility/StreamSerializerTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/utility/StreamSerializerTest.java index 2bad5584..d2f95a0c 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/utility/StreamSerializerTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/utility/StreamSerializerTest.java @@ -8,10 +8,10 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import net.minecraft.server.v1_8_R1.IntHashMap; +import net.minecraft.server.v1_8_R2.IntHashMap; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemFactory; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemFactory; import org.bukkit.inventory.ItemStack; import org.junit.BeforeClass; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java index 942370a8..7e7d175b 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/ChunkCoordIntPairTest.java @@ -15,15 +15,15 @@ public class ChunkCoordIntPairTest { @Test public void test() { - net.minecraft.server.v1_8_R1.ChunkCoordIntPair pair = new net.minecraft.server.v1_8_R1.ChunkCoordIntPair(1, 2); + net.minecraft.server.v1_8_R2.ChunkCoordIntPair pair = new net.minecraft.server.v1_8_R2.ChunkCoordIntPair(1, 2); ChunkCoordIntPair specific = ChunkCoordIntPair.getConverter().getSpecific(pair); assertEquals(1, specific.getChunkX()); assertEquals(2, specific.getChunkZ()); - net.minecraft.server.v1_8_R1.ChunkCoordIntPair roundtrip = - (net.minecraft.server.v1_8_R1.ChunkCoordIntPair) ChunkCoordIntPair.getConverter(). - getGeneric(net.minecraft.server.v1_8_R1.ChunkCoordIntPair.class, specific); + net.minecraft.server.v1_8_R2.ChunkCoordIntPair roundtrip = + (net.minecraft.server.v1_8_R2.ChunkCoordIntPair) ChunkCoordIntPair.getConverter(). + getGeneric(net.minecraft.server.v1_8_R2.ChunkCoordIntPair.class, specific); assertEquals(1, roundtrip.x); assertEquals(2, roundtrip.z); diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java index 3e89d0c8..55e07a8f 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/EnumWrappersTest.java @@ -1,12 +1,12 @@ package com.comphenix.protocol.wrappers; import static org.junit.Assert.assertEquals; -import net.minecraft.server.v1_8_R1.EnumChatVisibility; -import net.minecraft.server.v1_8_R1.EnumClientCommand; -import net.minecraft.server.v1_8_R1.EnumDifficulty; -import net.minecraft.server.v1_8_R1.EnumEntityUseAction; -import net.minecraft.server.v1_8_R1.EnumGamemode; -import net.minecraft.server.v1_8_R1.EnumProtocol; +import net.minecraft.server.v1_8_R2.EntityHuman.EnumChatVisibility; +import net.minecraft.server.v1_8_R2.EnumDifficulty; +import net.minecraft.server.v1_8_R2.EnumProtocol; +import net.minecraft.server.v1_8_R2.PacketPlayInClientCommand.EnumClientCommand; +import net.minecraft.server.v1_8_R2.PacketPlayInUseEntity.EnumEntityUseAction; +import net.minecraft.server.v1_8_R2.WorldSettings.EnumGamemode; import org.junit.BeforeClass; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java index ee3073eb..8fc67a4f 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java @@ -4,11 +4,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; +import java.util.Collection; import java.util.List; -import net.minecraft.server.v1_8_R1.AttributeModifier; -import net.minecraft.server.v1_8_R1.AttributeSnapshot; -import net.minecraft.server.v1_8_R1.PacketPlayOutUpdateAttributes; +import net.minecraft.server.v1_8_R2.AttributeModifier; +import net.minecraft.server.v1_8_R2.PacketPlayOutUpdateAttributes; +import net.minecraft.server.v1_8_R2.PacketPlayOutUpdateAttributes.AttributeSnapshot; import org.junit.Before; import org.junit.BeforeClass; @@ -33,13 +34,13 @@ public class WrappedAttributeTest { @Before public void setUp() { // Create a couple of modifiers - doubleModifier = + doubleModifier = WrappedAttributeModifier.newBuilder(). name("Double Damage"). amount(1). operation(Operation.ADD_PERCENTAGE). build(); - constantModifier = + constantModifier = WrappedAttributeModifier.newBuilder(). name("Damage Bonus"). amount(5). @@ -84,9 +85,15 @@ public class WrappedAttributeTest { for (WrappedAttributeModifier wrapper : attribute.getModifiers()) { modifiers.add((AttributeModifier) wrapper.getHandle()); } - return new AttributeSnapshot( - (PacketPlayOutUpdateAttributes) attribute.getParentPacket().getHandle(), - attribute.getAttributeKey(), attribute.getBaseValue(), modifiers); + + class PacketAccessor extends PacketPlayOutUpdateAttributes { + + public AttributeSnapshot attributeSnapshot(String string, double d, Collection coll) { + return new AttributeSnapshot(string, d, coll); + } + } + + return new PacketAccessor().attributeSnapshot(attribute.getAttributeKey(), attribute.getBaseValue(), modifiers); } private AttributeModifier getModifierCopy(WrappedAttributeModifier modifier) { diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedWatchableObjectTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedWatchableObjectTest.java index 811c9b43..5d59a637 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedWatchableObjectTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedWatchableObjectTest.java @@ -3,7 +3,7 @@ package com.comphenix.protocol.wrappers; import static org.junit.Assert.assertEquals; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemFactory; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemFactory; import org.bukkit.inventory.ItemStack; import org.junit.BeforeClass; import org.junit.Test; diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java index 078f20e0..9200110a 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/NbtFactoryTest.java @@ -27,7 +27,7 @@ import java.io.DataOutput; import java.io.DataOutputStream; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemFactory; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemFactory; import org.bukkit.inventory.ItemStack; import org.junit.BeforeClass; import org.junit.Test;