From 4a9f3c3b53d052b2c2dad39562cb61a058717091 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 1 Jun 2021 19:22:51 +0200 Subject: [PATCH] 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); + } + } +}