From 6cbdb837d029d3e4b932e453639e8b5d55ffdb90 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 21 Mar 2021 11:22:03 +0100 Subject: [PATCH 1/2] Add inspection option --- .../spectatesystem/PacketProcessor.java | 3 +- .../steamwar/spectatesystem/PlayerSetup.java | 4 +++ .../spectatesystem/SpectateSystem.java | 7 +++++ .../commands/InspectCommand.java | 29 +++++++++++++++++++ .../commands/ReplayCommand.java | 8 ++--- .../spectatesystem/listener/JoinListener.java | 12 ++++++++ .../listener/PlayerListener.java | 4 +++ .../steamwar/spectatesystem/util/Paster.java | 3 +- src/plugin.yml | 3 +- 9 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 src/de/steamwar/spectatesystem/commands/InspectCommand.java diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index b372e7b..f2a53ec 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -20,6 +20,7 @@ package de.steamwar.spectatesystem; import com.sk89q.worldedit.EditSession; +import de.steamwar.spectatesystem.commands.InspectCommand; import de.steamwar.spectatesystem.elements.*; import de.steamwar.spectatesystem.util.BlockTextCreator; import de.steamwar.spectatesystem.util.ColorConverter; @@ -203,7 +204,7 @@ class PacketProcessor { if(Config.ArenaMinX > x || Config.ArenaMaxX < x || Config.ArenaMinZ > z || Config.ArenaMaxZ < z) return; //Outside of the arena - if (Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { + if (!InspectCommand.inspecting && Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { blockState = Config.ObfuscateWith; } IBlockData blockData = Objects.requireNonNull(Block.REGISTRY_ID.fromId(blockState)); diff --git a/src/de/steamwar/spectatesystem/PlayerSetup.java b/src/de/steamwar/spectatesystem/PlayerSetup.java index 02d6a84..5c6a451 100644 --- a/src/de/steamwar/spectatesystem/PlayerSetup.java +++ b/src/de/steamwar/spectatesystem/PlayerSetup.java @@ -26,6 +26,7 @@ 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.spectatesystem.commands.InspectCommand; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -102,6 +103,9 @@ public class PlayerSetup { } } Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> { + if(InspectCommand.inspecting) + return; + PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); gm1packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); List playerInfoActions = new ArrayList<>(); diff --git a/src/de/steamwar/spectatesystem/SpectateSystem.java b/src/de/steamwar/spectatesystem/SpectateSystem.java index 76bc293..fbd45b2 100644 --- a/src/de/steamwar/spectatesystem/SpectateSystem.java +++ b/src/de/steamwar/spectatesystem/SpectateSystem.java @@ -19,6 +19,7 @@ package de.steamwar.spectatesystem; +import de.steamwar.spectatesystem.commands.InspectCommand; import de.steamwar.spectatesystem.commands.ReplayCommand; import de.steamwar.spectatesystem.elements.RScoreboard; import de.steamwar.spectatesystem.listener.PlayerListener; @@ -26,14 +27,19 @@ import de.steamwar.spectatesystem.listener.CancelListener; import de.steamwar.spectatesystem.listener.JoinListener; import de.steamwar.spectatesystem.listener.PlayerSeatListener; import de.steamwar.spectatesystem.util.WorldLoader; +import de.steamwar.sql.UserGroup; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import java.io.IOException; +import java.util.EnumSet; +import java.util.Set; import java.util.logging.Level; public class SpectateSystem extends JavaPlugin { + public static final Set allowedGroups = EnumSet.of(UserGroup.Admin, UserGroup.Developer, UserGroup.Moderator); + private static SpectateSystem instance; private static RScoreboard scoreboard; private ConnectionAcceptor acceptor; @@ -53,6 +59,7 @@ public class SpectateSystem extends JavaPlugin { } Bukkit.getPluginCommand("replay").setExecutor(new ReplayCommand()); + Bukkit.getPluginCommand("inspect").setExecutor(new InspectCommand()); WorldLoader.configureForceLoad(); } diff --git a/src/de/steamwar/spectatesystem/commands/InspectCommand.java b/src/de/steamwar/spectatesystem/commands/InspectCommand.java new file mode 100644 index 0000000..fc88afc --- /dev/null +++ b/src/de/steamwar/spectatesystem/commands/InspectCommand.java @@ -0,0 +1,29 @@ +package de.steamwar.spectatesystem.commands; + +import de.steamwar.spectatesystem.SpectateSystem; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class InspectCommand implements CommandExecutor { + + public static boolean inspecting = false; + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) { + if(sender instanceof Player){ + Player player = (Player) sender; + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(!SpectateSystem.allowedGroups.contains(user.getUserGroup())){ + player.sendMessage("§eSteam§8War» §cUnbekannter Befehl."); + return false; + } + } + + inspecting = !inspecting; + sender.sendMessage("Inspection: " + inspecting); + return false; + } +} diff --git a/src/de/steamwar/spectatesystem/commands/ReplayCommand.java b/src/de/steamwar/spectatesystem/commands/ReplayCommand.java index a0b6ed0..b0e4ed0 100644 --- a/src/de/steamwar/spectatesystem/commands/ReplayCommand.java +++ b/src/de/steamwar/spectatesystem/commands/ReplayCommand.java @@ -20,8 +20,8 @@ package de.steamwar.spectatesystem.commands; import de.steamwar.spectatesystem.FightfileConnection; +import de.steamwar.spectatesystem.SpectateSystem; import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserGroup; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -30,20 +30,16 @@ import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; -import java.util.EnumSet; -import java.util.Set; import java.util.logging.Level; public class ReplayCommand implements CommandExecutor { - private static final Set allowedGroups = EnumSet.of(UserGroup.Admin, UserGroup.Developer, UserGroup.Moderator); - @Override public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) { if(sender instanceof Player){ Player player = (Player) sender; SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if(!allowedGroups.contains(user.getUserGroup())){ + if(!SpectateSystem.allowedGroups.contains(user.getUserGroup())){ player.sendMessage("§eSteam§8War» §cUnbekannter Befehl."); return false; } diff --git a/src/de/steamwar/spectatesystem/listener/JoinListener.java b/src/de/steamwar/spectatesystem/listener/JoinListener.java index a29e611..5ecef40 100644 --- a/src/de/steamwar/spectatesystem/listener/JoinListener.java +++ b/src/de/steamwar/spectatesystem/listener/JoinListener.java @@ -23,7 +23,9 @@ import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.spectatesystem.Config; import de.steamwar.spectatesystem.PlayerSetup; import de.steamwar.spectatesystem.SpectateSystem; +import de.steamwar.spectatesystem.commands.InspectCommand; import de.steamwar.spectatesystem.elements.REntity; +import de.steamwar.sql.SteamwarUser; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; @@ -35,6 +37,16 @@ public class JoinListener extends BasicListener { public void onJoin(PlayerJoinEvent e){ e.setJoinMessage(null); Player player = e.getPlayer(); + + if(InspectCommand.inspecting){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(!SpectateSystem.allowedGroups.contains(user.getUserGroup())){ + player.sendMessage("§eSteam§8War» §cDerzeit ist das Zuschauen nicht gestattet."); + player.kickPlayer(null); + return; + } + } + player.teleport(Config.SpecSpawn); REntity.playerJoins(player); PlayerSetup.playerJoins(player); diff --git a/src/de/steamwar/spectatesystem/listener/PlayerListener.java b/src/de/steamwar/spectatesystem/listener/PlayerListener.java index c63b5cd..baf82e6 100644 --- a/src/de/steamwar/spectatesystem/listener/PlayerListener.java +++ b/src/de/steamwar/spectatesystem/listener/PlayerListener.java @@ -22,6 +22,7 @@ package de.steamwar.spectatesystem.listener; import de.steamwar.spectatesystem.Config; import de.steamwar.spectatesystem.PlayerSetup; import de.steamwar.spectatesystem.SpectateSystem; +import de.steamwar.spectatesystem.commands.InspectCommand; import de.steamwar.spectatesystem.util.Region; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; @@ -53,6 +54,9 @@ public class PlayerListener extends BasicListener { } private void checkMovementInArena(PlayerMoveEvent event, Location to){ + if(InspectCommand.inspecting) + return; + boolean inArenaY = to.getY() + 1.8 <= Config.upperArenaBorder; boolean inBlueArea = inArenaY && Region.isIn2DRange(to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic); boolean inRedArea = inArenaY && Region.isIn2DRange(to, Config.TeamRedCornerX, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic); diff --git a/src/de/steamwar/spectatesystem/util/Paster.java b/src/de/steamwar/spectatesystem/util/Paster.java index 06da440..350e76e 100644 --- a/src/de/steamwar/spectatesystem/util/Paster.java +++ b/src/de/steamwar/spectatesystem/util/Paster.java @@ -35,6 +35,7 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.spectatesystem.Config; +import de.steamwar.spectatesystem.commands.InspectCommand; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -90,7 +91,7 @@ public class Paster { for(int y = 0; y < clipboard.getDimensions().getY(); y++){ for(int z = 0; z < clipboard.getDimensions().getZ(); z++){ BlockVector3 blockPos = minimum.add(x, y, z); - if(Config.HiddenBlockTags.contains(BukkitAdapter.adapt(clipboard.getFullBlock(blockPos).getBlockType()).name())){ + if(!InspectCommand.inspecting && Config.HiddenBlockTags.contains(BukkitAdapter.adapt(clipboard.getFullBlock(blockPos).getBlockType()).name())){ try { clipboard.setBlock(blockPos, obfuscateWith); } catch (WorldEditException e) { diff --git a/src/plugin.yml b/src/plugin.yml index cb71967..10295c1 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -10,4 +10,5 @@ depend: - WorldEdit - ProtocolLib commands: - replay: \ No newline at end of file + replay: + inspect: From ccc1388cc3b7f8ef80bf74c8b986b4861e681ddc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 21 Mar 2021 11:27:01 +0100 Subject: [PATCH 2/2] Fix to login event --- .../spectatesystem/listener/JoinListener.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/spectatesystem/listener/JoinListener.java b/src/de/steamwar/spectatesystem/listener/JoinListener.java index 5ecef40..64715d6 100644 --- a/src/de/steamwar/spectatesystem/listener/JoinListener.java +++ b/src/de/steamwar/spectatesystem/listener/JoinListener.java @@ -29,23 +29,27 @@ import de.steamwar.sql.SteamwarUser; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; public class JoinListener extends BasicListener { @EventHandler - public void onJoin(PlayerJoinEvent e){ - e.setJoinMessage(null); + public void onLogin(PlayerLoginEvent e){ Player player = e.getPlayer(); if(InspectCommand.inspecting){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); if(!SpectateSystem.allowedGroups.contains(user.getUserGroup())){ - player.sendMessage("§eSteam§8War» §cDerzeit ist das Zuschauen nicht gestattet."); - player.kickPlayer(null); - return; + e.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "§eSteam§8War» §cDerzeit ist das Zuschauen nicht gestattet."); } } + } + + @EventHandler + public void onJoin(PlayerJoinEvent e){ + e.setJoinMessage(null); + Player player = e.getPlayer(); player.teleport(Config.SpecSpawn); REntity.playerJoins(player);