package de.steamwar.fightsystem.utils; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketEvent; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import javafx.util.Pair; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Collections; import java.util.List; import static de.steamwar.fightsystem.utils.ITechHider.bypass; public class TechHider { private TechHider(){} private static boolean running = false; public static void init(){ if(disabled()) return; if(Core.getVersion() > 8){ ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ITEM) { @Override public void onPacketReceiving(PacketEvent e) { Player p = e.getPlayer(); if(p.getGameMode() == GameMode.SPECTATOR) e.setCancelled(true); } }); } ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ENTITY) { @Override public void onPacketReceiving(PacketEvent e) { Player p = e.getPlayer(); if(p.getGameMode() == GameMode.SPECTATOR) e.setCancelled(true); } }); } public static void start(){ if(running) return; running = true; if(disabled()) return; switch(Core.getVersion()){ case 8: break; default: TechHider_12.start(); } } public static List> prepareChunkReload(Player p){ if(disabled()) return Collections.emptyList(); List> chunksToReload = new ArrayList<>(); for(int x = ITechHider.arenaMinX; x <= ITechHider.arenaMaxX; x++) for(int z = ITechHider.arenaMinZ; z <= ITechHider.arenaMaxZ; z++) if(!bypass(p, x, z)) chunksToReload.add(new Pair<>(x, z)); return chunksToReload; } public static void reloadChunks(Player p, List> chunksToReload){ if(disabled()) return; Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { for(Pair chunk : chunksToReload){ if(bypass(p, chunk.getKey(), chunk.getValue())) reloadChunk(p, chunk); } }, 40); } private static void reloadChunk(Player p, Pair chunk){ switch(Core.getVersion()){ case 8: TechHider_8.reloadChunk(p, chunk); break; default: TechHider_12.reloadChunk(p, chunk); } } private static boolean disabled(){ return Config.OnlyPublicSchematics; } }