From 58f39401d2ccf27259dcee2a96c15520a73a5a06 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 8 Oct 2013 05:56:47 +1300 Subject: [PATCH] Did more work, but its not going to be done soon. So doing a release with it disabled --- .../libraryaddict/disguise/DisguiseAPI.java | 5 --- .../libraryaddict/disguise/LibsDisguises.java | 5 ++- .../disguise/PacketsManager.java | 31 ++++++++++++++++++- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseAPI.java b/src/me/libraryaddict/disguise/DisguiseAPI.java index 1bf81090..31a86671 100644 --- a/src/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/me/libraryaddict/disguise/DisguiseAPI.java @@ -45,7 +45,6 @@ public class DisguiseAPI { private static boolean hearSelfDisguise; private static boolean hidingArmor; private static boolean hidingHeldItem; - private static LibsDisguises libsDisguises; // A internal storage of fake entity ID's I can use. // Realistically I could probably use a ID like "4" for everyone seeing as no one shares the ID @@ -144,10 +143,6 @@ public class DisguiseAPI { return -1; } - protected static void init(LibsDisguises mainPlugin) { - libsDisguises = mainPlugin; - } - /** * Is this entity disguised */ diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 1346b931..09965b22 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -70,13 +70,12 @@ public class LibsDisguises extends JavaPlugin { e.printStackTrace(); } PacketsManager.init(this); - DisguiseAPI.init(this); DisguiseAPI.setSoundsEnabled(getConfig().getBoolean("DisguiseSounds")); DisguiseAPI.setVelocitySent(getConfig().getBoolean("SendVelocity")); DisguiseAPI.setViewDisguises(getConfig().getBoolean("ViewDisguises")); DisguiseAPI.setHearSelfDisguise(getConfig().getBoolean("HearSelfDisguise")); - DisguiseAPI.setHideArmorFromSelf(getConfig().getBoolean("RemoveArmor")); - DisguiseAPI.setHideHeldItemFromSelf(getConfig().getBoolean("RemoveHeldItem")); + // DisguiseAPI.setHideArmorFromSelf(getConfig().getBoolean("RemoveArmor")); + // DisguiseAPI.setHideHeldItemFromSelf(getConfig().getBoolean("RemoveHeldItem")); if (DisguiseAPI.isHidingArmorFromSelf() || DisguiseAPI.isHidingHeldItemFromSelf()) { DisguiseAPI.setInventoryListenerEnabled(true); } diff --git a/src/me/libraryaddict/disguise/PacketsManager.java b/src/me/libraryaddict/disguise/PacketsManager.java index a492fe59..c416ac5e 100644 --- a/src/me/libraryaddict/disguise/PacketsManager.java +++ b/src/me/libraryaddict/disguise/PacketsManager.java @@ -683,7 +683,7 @@ public class PacketsManager { }; // TODO Potentionally combine both listeners. inventoryListenerServer = new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGHEST, - Packets.Server.SET_SLOT) { + Packets.Server.SET_SLOT, Packets.Server.WINDOW_ITEMS) { @Override public void onPacketSending(PacketEvent event) { // If the inventory is the players inventory @@ -735,6 +735,33 @@ public class PacketsManager { case Packets.Server.WINDOW_ITEMS: { // TODO Find out how this works // It seems to 'update' the inventory.. Screw you.. + event.setPacket(event.getPacket().deepClone()); + StructureModifier mods = event.getPacket().getModifier(); + ItemStack[] items = (ItemStack[]) mods.read(1); + for (int slot = 0; slot < items.length; slot++) { + if (slot >= 5 && slot <= 8) { + if (disguise.isHidingArmorFromSelf()) { + // Get the bukkit armor slot! + int armorSlot = Math.abs((slot - 5) - 3); + org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot]; + if (item != null && item.getType() != Material.AIR) { + items[slot] = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)); + } + } + // Else if its a hotbar slot + } else if (slot >= 36 && slot <= 44) { + if (disguise.isHidingHeldItemFromSelf()) { + int currentSlot = event.getPlayer().getInventory().getHeldItemSlot(); + // Check if the player is on the same slot as the slot that its setting + if (slot == currentSlot + 36) { + org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); + if (item != null && item.getType() != Material.AIR) { + items[slot] = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)); + } + } + } + } + } break; } default: @@ -850,6 +877,8 @@ public class PacketsManager { org.bukkit.inventory.ItemStack clickedItem; if (event.getPacket().getIntegers().read(3) == 1) { // Its a shift click + // TODO Make the item appear in the right place + // Also set the armor/item in hand to air cos the client is stupid. clickedItem = event.getPacket().getItemModifier().read(0); if (clickedItem != null && clickedItem.getType() != Material.AIR) { org.bukkit.inventory.ItemStack armorItem = null;