From b2193ad0212699bba2414340fe500664a6f361cd Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 21 Dec 2019 12:02:30 +1300 Subject: [PATCH] Remove meta after a set tick, not last packet --- .../disguise/utilities/packets/LibsPackets.java | 12 ++++++------ .../packets/packethandlers/PacketHandlerSpawn.java | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/LibsPackets.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/LibsPackets.java index 4249c0bd..e32e8b12 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/LibsPackets.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/LibsPackets.java @@ -21,6 +21,7 @@ public class LibsPackets { private boolean isSpawnPacket; private Disguise disguise; private boolean doNothing; + private int removeMetaAt = -1; public LibsPackets(Disguise disguise) { this.disguise = disguise; @@ -30,6 +31,10 @@ public class LibsPackets { doNothing = true; } + public void setRemoveMetaAt(int tick) { + removeMetaAt = tick; + } + public boolean isUnhandled() { return doNothing; } @@ -71,16 +76,11 @@ public class LibsPackets { public void sendDelayed(final Player observer) { Iterator>> itel = delayedPackets.entrySet().iterator(); - Optional largestTick = delayedPackets.keySet().stream().max(Integer::compare); - - if (!largestTick.isPresent()) { - return; - } while (itel.hasNext()) { Map.Entry> entry = itel.next(); // If this is the last delayed packet - final boolean isRemoveCancel = isSpawnPacket && largestTick.get().equals(entry.getKey()); + final boolean isRemoveCancel = isSpawnPacket && entry.getKey() >= removeMetaAt && removeMetaAt >= 0; Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> { if (isRemoveCancel) { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java index e5d01800..a5c976ec 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java @@ -254,6 +254,7 @@ public class PacketHandlerSpawn implements IPacketHandler { // Add a delay to remove the entry from 'cancelMeta' packets.addDelayedPacket(metaPacket, 7); + packets.setRemoveMetaAt(7); } // Remove player from the list @@ -436,6 +437,7 @@ public class PacketHandlerSpawn implements IPacketHandler { if (delayedArmor) { packets.addDelayedPacket(packet, 7); + packets.setRemoveMetaAt(7); } else { packets.addDelayedPacket(packet); }