SteamWar/FightSystem
Archiviert
13
1
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
FightSystem/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java

104 Zeilen
3.2 KiB
Java

2019-09-05 18:26:13 +02:00
package de.steamwar.fightsystem.utils;
2019-04-25 20:33:36 +02:00
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
2019-11-10 22:34:22 +01:00
import de.steamwar.core.Core;
2019-11-16 08:37:33 +01:00
import de.steamwar.fightsystem.Config;
2019-09-05 18:26:13 +02:00
import de.steamwar.fightsystem.FightSystem;
import javafx.util.Pair;
import org.bukkit.Bukkit;
2019-05-28 06:16:16 +02:00
import org.bukkit.GameMode;
2019-04-25 20:33:36 +02:00
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
2019-04-25 20:33:36 +02:00
2019-11-16 08:37:33 +01:00
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
2019-04-25 20:33:36 +02:00
public class TechHider {
2019-06-22 17:11:10 +02:00
private TechHider(){}
private static boolean running = false;
2019-05-28 06:16:16 +02:00
2019-04-25 20:33:36 +02:00
public static void init(){
2019-09-12 20:46:21 +02:00
if(disabled())
return;
2019-11-10 22:34:22 +01:00
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)
2019-11-10 22:34:22 +01:00
e.setCancelled(true);
}
2019-11-10 22:34:22 +01:00
});
}
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;
2019-11-15 08:22:16 +01:00
if(disabled())
return;
2019-11-15 08:22:16 +01:00
switch(Core.getVersion()){
case 8:
break;
default:
TechHider_12.start();
2019-11-15 08:22:16 +01:00
}
2019-11-10 17:29:59 +01:00
}
public static List<Pair<Integer, Integer>> prepareChunkReload(Player p){
2019-09-12 20:46:21 +02:00
if(disabled())
return Collections.emptyList();
List<Pair<Integer, Integer>> 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<Pair<Integer, Integer>> chunksToReload){
2019-09-12 20:46:21 +02:00
if(disabled())
return;
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
for(Pair<Integer, Integer> chunk : chunksToReload){
if(bypass(p, chunk.getKey(), chunk.getValue()))
2019-11-10 22:34:22 +01:00
reloadChunk(p, chunk);
}
2019-06-22 17:11:10 +02:00
}, 40);
}
2019-11-10 22:34:22 +01:00
private static void reloadChunk(Player p, Pair<Integer, Integer> chunk){
switch(Core.getVersion()){
case 8:
2019-11-15 08:22:16 +01:00
TechHider_8.reloadChunk(p, chunk);
2019-11-10 22:34:22 +01:00
break;
default:
2019-11-15 08:22:16 +01:00
TechHider_12.reloadChunk(p, chunk);
2019-11-10 22:34:22 +01:00
}
}
2019-09-12 20:46:21 +02:00
private static boolean disabled(){
2019-11-16 08:37:33 +01:00
return Config.OnlyPublicSchematics;
2019-04-25 20:33:36 +02:00
}
}