From 1cea2e21634ea6c2e616fbdec1508dfcd45e3ded Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 19 Jan 2014 11:32:02 +1300 Subject: [PATCH] Silly mojang and their silly bugs. Fixed right clicking not always working --- .../disguise/disguisetypes/FlagWatcher.java | 5 +--- .../disguise/utilities/PacketsManager.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 26f850be..b51b2acf 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -4,7 +4,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import org.bukkit.entity.Entity; @@ -68,12 +67,10 @@ public class FlagWatcher { } public List convert(List list) { - Iterator itel = list.iterator(); List newList = new ArrayList(); HashSet sentValues = new HashSet(); boolean sendAllCustom = false; - while (itel.hasNext()) { - WrappedWatchableObject watch = itel.next(); + for (WrappedWatchableObject watch : list) { int dataType = watch.getIndex(); sentValues.add(dataType); // Its sending the air metadata. This is the least commonly sent metadata which all entitys still share. diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 25c47892..9f690468 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -1208,6 +1208,33 @@ public class PacketsManager { packets[0].getModifier().write(2, (itemstack.getTypeId() == 0 ? null : ReflectionManager.getNmsItem(itemstack))); } + if (disguise.getWatcher().isRightClicking() && slot == 4) { + ItemStack heldItem = packets[0].getItemModifier().read(0); + if (heldItem != null && heldItem.getType() != Material.AIR) { + // Convert the datawatcher + WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(entity); + List list = new ArrayList(); + for (WrappedWatchableObject value : dataWatcher.getWatchableObjects()) { + if (value.getIndex() == 0) { + list.add(value); + } + } + list = disguise.getWatcher().convert(list); + // Construct the packets to return + PacketContainer packetBlock = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); + packetBlock.getModifier().write(0, entity.getEntityId()); + packetBlock.getWatchableCollectionModifier().write(0, list); + PacketContainer packetUnblock = packetBlock.deepClone(); + // Make a packet to send the 'unblock' + for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) { + watcher.setValue((byte) ((Byte) watcher.getValue() & ~(1 << 4))); + } + // Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? Scheduler delay. + packets = new PacketContainer[] { packetUnblock, packets[0], packetBlock }; + // Silly mojang made the right clicking datawatcher value only valid for one use. So I have to reset + // it. + } + } } else if (sentPacket.getType() == PacketType.Play.Server.BED) {