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

View File

@ -21,6 +21,7 @@ public class LibsPackets {
private boolean isSpawnPacket; private boolean isSpawnPacket;
private Disguise disguise; private Disguise disguise;
private boolean doNothing; private boolean doNothing;
private int removeMetaAt = -1;
public LibsPackets(Disguise disguise) { public LibsPackets(Disguise disguise) {
this.disguise = disguise; this.disguise = disguise;
@ -30,6 +31,10 @@ public class LibsPackets {
doNothing = true; doNothing = true;
} }
public void setRemoveMetaAt(int tick) {
removeMetaAt = tick;
}
public boolean isUnhandled() { public boolean isUnhandled() {
return doNothing; return doNothing;
} }
@ -71,16 +76,11 @@ public class LibsPackets {
public void sendDelayed(final Player observer) { public void sendDelayed(final Player observer) {
Iterator<Map.Entry<Integer, ArrayList<PacketContainer>>> itel = delayedPackets.entrySet().iterator(); 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()) { while (itel.hasNext()) {
Map.Entry<Integer, ArrayList<PacketContainer>> entry = itel.next(); Map.Entry<Integer, ArrayList<PacketContainer>> entry = itel.next();
// If this is the last delayed packet // 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(), () -> { Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
if (isRemoveCancel) { if (isRemoveCancel) {

View File

@ -254,6 +254,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
// Add a delay to remove the entry from 'cancelMeta' // Add a delay to remove the entry from 'cancelMeta'
packets.addDelayedPacket(metaPacket, 7); packets.addDelayedPacket(metaPacket, 7);
packets.setRemoveMetaAt(7);
} }
// Remove player from the list // Remove player from the list
@ -436,6 +437,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
if (delayedArmor) { if (delayedArmor) {
packets.addDelayedPacket(packet, 7); packets.addDelayedPacket(packet, 7);
packets.setRemoveMetaAt(7);
} else { } else {
packets.addDelayedPacket(packet); packets.addDelayedPacket(packet);
} }