From b29e8e611517647692926f2a1cfeb1655829a37a Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 6 Dec 2013 20:13:45 +1300 Subject: [PATCH] Read desc Added method to reflection manager to check if after 1.7 Fixed error with packet use entity Fixed error with walk sounds --- .../disguise/utilities/PacketsManager.java | 9 +++++-- .../disguise/utilities/ReflectionManager.java | 24 ++++++++++--------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index d685b607..cd5012fa 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -110,7 +110,7 @@ public class PacketsManager { try { Player observer = event.getPlayer(); StructureModifier entityModifer = event.getPacket().getEntityModifier(observer.getWorld()); - org.bukkit.entity.Entity entity = entityModifer.read(1); + org.bukkit.entity.Entity entity = entityModifer.read(ReflectionManager.isAfter17() ? 1 : 0); if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow) { event.setCancelled(true); } @@ -535,7 +535,12 @@ public class PacketsManager { int typeId = soundLoc.getWorld().getBlockTypeIdAt(soundLoc.getBlockX(), soundLoc.getBlockY() - 1, soundLoc.getBlockZ()); Class blockClass = ReflectionManager.getNmsClass("Block"); - Object block = ((Object[]) blockClass.getField("byId").get(null))[typeId]; + Object block; + if (ReflectionManager.isAfter17()) { + block = blockClass.getMethod("REGISTRY", int.class).invoke(null, typeId); + } else { + block = ((Object[]) blockClass.getField("byId").get(null))[typeId]; + } if (block != null) { Object step = blockClass.getField("stepSound").get(block); mods.write(0, step.getClass().getMethod("getStepSound").invoke(step)); diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index 8a1cd1a9..9ec53b64 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -15,6 +15,7 @@ public class ReflectionManager { private static String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3]; private static Class itemClass; private static Method soundMethod; + private static boolean after17 = true; static { for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) { try { @@ -43,6 +44,17 @@ public class ReflectionManager { } catch (Exception e) { e.printStackTrace(); } + if (bukkitVersion.startsWith("1.")) { + try { + if (Integer.parseInt(bukkitVersion.split("\\.")[1]) < 7) { + after17 = false; + } + } catch (Exception ex) { + + } + } + }public static boolean isAfter17() { + return after17; } public static Object createEntityInstance(String entityName) { @@ -51,20 +63,10 @@ public class ReflectionManager { Object entityObject; Object world = getWorld(Bukkit.getWorlds().get(0)); if (entityName.equals("Player")) { - boolean useOld = false; - if (bukkitVersion.startsWith("1.")) { - try { - if (Integer.parseInt(bukkitVersion.split("\\.")[1]) < 7) { - useOld = true; - } - } catch (Exception ex) { - - } - } Object minecraftServer = getNmsClass("MinecraftServer").getMethod("getServer").invoke(null); Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World")) .newInstance(world); - if (useOld) { + if (!isAfter17()) { entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("World"), String.class, playerinteractmanager.getClass()).newInstance(minecraftServer, world, "LibsDisguises", playerinteractmanager);