Remove meta after a set tick, not last packet

This commit is contained in:
libraryaddict 2019-12-21 12:02:30 +13:00
parent 8350f72d23
commit d035c01d94
No known key found for this signature in database
GPG key ID: 052E4FBCD257AEA4
2 changed files with 8 additions and 6 deletions

View file

@ -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) {

View file

@ -249,6 +249,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
@ -425,6 +426,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
if (delayedArmor) {
packets.addDelayedPacket(packet, 7);
packets.setRemoveMetaAt(7);
} else {
packets.addDelayedPacket(packet);
}