diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/other/NoClipCommand_15.java b/BauSystem_15/src/de/steamwar/bausystem/features/other/NoClipCommand_15.java index f5c44fe1..435c3528 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/features/other/NoClipCommand_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/features/other/NoClipCommand_15.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.other; +import lombok.experimental.UtilityClass; import net.minecraft.server.v1_15_R1.EnumGamemode; import net.minecraft.server.v1_15_R1.PlayerInteractManager; import org.bukkit.GameMode; @@ -27,11 +28,12 @@ import org.bukkit.entity.Player; import java.lang.reflect.Field; +@UtilityClass public class NoClipCommand_15 { - private static Field gameModeField; + private Field gameModeField; - public static void setGameModeInternal(Player player, GameMode gameMode) { + public void setGameModeInternal(Player player, GameMode gameMode) { CraftPlayer craftPlayer = (CraftPlayer) player; EnumGamemode enumGamemode = EnumGamemode.getById(gameMode.getValue()); try { @@ -42,7 +44,7 @@ public class NoClipCommand_15 { } } - private static void checkCache() throws NoSuchFieldException { + private void checkCache() throws NoSuchFieldException { if (gameModeField == null) { gameModeField = PlayerInteractManager.class.getDeclaredField("gamemode"); gameModeField.setAccessible(true); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/KillAllCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/KillAllCommand.java index 52d0ccfd..2c1ce821 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/KillAllCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/KillAllCommand.java @@ -30,10 +30,8 @@ import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.command.SWCommand; import org.bukkit.Bukkit; import org.bukkit.World; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @Linked(LinkageType.COMMAND) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java index be6d29d4..f260bcb2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -42,6 +42,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent; +import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerToggleFlightEvent; import java.lang.reflect.InvocationTargetException; @@ -79,14 +80,6 @@ public class NoClipCommand extends SWCommand implements Listener { } } }); - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.SPECTATE) { - @Override - public void onPacketReceiving(PacketEvent event) { - if (NOCLIPS.contains(event.getPlayer())) { - event.setCancelled(true); - } - } - }); } @Register(help = true) @@ -138,4 +131,15 @@ public class NoClipCommand extends SWCommand implements Listener { event.getPlayer().setFlying(true); } } + + @EventHandler(ignoreCancelled = true) + public void onPlayerTeleport(PlayerTeleportEvent event) { + if (event.getCause() != PlayerTeleportEvent.TeleportCause.SPECTATE) { + return; + } + if (NOCLIPS.contains(event.getPlayer())) { + event.getPlayer().setSpectatorTarget(null); + event.setCancelled(true); + } + } } \ No newline at end of file