SteamWar/BauSystem2.0
Archiviert
12
0

Hotfix AntiCursorReCentering

Dieser Commit ist enthalten in:
yoyosource 2023-10-24 18:23:12 +02:00 committet von D4rkr34lm
Ursprung d1ff80b9dc
Commit f2a957c88f

Datei anzeigen

@ -25,40 +25,24 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.api.Enable;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.event.inventory.InventoryType;
@Linked
public class AntiCursorReCentering implements Enable {
private final Set<Player> CLOSE_PACKETS = new HashSet<>();
private final Set<Player> CLOSE_NOW = new HashSet<>();
@Override
public void enable() {
Class<?> closeWindow = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutCloseWindow");
TinyProtocol.instance.addFilter(closeWindow, (player, object) -> {
if (CLOSE_NOW.remove(player)) {
if (player.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) {
return object;
}
CLOSE_PACKETS.add(player);
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
if (CLOSE_PACKETS.remove(player)) {
CLOSE_NOW.add(player);
if (player.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) {
TinyProtocol.instance.sendPacket(player, object);
}
}, 0);
return null;
});
Class<?> openWindow = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutOpenWindow");
TinyProtocol.instance.addFilter(openWindow, (player, object) -> {
CLOSE_PACKETS.remove(player);
return object;
});
}
}