mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-11-06 09:19:35 +01:00
Remove meta cancel only once and when it's the last delayed packet
This commit is contained in:
parent
6d64f44b15
commit
b813c5b899
@ -9,10 +9,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by libraryaddict on 3/01/2019.
|
* Created by libraryaddict on 3/01/2019.
|
||||||
@ -72,9 +69,19 @@ public class LibsPackets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendDelayed(final Player observer) {
|
public void sendDelayed(final Player observer) {
|
||||||
for (final Map.Entry<Integer, ArrayList<PacketContainer>> entry : delayedPackets.entrySet()) {
|
Iterator<Map.Entry<Integer, ArrayList<PacketContainer>>> itel = delayedPackets.entrySet().iterator();
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), new Runnable() {
|
Optional<Integer> largestTick = delayedPackets.keySet().stream().max(Integer::compare);
|
||||||
public void run() {
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
for (PacketContainer packet : entry.getValue()) {
|
for (PacketContainer packet : entry.getValue()) {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||||
@ -84,10 +91,9 @@ public class LibsPackets {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSpawnPacket) {
|
if (isRemoveCancel) {
|
||||||
PacketsManager.getPacketsHandler().removeCancel(disguise, observer);
|
PacketsManager.getPacketsHandler().removeCancel(disguise, observer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}, entry.getKey());
|
}, entry.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user