Remove meta after a set tick, not last packet

This commit is contained in:
libraryaddict 2019-12-21 12:02:30 +13:00
parent 3ee66d918c
commit b2193ad021
2 changed files with 8 additions and 6 deletions

@ -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<Map.Entry<Integer, ArrayList<PacketContainer>>> itel = delayedPackets.entrySet().iterator();
Optional<Integer> largestTick = delayedPackets.keySet().stream().max(Integer::compare);
if (!largestTick.isPresent()) {
return;
}
while (itel.hasNext()) {
Map.Entry<Integer, ArrayList<PacketContainer>> 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) {

@ -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);
}