From a3331788d4cbd01aa8af4ebd2dba83cc43b77186 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 7 Oct 2019 08:23:24 +0200 Subject: [PATCH] Starting Techhider delayed while schematicpasting --- .../steamwar/fightsystem/fight/FightTeam.java | 1 + .../steamwar/fightsystem/utils/TechHider.java | 53 +++++++++++-------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/de/steamwar/fightsystem/fight/FightTeam.java b/src/de/steamwar/fightsystem/fight/FightTeam.java index f3c9765..2db69a8 100644 --- a/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -292,6 +292,7 @@ public class FightTeam { if(Config.test()) pasteSchematic(); else if(Fight.getOpposite(this).hasSchematic()){ + TechHider.start(); pasteSchematic(); Fight.getOpposite(this).pasteSchematic(); } diff --git a/src/de/steamwar/fightsystem/utils/TechHider.java b/src/de/steamwar/fightsystem/utils/TechHider.java index 117ad1a..9804186 100644 --- a/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/src/de/steamwar/fightsystem/utils/TechHider.java @@ -50,6 +50,8 @@ public class TechHider { private static short obfuscateShift4; private static final short BITMASK = 0x1FF; private static Material obfuscateMaterial; + private static boolean running = false; + private static int threadMultiplier = 1; public static void init(){ if(disabled()) @@ -72,10 +74,39 @@ public class TechHider { obfuscateShift4 = (short)(Config.ObfuscateWith << 4); obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith); - int threadMultiplier = 1; if(Config.event()) threadMultiplier = 4; + ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(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); + } + } + }).start(threadMultiplier); + ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(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); + } + } + }).start(threadMultiplier); + } + + public static void start(){ + if(running) + return; + running = true; + + if(disabled()) + return; + ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { @Override public void onPacketSending(PacketEvent e) { @@ -243,26 +274,6 @@ public class TechHider { e.setCancelled(true); } }).start(); - ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(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); - } - } - }).start(threadMultiplier); - ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(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); - } - } - }).start(threadMultiplier); } private static boolean bypass(Player p, int chunkX, int chunkZ){