diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 07aee163..6f34acc1 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -729,30 +729,7 @@ public class FlagWatcher { return; if (itemStack == null && getDisguise().getEntity() instanceof LivingEntity) { - EntityEquipment equip = ((LivingEntity) getDisguise().getEntity()).getEquipment(); - - switch (slot) { - case HAND: - itemStack = equip.getItemInMainHand(); - break; - case OFF_HAND: - itemStack = equip.getItemInOffHand(); - break; - case HEAD: - itemStack = equip.getHelmet(); - break; - case CHEST: - itemStack = equip.getChestplate(); - break; - case LEGS: - itemStack = equip.getLeggings(); - break; - case FEET: - itemStack = equip.getBoots(); - break; - default: - break; - } + itemStack = ReflectionManager.getEquipment(slot, getDisguise().getEntity()); } Object itemToSend = ReflectionManager.getNmsItem(itemStack); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index c1f424c7..c8ebd11d 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -46,8 +46,10 @@ import org.bukkit.*; import org.bukkit.boss.KeyedBossBar; import org.bukkit.command.CommandSender; import org.bukkit.entity.*; +import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.scheduler.BukkitRunnable; @@ -2024,6 +2026,28 @@ public class DisguiseUtilities { return list.toArray(new String[0]); } + + public static ItemStack getSlot(PlayerInventory equip, EquipmentSlot slot) { + switch (slot) { + case HAND: + return equip.getItemInMainHand(); + case OFF_HAND: + return equip.getItemInOffHand(); + case HEAD: + return equip.getHelmet(); + case CHEST: + return equip.getChestplate(); + case LEGS: + return equip.getLeggings(); + case FEET: + return equip.getBoots(); + default: + break; + } + + return null; + } + /** * Sends the self disguise to the player */ @@ -2122,11 +2146,11 @@ public class DisguiseUtilities { manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, list).createPacket(0, list)); } else { for (EquipmentSlot slot : EquipmentSlot.values()) { + Object item = ReflectionManager.getNmsItem(getSlot(player.getInventory(), slot)); + sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, - ReflectionManager.createEnumItemSlot(slot), - ReflectionManager.getNmsItem(player.getInventory().getItem(slot))) - .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(slot), - ReflectionManager.getNmsItem(player.getInventory().getItem(slot)))); + ReflectionManager.createEnumItemSlot(slot), item) + .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(slot), item)); } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index b4702f84..6d8a9aea 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -1121,7 +1121,9 @@ public class ReflectionManager { Method toMinecraft = getCraftMethod("util.CraftMagicNumbers", "getMaterialFromInternalName", String.class); - return (Material) toMinecraft.invoke(null, name); + Object instance = toMinecraft.getDeclaringClass().getField("INSTANCE").get(null); + + return (Material) toMinecraft.invoke(instance, name); } Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name); @@ -1140,7 +1142,12 @@ public class ReflectionManager { return (Material) getMaterial.invoke(null, item); } catch (Exception ex) { + DisguiseUtilities.getLogger().severe("Error when trying to convert '" + name + "' into a Material"); ex.printStackTrace(); + + if (ex.getCause() != null) { + ex.getCause().printStackTrace(); + } } return null;