mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-11-05 09:09:40 +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,22 +69,31 @@ 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() {
|
|
||||||
try {
|
|
||||||
for (PacketContainer packet : entry.getValue()) {
|
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSpawnPacket) {
|
if (!largestTick.isPresent()) {
|
||||||
PacketsManager.getPacketsHandler().removeCancel(disguise, observer);
|
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 {
|
||||||
|
for (PacketContainer packet : entry.getValue()) {
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (InvocationTargetException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isRemoveCancel) {
|
||||||
|
PacketsManager.getPacketsHandler().removeCancel(disguise, observer);
|
||||||
|
}
|
||||||
}, entry.getKey());
|
}, entry.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user