From cdc02b4090935e4a808d38dfe65f5f3eeda71579 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 8 Dec 2013 07:51:37 +1300 Subject: [PATCH] Cleaned up code. Fixed error for sounds handling --- .../disguise/disguisetypes/FlagWatcher.java | 8 ++++---- .../disguise/utilities/DisguiseUtilities.java | 19 ++++++++++--------- .../disguise/utilities/PacketsManager.java | 5 ++++- .../disguise/utilities/ReflectionManager.java | 12 ++++++------ 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index ff3c9291..dc79010f 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -282,15 +282,15 @@ public class FlagWatcher { setItemInHand(itemstack); } - public void setItemInHand(org.bukkit.inventory.ItemStack itemstack) { - setItemStack(SlotType.HELD_ITEM, itemstack); - } - public void setInvisible(boolean setInvis) { setFlag(0, 5, setInvis); sendData(0); } + public void setItemInHand(org.bukkit.inventory.ItemStack itemstack) { + setItemStack(SlotType.HELD_ITEM, itemstack); + } + public void setItemStack(int slot, org.bukkit.inventory.ItemStack itemStack) { // Itemstack which is null means that its not replacing the disguises itemstack. if (itemStack == null) { diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index cb1fb466..41876296 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -226,6 +226,7 @@ public class DisguiseUtilities { if (player.equals(((Player) ReflectionManager.getBukkitEntity(p)).getName())) { clear.invoke(entityTrackerEntry, p); updatePlayer.invoke(entityTrackerEntry, p); + break; } } } @@ -373,9 +374,9 @@ public class DisguiseUtilities { Vector velocity = player.getVelocity(); manager.sendServerPacket( player, - manager.createPacketConstructor(PacketType.Play.Server.ENTITY_VELOCITY, player.getEntityId(), velocity.getX(), - velocity.getY(), velocity.getZ()).createPacket(player.getEntityId(), velocity.getX(), - velocity.getY(), velocity.getZ())); + manager.createPacketConstructor(PacketType.Play.Server.ENTITY_VELOCITY, player.getEntityId(), + velocity.getX(), velocity.getY(), velocity.getZ()).createPacket(player.getEntityId(), + velocity.getX(), velocity.getY(), velocity.getZ())); } // Why the hell would he even need this. Meh. @@ -399,9 +400,10 @@ public class DisguiseUtilities { } if (item != null && item.getType() != Material.AIR) { - manager.sendServerPacket(player, - manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EQUIPMENT, player.getEntityId(), i, item) - .createPacket(player.getEntityId(), i, item)); + manager.sendServerPacket( + player, + manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EQUIPMENT, player.getEntityId(), i, + item).createPacket(player.getEntityId(), i, item)); } } Location loc = player.getLocation(); @@ -409,9 +411,8 @@ public class DisguiseUtilities { if (player.isSleeping()) { manager.sendServerPacket( player, - manager.createPacketConstructor(PacketType.Play.Server.BED, player, 0, loc.getBlockX(), - loc.getBlockY(), loc.getBlockZ()).createPacket(player, 0, loc.getBlockX(), loc.getBlockY(), - loc.getBlockZ())); + manager.createPacketConstructor(PacketType.Play.Server.BED, player, 0, loc.getBlockX(), loc.getBlockY(), + loc.getBlockZ()).createPacket(player, 0, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); } // Resend any active potion effects diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 663c5c48..224dea7d 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -2,6 +2,7 @@ package me.libraryaddict.disguise.utilities; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Random; @@ -539,7 +540,9 @@ public class PacketsManager { Class blockClass = ReflectionManager.getNmsClass("Block"); Object block; if (ReflectionManager.isAfter17()) { - block = blockClass.getMethod("REGISTRY", int.class).invoke(null, typeId); + block = ReflectionManager.getNmsClass("RegistryMaterials") + .getMethod("a", int.class) + .invoke(blockClass.getField("REGISTRY").get(null), typeId); } else { block = ((Object[]) blockClass.getField("byId").get(null))[typeId]; } diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index 9ec53b64..29373cfa 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -12,10 +12,10 @@ import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack; public class ReflectionManager { + private static boolean after17 = true; 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 { @@ -53,11 +53,7 @@ public class ReflectionManager { } } - }public static boolean isAfter17() { - return after17; - } - - public static Object createEntityInstance(String entityName) { + }public static Object createEntityInstance(String entityName) { try { Class entityClass = getNmsClass("Entity" + entityName); Object entityObject; @@ -194,4 +190,8 @@ public class ReflectionManager { return null; } + public static boolean isAfter17() { + return after17; + } + }