From 1f6b873f846fd3599005480c1cb0cca3fa9205a9 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sat, 29 Nov 2014 13:12:35 -0500 Subject: [PATCH] ChunkPosition was replaced by BlockPosition --- .../reflect/cloning/BukkitCloner.java | 3 +- .../protocol/utility/MinecraftReflection.java | 50 ++++++++++++++++--- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java index cf4c8f16..dedaf7f2 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java @@ -40,8 +40,7 @@ public class BukkitCloner implements Cloner { List> classes = Lists.newArrayList(); classes.add(MinecraftReflection.getItemStackClass()); - // TODO: Chunk position does not exist - // classes.add(MinecraftReflection.getChunkPositionClass()); + classes.add(MinecraftReflection.getBlockPositionClass()); classes.add(MinecraftReflection.getDataWatcherClass()); if (MinecraftReflection.isUsingNetty()) { 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 95d200f9..42076c61 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java @@ -418,12 +418,23 @@ public class MinecraftReflection { /** * Determine if a given object is a ChunkPosition. * @param obj - the object to test. + * @deprecated ChunkPosition no longer exists * @return TRUE if it can, FALSE otherwise. */ + @Deprecated public static boolean isChunkPosition(Object obj) { return obj != null && getChunkPositionClass().isAssignableFrom(obj.getClass()); } + /** + * Determine if a given object is a BlockPosition. + * @param obj - the object to test. + * @return TRUE if it can, FALSE otherwise. + */ + public static boolean isBlockPosition(Object obj) { + return obj != null && getBlockPositionClass().isAssignableFrom(obj.getClass()); + } + /** * Determine if the given object is an NMS ChunkCoordIntPar. * @param obj - the object. @@ -1167,26 +1178,53 @@ public class MinecraftReflection { } /** - * Retrieve the ChunkPosition class. + * Retrieves the ChunkPosition class. + * + * @deprecated ChunkPosition no longer exists. Replaced by BlockPosition. * @return The ChunkPosition class. */ + @Deprecated public static Class getChunkPositionClass() { try { return getMinecraftClass("ChunkPosition"); + } catch (RuntimeException e) { + return getBlockPositionClass(); +// Class normalChunkGenerator = getCraftBukkitClass("generator.NormalChunkGenerator"); +// +// // ChunkPosition a(net.minecraft.server.World world, String string, int i, int i1, int i2) { +// FuzzyMethodContract selected = FuzzyMethodContract.newBuilder() +// .banModifier(Modifier.STATIC) +// .parameterMatches(getMinecraftObjectMatcher(), 0) +// .parameterExactType(String.class, 1) +// .parameterExactType(int.class, 2) +// .parameterExactType(int.class, 3) +// .parameterExactType(int.class, 4) +// .build(); +// +// return setMinecraftClass("ChunkPosition", +// FuzzyReflection.fromClass(normalChunkGenerator).getMethod(selected).getReturnType()); + } + } + + /** + * Retrieves the BlockPosition class. + * @return The BlockPosition class. + */ + public static Class getBlockPositionClass() { + try { + return getMinecraftClass("BlockPosition"); } catch (RuntimeException e) { Class normalChunkGenerator = getCraftBukkitClass("generator.NormalChunkGenerator"); - // ChunkPosition a(net.minecraft.server.World world, String string, int i, int i1, int i2) { + // BlockPosition findNearestMapFeature(World, String, BlockPosition) FuzzyMethodContract selected = FuzzyMethodContract.newBuilder() .banModifier(Modifier.STATIC) .parameterMatches(getMinecraftObjectMatcher(), 0) .parameterExactType(String.class, 1) - .parameterExactType(int.class, 2) - .parameterExactType(int.class, 3) - .parameterExactType(int.class, 4) + .parameterMatches(getMinecraftObjectMatcher(), 1) .build(); - return setMinecraftClass("ChunkPosition", + return setMinecraftClass("BlockPosition", FuzzyReflection.fromClass(normalChunkGenerator).getMethod(selected).getReturnType()); } }