SteamWar/BauSystem2.0
Archiviert
12
0

Merge branch 'noclip'

Dieser Commit ist enthalten in:
yoyosource 2021-06-06 12:31:27 +02:00
Commit d6f0174e98
5 geänderte Dateien mit 294 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,53 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
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;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
@UtilityClass
public class NoClipCommand_15 {
private Field gameModeField;
public 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 void checkCache() throws NoSuchFieldException {
if (gameModeField == null) {
gameModeField = PlayerInteractManager.class.getDeclaredField("gamemode");
gameModeField.setAccessible(true);
}
}
}

Datei anzeigen

@ -214,12 +214,11 @@ 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_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

Datei anzeigen

@ -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)

Datei anzeigen

@ -0,0 +1,146 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
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 org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
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)
@Linked(LinkageType.LISTENER)
public class NoClipCommand extends SWCommand implements Listener {
private static final List<Player> NOCLIPS = new ArrayList<>();
private static final Map<Player, Long> 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, PacketType.Play.Client.WINDOW_CLICK) {
@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) {
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<PlayerInfoData> 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);
BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", 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);
}
}
@EventHandler(ignoreCancelled = true)
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
if (NOCLIPS.contains(event.getPlayer())) {
event.setCancelled(true);
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);
}
}
}

Datei anzeigen

@ -0,0 +1,78 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
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
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) {
return;
}
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<Integer> 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"));
}
}