From 4a9f3c3b53d052b2c2dad39562cb61a058717091 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 1 Jun 2021 19:22:51 +0200 Subject: [PATCH 1/9] Add Experimental Noclip Command Signed-off-by: Chaoscaot --- .../features/other/NoClipCommand.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java new file mode 100644 index 00000000..d98e1cee --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -0,0 +1,69 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.other; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers; +import com.comphenix.protocol.wrappers.PlayerInfoData; +import com.comphenix.protocol.wrappers.WrappedChatComponent; +import com.comphenix.protocol.wrappers.WrappedGameProfile; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.SWCommand; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +@Linked(LinkageType.COMMAND) +public class NoClipCommand extends SWCommand { + protected NoClipCommand() { + super("noclip", "nc"); + } + + @Register(help = true) + public void genericCommand(Player player, String... args) { + player.setGameMode(GameMode.SPECTATOR); + ((CraftPlayer) player).getHandle().abilities.mayBuild = true; + ((CraftPlayer) player).getHandle().abilities.canInstantlyBuild = true; + //player.sendMessage(((CraftPlayer) player).getHandle().noclip + ""); + PacketContainer gm3packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); + gm3packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); + List playerInfoActions = new ArrayList<>(); + playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, EnumWrappers.NativeGameMode.SPECTATOR, WrappedChatComponent.fromText(player.getDisplayName()))); + gm3packet.getPlayerInfoDataLists().write(0, playerInfoActions); + PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.GAME_STATE_CHANGE); + gm1packet.getIntegers().write(0, 3); + gm1packet.getFloat().write(0, 1F); + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm3packet); + } catch (InvocationTargetException e) { + Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); + } + } +} From df84e5b252182278ee860d54789a1496c9ad971c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 3 Jun 2021 23:54:21 +0200 Subject: [PATCH 2/9] Finalize NoClip Command Signed-off-by: Chaoscaot --- .../features/other/NoClipCommand_15.java | 51 ++++++++++ .../features/other/NoClipCommand.java | 93 +++++++++++++++---- 2 files changed, 125 insertions(+), 19 deletions(-) create mode 100644 BauSystem_15/src/de/steamwar/bausystem/features/other/NoClipCommand_15.java 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 new file mode 100644 index 00000000..f5c44fe1 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/features/other/NoClipCommand_15.java @@ -0,0 +1,51 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.other; + +import net.minecraft.server.v1_15_R1.EnumGamemode; +import net.minecraft.server.v1_15_R1.PlayerInteractManager; +import org.bukkit.GameMode; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import java.lang.reflect.Field; + +public class NoClipCommand_15 { + + private static Field gameModeField; + + public static void setGameModeInternal(Player player, GameMode gameMode) { + CraftPlayer craftPlayer = (CraftPlayer) player; + EnumGamemode enumGamemode = EnumGamemode.getById(gameMode.getValue()); + try { + checkCache(); + gameModeField.set(craftPlayer.getHandle().playerInteractManager, enumGamemode); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new SecurityException("Could not find Field?"); + } + } + + private static 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/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java index d98e1cee..b544a97f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -21,49 +21,104 @@ package de.steamwar.bausystem.features.other; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.PlayerInfoData; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedGameProfile; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.command.SWCommand; +import de.steamwar.core.VersionedRunnable; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockCanBuildEvent; +import org.bukkit.event.player.PlayerGameModeChangeEvent; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Level; @Linked(LinkageType.COMMAND) -public class NoClipCommand extends SWCommand { +@Linked(LinkageType.LISTENER) +public class NoClipCommand extends SWCommand implements Listener { + + private static final List NOCLIPS = new ArrayList<>(); + private static final Map LAST_TICKS = new HashMap<>(); + protected NoClipCommand() { super("noclip", "nc"); + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK) { + @Override + public void onPacketReceiving(PacketEvent event) { + if (NOCLIPS.contains(event.getPlayer())) { + if (LAST_TICKS.getOrDefault(event.getPlayer(), -1L).equals(TPSUtils.currentTick.get())) return; + VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(event.getPlayer(), GameMode.SPECTATOR), 15)); + LAST_TICKS.put(event.getPlayer(), TPSUtils.currentTick.get()); + } + } + }); + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.USE_ITEM, PacketType.Play.Client.BLOCK_DIG) { + @Override + public void onPacketReceiving(PacketEvent event) { + if (NOCLIPS.contains(event.getPlayer())) { + VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(event.getPlayer(), GameMode.CREATIVE), 15)); + LAST_TICKS.put(event.getPlayer(), TPSUtils.currentTick.get()); + } + } + }); } @Register(help = true) public void genericCommand(Player player, String... args) { - player.setGameMode(GameMode.SPECTATOR); - ((CraftPlayer) player).getHandle().abilities.mayBuild = true; - ((CraftPlayer) player).getHandle().abilities.canInstantlyBuild = true; - //player.sendMessage(((CraftPlayer) player).getHandle().noclip + ""); - PacketContainer gm3packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); - gm3packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); - List playerInfoActions = new ArrayList<>(); - playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, EnumWrappers.NativeGameMode.SPECTATOR, WrappedChatComponent.fromText(player.getDisplayName()))); - gm3packet.getPlayerInfoDataLists().write(0, playerInfoActions); - PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.GAME_STATE_CHANGE); - gm1packet.getIntegers().write(0, 3); - gm1packet.getFloat().write(0, 1F); - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet); - ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm3packet); - } catch (InvocationTargetException e) { - Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); + if (NOCLIPS.contains(player)) { + NOCLIPS.remove(player); + player.setGameMode(GameMode.CREATIVE); + } else { + player.setGameMode(GameMode.SPECTATOR); + ((CraftPlayer) player).getHandle().abilities.mayBuild = true; + ((CraftPlayer) player).getHandle().abilities.canInstantlyBuild = true; + PacketContainer gm3packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); + gm3packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); + List playerInfoActions = new ArrayList<>(); + playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, EnumWrappers.NativeGameMode.SPECTATOR, WrappedChatComponent.fromText(player.getDisplayName()))); + gm3packet.getPlayerInfoDataLists().write(0, playerInfoActions); + PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.GAME_STATE_CHANGE); + gm1packet.getIntegers().write(0, 3); + gm1packet.getFloat().write(0, 1F); + NOCLIPS.add(player); + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm3packet); + } catch (InvocationTargetException e) { + Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); + player.performCommand("noclip"); + } } } -} + + @EventHandler(ignoreCancelled = true) + public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) { + if (NOCLIPS.contains(event.getPlayer())) { + event.setCancelled(true); + } + } + + @EventHandler(ignoreCancelled = true) + public void onBlock(BlockCanBuildEvent event) { + if (NOCLIPS.contains(event.getPlayer())) { + event.setBuildable(true); + } + } +} \ No newline at end of file From c62ea3a33e3a697fdd37f1bd49a06668499932bc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 4 Jun 2021 00:04:35 +0200 Subject: [PATCH 3/9] Add NoClipCommand Inventory Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/other/NoClipCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b544a97f..789b0696 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -69,7 +69,7 @@ public class NoClipCommand extends SWCommand implements Listener { } } }); - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.USE_ITEM, PacketType.Play.Client.BLOCK_DIG) { + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.USE_ITEM, PacketType.Play.Client.BLOCK_DIG, PacketType.Play.Client.WINDOW_CLICK) { @Override public void onPacketReceiving(PacketEvent event) { if (NOCLIPS.contains(event.getPlayer())) { From 69f499afb6b845766188ea7edf0c48aa335c4d87 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 4 Jun 2021 00:22:43 +0200 Subject: [PATCH 4/9] Finalize Slot Command and some more touches on NoClipCommand Signed-off-by: Chaoscaot --- BauSystem_Main/src/BauSystem.properties | 3 +- .../features/other/NoClipCommand.java | 2 +- .../bausystem/features/other/SlotCommand.java | 84 +++++++++++++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 77abd12c..69c3f87a 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -218,7 +218,8 @@ LOADTIMER_SUMARY_STATS_FREQ = §7Belade Frequenz: §e{0}/m§8, §7Schuss Frequen # Other OTHER_ITEMS_TELEPORT_GUI-NAME = Teleportieren -OTHER_ITEMS_TELEPORT_PLAYER-OFFLINE = §cDer Spieler ist Offline +OTHER_ITEMS_TELEPORT_PLAYER-OFFLINE=§cDer Spieler ist Offline +OTHER_SLOT_INVALID_SLOT=§cInvalid Slot # Material MATERIAL_BLAST-RESISTANCE = §8- §eBlast Resistance§8: §7{0} 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 789b0696..bbd8e9de 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -69,7 +69,7 @@ public class NoClipCommand extends SWCommand implements Listener { } } }); - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.USE_ITEM, PacketType.Play.Client.BLOCK_DIG, PacketType.Play.Client.WINDOW_CLICK) { + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.USE_ITEM, PacketType.Play.Client.BLOCK_DIG, PacketType.Play.Client.WINDOW_CLICK, PacketType.Play.Client.SPECTATE) { @Override public void onPacketReceiving(PacketEvent event) { if (NOCLIPS.contains(event.getPlayer())) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java new file mode 100644 index 00000000..eaee813c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java @@ -0,0 +1,84 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.other; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.SWCommand; +import de.steamwar.command.SWCommandUtils; +import de.steamwar.command.TypeMapper; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.Arrays; + +@Linked(LinkageType.COMMAND) +public class SlotCommand extends SWCommand { + + protected SlotCommand() { + super("slot", "s"); + } + + @Register(help = true) + public void genericHelp(Player player, String... args) { + + } + + @Register + public void slotCommand(Player player, Integer slot) { + if (slot < 1 || slot > 9) { + BauSystem.MESSAGE.send("OTHER_SLOT_INVALID_SLOT", player); + return; + } + player.getInventory().setHeldItemSlot(slot - 1); + } + + @Register("pick") + public void eyedropBlock(Player player) { + Block block = player.getTargetBlockExact(6); + ItemStack itemStack; + if (block == null) { + itemStack = new ItemStack(Material.AIR); + } else { + itemStack = new ItemStack(block.getType()); + } + SWUtils.giveItemToPlayer(player, itemStack); + } + + @Register("drop") + public void dropBlock(Player player) { + player.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); + } + + @ClassMapper(value = Integer.class, local = true) + private TypeMapper integerTypeMapper() { + return SWCommandUtils.createMapper(s -> { + try { + return Integer.parseInt(s); + } catch (NumberFormatException e) { + return null; + } + }, (commandSender, s) -> Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9")); + } +} From 535d8f497b1d44b70f4648128285dc74e703d482 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 4 Jun 2021 00:25:49 +0200 Subject: [PATCH 5/9] Add Flying Signed-off-by: Chaoscaot --- .../steamwar/bausystem/features/other/NoClipCommand.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 bbd8e9de..592b1a55 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.PlayerToggleFlightEvent; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -121,4 +122,12 @@ public class NoClipCommand extends SWCommand implements Listener { event.setBuildable(true); } } + + @EventHandler(ignoreCancelled = true) + public void onPlayerToggleFlight(PlayerToggleFlightEvent event) { + if (NOCLIPS.contains(event.getPlayer())) { + event.setCancelled(true); + event.getPlayer().setFlying(true); + } + } } \ No newline at end of file From c6b6ce3abd7ec9cc98070c4ae47d5c0fad9bf5e6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 4 Jun 2021 11:16:33 +0200 Subject: [PATCH 6/9] Add NoClipCommand spectate Signed-off-by: yoyosource --- .../bausystem/features/other/NoClipCommand.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 592b1a55..be6d29d4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -70,7 +70,7 @@ public class NoClipCommand extends SWCommand implements Listener { } } }); - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.USE_ITEM, PacketType.Play.Client.BLOCK_DIG, PacketType.Play.Client.WINDOW_CLICK, PacketType.Play.Client.SPECTATE) { + ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.USE_ITEM, PacketType.Play.Client.BLOCK_DIG, PacketType.Play.Client.WINDOW_CLICK) { @Override public void onPacketReceiving(PacketEvent event) { if (NOCLIPS.contains(event.getPlayer())) { @@ -79,6 +79,14 @@ 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) From f897fad09f3a055311bdb06be7d34bb7c098d285 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 5 Jun 2021 17:02:12 +0200 Subject: [PATCH 7/9] Chenges Signed-off-by: Chaoscaot --- BauSystem_Main/src/BauSystem.properties | 32 +++++++++---------- .../features/other/NoClipCommand.java | 1 + .../bausystem/features/other/SlotCommand.java | 5 ++- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 69c3f87a..c63af658 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -209,25 +209,23 @@ LOADTIMER_SUMARY_TIMES_HEAD = §7Zeiten: §eSekunden §7(§eTicks§7) LOADTIMER_SUMARY_TIMES_START = §7 || §7Start! LOADTIMER_SUMARY_TIMES_ACTIVATION = §7 || Aktivierung: §e{0}s §7(§e{1}t§7) LOADTIMER_SUMARY_TIMES_IGNITION = §7 || Zündung: §e{0}s §7(§e{1}t§7) -LOADTIMER_SUMARY_TIMES_EXPLOSION = §7 || Explosion: §e{0}s §7(§e{1}t§7) -LOADTIMER_SUMARY_TIMES_LAST = §7\\/ -LOADTIMER_SUMARY_STATS_HEAD = §7Kanonen-Stats§8: -LOADTIMER_SUMARY_STATS_TNT = §7TNT: §e{0} -LOADTIMER_SUMARY_STATS_FREQ = §7Belade Frequenz: §e{0}/m§8, §7Schuss Frequenz: §e{1}/m - - +LOADTIMER_SUMARY_TIMES_EXPLOSION=§7 || Explosion: §e{0}s §7(§e{1}t§7) +LOADTIMER_SUMARY_TIMES_LAST=§7\\/ +LOADTIMER_SUMARY_STATS_HEAD=§7Kanonen-Stats§8: +LOADTIMER_SUMARY_STATS_TNT=§7TNT: §e{0} +LOADTIMER_SUMARY_STATS_FREQ=§7Belade Frequenz: §e{0}/m§8, §7Schuss Frequenz: §e{1}/m # Other -OTHER_ITEMS_TELEPORT_GUI-NAME = Teleportieren +OTHER_ITEMS_TELEPORT_GUI-NAME=Teleportieren OTHER_ITEMS_TELEPORT_PLAYER-OFFLINE=§cDer Spieler ist Offline OTHER_SLOT_INVALID_SLOT=§cInvalid Slot - +OTHER_NOCLIP_SLOT_INFO=§7Mit /slot kannst du den ausgewählten Slot ändern und einen anderen Block in den Slot nehmen. # Material -MATERIAL_BLAST-RESISTANCE = §8- §eBlast Resistance§8: §7{0} -MATERIAL_TNT_BREAKABLE = §8- §eZerstörbar durch TNT -MATERIAL_TNT_UNBREAKABLE = §8- §eNicht Zerstörbar durch TNT -MATERIAL_TRANSPARENT = §8- §eTransparenter Block -MATERIAL_SOLID = §8- §eSolider Block -MATERIAL_GRAVITY = §8- §eFallender Block -MATERIAL_OCCLUDING = §8- §eOccluding Block -MATERIAL_INTERACT-ABLE = §8- §eInterargierbarer Block +MATERIAL_BLAST-RESISTANCE=§8- §eBlast Resistance§8: §7{0} +MATERIAL_TNT_BREAKABLE=§8- §eZerstörbar durch TNT +MATERIAL_TNT_UNBREAKABLE=§8- §eNicht Zerstörbar durch TNT +MATERIAL_TRANSPARENT=§8- §eTransparenter Block +MATERIAL_SOLID=§8- §eSolider Block +MATERIAL_GRAVITY=§8- §eFallender Block +MATERIAL_OCCLUDING=§8- §eOccluding Block +MATERIAL_INTERACT-ABLE=§8- §eInterargierbarer Block MATERIAL_FLAMMABLE = §8- §eFlammbarer Block \ No newline at end of file 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..aed64ed6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -107,6 +107,7 @@ public class NoClipCommand extends SWCommand implements Listener { gm1packet.getIntegers().write(0, 3); gm1packet.getFloat().write(0, 1F); NOCLIPS.add(player); + BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player); try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet); ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm3packet); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java index eaee813c..30258004 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java @@ -59,10 +59,9 @@ public class SlotCommand extends SWCommand { Block block = player.getTargetBlockExact(6); ItemStack itemStack; if (block == null) { - itemStack = new ItemStack(Material.AIR); - } else { - itemStack = new ItemStack(block.getType()); + return; } + itemStack = new ItemStack(block.getType()); SWUtils.giveItemToPlayer(player, itemStack); } From 92b64d0f2c2a76f6be5837a38f113e9e299ebe7f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 5 Jun 2021 17:03:35 +0200 Subject: [PATCH 8/9] Chenges Signed-off-by: Chaoscaot --- .../de/steamwar/bausystem/features/other/SlotCommand.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java index 30258004..a741d763 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/SlotCommand.java @@ -40,11 +40,6 @@ public class SlotCommand extends SWCommand { super("slot", "s"); } - @Register(help = true) - public void genericHelp(Player player, String... args) { - - } - @Register public void slotCommand(Player player, Integer slot) { if (slot < 1 || slot > 9) { From 868de95898e8c5f909ab5e2815591086982cab2a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 5 Jun 2021 21:27:33 +0200 Subject: [PATCH 9/9] Fix NoClipCommand Signed-off-by: yoyosource --- .../features/other/NoClipCommand_15.java | 8 +++++--- .../features/other/KillAllCommand.java | 2 -- .../features/other/NoClipCommand.java | 20 +++++++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) 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