From c214ca02e8f326651d371330769ce1b5ac876124 Mon Sep 17 00:00:00 2001 From: Mats Date: Thu, 14 Apr 2016 13:59:23 +0200 Subject: [PATCH] Make commandblocks compatible with all 1.8 spigot/craftbukkit versions, fix #355 (#356) --- .../protocol1_9to1_8/listeners/CommandBlockListener.java | 8 ++++++-- .../java/us/myles/ViaVersion/util/ReflectionUtil.java | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/listeners/CommandBlockListener.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/listeners/CommandBlockListener.java index 35db915bc..f6a6911ab 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/listeners/CommandBlockListener.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/listeners/CommandBlockListener.java @@ -122,11 +122,15 @@ public class CommandBlockListener implements Listener { private long[] getPosition(Object obj) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { return new long[]{ (long) ReflectionUtil.getSuper(obj, "a", int.class), //X - (long) ReflectionUtil.getSuper(obj, "c", int.class), //Y - (long) ReflectionUtil.getSuper(obj, "d", int.class) //Z + (long) ReflectionUtil.getSuper(obj, isR1() ? "b" : "c", int.class), //Y + (long) ReflectionUtil.getSuper(obj, isR1() ? "c" : "d", int.class) //Z }; } + private boolean isR1() { + return ReflectionUtil.getVersion().equals("v1_8_R1"); + } + private CompoundTag getNBT(Object obj) throws Exception { ByteBuf buf = Unpooled.buffer(); Method m = ReflectionUtil.nms("NBTCompressedStreamTools").getMethod("a", ReflectionUtil.nms("NBTTagCompound"), DataOutput.class); diff --git a/src/main/java/us/myles/ViaVersion/util/ReflectionUtil.java b/src/main/java/us/myles/ViaVersion/util/ReflectionUtil.java index 7b0c51a6e..9bc115a82 100644 --- a/src/main/java/us/myles/ViaVersion/util/ReflectionUtil.java +++ b/src/main/java/us/myles/ViaVersion/util/ReflectionUtil.java @@ -22,6 +22,10 @@ public class ReflectionUtil { return Class.forName(BASE + "." + className); } + public static String getVersion() { + return BASE.substring(BASE.lastIndexOf('.') + 1); + } + public static Object invokeStatic(Class clazz, String method) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Method m = clazz.getDeclaredMethod(method); return m.invoke(null);