From ea3aad3bd2734e42ef1d88f2764e00d3687d09f4 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 28 Aug 2026 19:51:31 +0200 Subject: [PATCH] Initial FightSWCommand --- .../de/steamwar/fightsystem/ArenaMode.java | 1 + .../de/steamwar/fightsystem/FightSystem.java | 3 - .../fightsystem/commands/AkCommand.java | 26 ++--- .../fightsystem/commands/FightSWCommand.java | 95 +++++++++++++++++++ .../fightsystem/commands/GamemodeCommand.java | 84 ++-------------- .../fightsystem/commands/InfoCommand.java | 22 ++--- .../fightsystem/commands/KitCommand.java | 27 ++---- .../fightsystem/commands/LeaveCommand.java | 18 +--- .../commands/LockschemCommand.java | 30 ++---- .../fightsystem/commands/ReadyCommand.java | 18 +--- .../fightsystem/commands/RemoveCommand.java | 26 +---- .../fightsystem/commands/RequestsCommand.java | 21 ++-- .../fightsystem/commands/SkipCommand.java | 18 +--- .../fightsystem/commands/StateCommand.java | 19 +--- .../fightsystem/commands/TBCommand.java | 16 +--- .../fightsystem/commands/TPSWarpCommand.java | 24 +---- .../fightsystem/commands/TechareaCommand.java | 39 ++++---- .../commands/TechhiderbugCommand.java | 16 ++-- .../fightsystem/commands/WGCommand.java | 16 +--- .../fightsystem/commands/WinCommand.java | 39 +++----- .../steamwar/fightsystem/listener/Check.java | 4 + .../fightsystem/states/FightState.java | 3 + .../states/StateDependentCommand.java | 58 ----------- FightSystem/FightSystem_Core/src/plugin.yml | 20 +--- FightSystem/build.gradle.kts | 12 +++ 25 files changed, 239 insertions(+), 416 deletions(-) create mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/FightSWCommand.java delete mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCommand.java diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java index e65ce94c..f430ed72 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java @@ -39,6 +39,7 @@ public enum ArenaMode { public static final Set Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK)); public static final Set Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE)); public static final Set Replay = Collections.unmodifiableSet(EnumSet.of(REPLAY, TEST)); + public static final Set TestOrReferee = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, EVENT)); public static final Set AntiReplay = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(REPLAY))); public static final Set AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK))); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 06ceac41..ebfbf7c1 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -22,7 +22,6 @@ package de.steamwar.fightsystem; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.core.WorldEditRendererCUIEditor; -import de.steamwar.fightsystem.commands.TechareaCommand; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.listener.ClickAnalyzer; @@ -127,8 +126,6 @@ public class FightSystem extends JavaPlugin { if (checkSchematicNode.isPrepared()) { Fight.getRedTeam().setSchem(checkSchematicNode, NodeData.getRevisions(checkSchematicNode) - 1); } - - new TechareaCommand(); } else if (Config.mode == ArenaMode.PREPARE) { Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID)); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/AkCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/AkCommand.java index b1ffede2..e1209976 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/AkCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/AkCommand.java @@ -24,35 +24,25 @@ import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Kit; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserPerm; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @Linked -public class AkCommand implements CommandExecutor { +public class AkCommand extends FightSWCommand { public AkCommand() { - new StateDependentCommand(ArenaMode.Test, FightState.All, "ak", this); + super(ArenaMode.Test, FightState.All, "ak"); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - return false; - } - Player player = (Player) sender; - if (!player.isOp()) return false; + protected boolean hasPerm(Player player, SteamwarUser user) { + return player.isOp() && user.hasPerm(UserPerm.ADMINISTRATION) && Core.getInstance() != FightSystem.getPlugin(); + } - if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.ADMINISTRATION) && Core.getInstance() != FightSystem.getPlugin()) { - return false; - } - - Kit.createKit(args[0], player); - return false; + @Register + public void run(@Validator Player player, String name) { + Kit.createKit(name, player); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/FightSWCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/FightSWCommand.java new file mode 100644 index 00000000..c9563d9d --- /dev/null +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/FightSWCommand.java @@ -0,0 +1,95 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2026 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.fightsystem.commands; + +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandSendEvent; + +import java.util.Set; + +public abstract class FightSWCommand extends SWCommand implements Listener { + + private final String command; + private final String[] aliases; + + protected FightSWCommand(Set mode, Set states, String command) { + super(command); + this.command = command; + this.aliases = new String[0]; + stateDependant(mode, states); + } + + protected FightSWCommand(Set mode, Set states, String command, String... aliases) { + super(command, aliases); + this.command = command; + this.aliases = aliases; + stateDependant(mode, states); + } + + private void stateDependant(Set mode, Set states) { + FightSWCommand.this.unregister(); + new StateDependent(mode, states) { + @Override + public void enable() { + System.out.println("--- Enable: " + command); + FightSWCommand.this.register(); + } + + @Override + public void disable() { + System.out.println("--- Disable: " + command); + FightSWCommand.this.unregister(); + } + }.register(); + } + + public static void postFightStateChange() { + for (Player player : Bukkit.getOnlinePlayers()) { + player.updateCommands(); + } + } + + protected boolean hasPerm(Player player, SteamwarUser user) { + return true; + } + + @EventHandler(ignoreCancelled = true) + public final void onPlayerCommandSend(PlayerCommandSendEvent event) { + if (hasPerm(event.getPlayer(), SteamwarUser.get(event.getPlayer().getUniqueId()))) return; + event.getCommands().remove(command); + for (String alias : aliases) { + event.getCommands().remove(alias); + } + } + + @ClassValidator(value = Player.class, local = true) + public final TypeValidator permissionCheck() { + return (sender, value, messageSender) -> hasPerm(value, SteamwarUser.get(value.getUniqueId())); + } +} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java index 1ac59065..67eabdde 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java @@ -19,92 +19,28 @@ package de.steamwar.fightsystem.commands; -import com.google.common.collect.ImmutableList; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.linkage.Linked; -import net.md_5.bungee.api.ChatMessageType; -import org.bukkit.Bukkit; +import de.steamwar.sql.SteamwarUser; import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.defaults.BukkitCommand; -import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Player; -import org.bukkit.util.StringUtil; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; @Linked -public class GamemodeCommand extends BukkitCommand { - - private static final List GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival", - "spectator"); +public class GamemodeCommand extends FightSWCommand { public GamemodeCommand() { - super("gamemode"); - List aliases = new ArrayList<>(); - aliases.add("gm"); - this.setAliases(aliases); - - Map knownCommands = ((CraftServer) Bukkit.getServer()).getCommandMap().getKnownCommands(); - knownCommands.remove("gamemode"); - Commands.injectCommand(this); + super(ArenaMode.TestOrReferee, FightState.All, "gamemode", "gm"); } @Override - public boolean execute(CommandSender sender, String currentAlias, String[] args) { - if (!(sender instanceof Player)) { - return false; - } else if (args.length == 0) { - FightSystem.getMessage().sendPrefixless("GAMEMODE_HELP", sender); - return false; - } - - Player p = (Player) sender; - - if (!(Config.test() || Config.isReferee(p))) { - FightSystem.getMessage().sendPrefixless("GAMEMODE_NOT_ALLOWED", p, ChatMessageType.ACTION_BAR); - return false; - } - - GameMode mode = createMode(args[0]); - - if (mode == null) { - FightSystem.getMessage().sendPrefixless("GAMEMODE_UNKNOWN", p, ChatMessageType.ACTION_BAR, args[0]); - return false; - } - - p.setGameMode(mode); - return true; + protected boolean hasPerm(Player player, SteamwarUser user) { + return Config.test() || Config.isReferee(player); } - @SuppressWarnings("deprecation") - private GameMode createMode(String modeArg) { - try { - return GameMode.getByValue(Integer.parseInt(modeArg)); - } catch (NumberFormatException ignored) { - if ((modeArg.equalsIgnoreCase("creative")) || (modeArg.equalsIgnoreCase("c"))) { - return GameMode.CREATIVE; - } else if ((modeArg.equalsIgnoreCase("adventure")) || (modeArg.equalsIgnoreCase("a"))) { - return GameMode.ADVENTURE; - } else if ((modeArg.equalsIgnoreCase("spectator")) || (modeArg.equalsIgnoreCase("sp"))) { - return GameMode.SPECTATOR; - } else if ((modeArg.equalsIgnoreCase("survival")) || (modeArg.equalsIgnoreCase("s"))) { - return GameMode.SURVIVAL; - } - } - return null; + @Register(description = "GAMEMODE_HELP") + public void execute(@Validator Player player, GameMode gameMode) { + player.setGameMode(gameMode); } - - @Override - public List tabComplete(CommandSender sender, String alias, String[] args) { - if (args.length == 1) { - return StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES, new ArrayList<>(GAMEMODE_NAMES.size())); - } - return ImmutableList.of(); - } - } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/InfoCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/InfoCommand.java index 4fc8e96c..5b3717eb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/InfoCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/InfoCommand.java @@ -20,34 +20,31 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.listener.Check; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserPerm; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @Linked -public class InfoCommand implements CommandExecutor { +public class InfoCommand extends FightSWCommand { public InfoCommand() { - new StateDependentCommand(ArenaMode.All, FightState.All, "fightinfo", this); + super(ArenaMode.All, FightState.All, "fightinfo"); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) return false; - - Player player = (Player) sender; - if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.CHECK)) return false; + protected boolean hasPerm(Player player, SteamwarUser user) { + return Check.checkPermission(user, Config.GameModeConfig); + } + @Register + public void run(@Validator Player player) { for (FightTeam team : Fight.teams()) { if (!team.isLeaderless()) { FightSystem.getMessage().send("INFO_LEADER", player, team.getColoredName(), team.getLeader().getEntity().getName()); @@ -58,6 +55,5 @@ public class InfoCommand implements CommandExecutor { FightSystem.getMessage().send("INFO_SCHEMATIC", player, team.getColoredName(), schematic.getName(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getRank()); } } - return false; } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/KitCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/KitCommand.java index bbbe07cb..0d667596 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/KitCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/KitCommand.java @@ -21,32 +21,23 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @Linked -public class KitCommand implements CommandExecutor { +public class KitCommand extends FightSWCommand { public KitCommand() { - new StateDependentCommand(ArenaMode.AntiReplay, FightState.Setup, "kit", this); + super(ArenaMode.AntiReplay, FightState.Setup, "kit"); } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - return false; - } - Player player = (Player) sender; + @Register + public void execute(Player player) { + GUI.kitSelection(player, ""); + } - if (args.length != 1) { - GUI.kitSelection(player, ""); - } else { - Commands.kit(player, args[0]); - } - return false; + @Register + public void execute(Player player, String query) { // TODO: TabCompletion of Kit Names! + GUI.kitSelection(player, query); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaveCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaveCommand.java index 8d63e060..bd493e42 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaveCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaveCommand.java @@ -21,28 +21,18 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @Linked -public class LeaveCommand implements CommandExecutor { +public class LeaveCommand extends FightSWCommand { public LeaveCommand() { - new StateDependentCommand(ArenaMode.AntiReplay, FightState.Setup, "leave", this); + super(ArenaMode.AntiReplay, FightState.Setup, "leave"); } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - return false; - } - Player player = (Player) sender; - + @Register + public void execute(Player player) { Commands.leaveTeam(player); - return false; } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java index 4487b30f..eb1633d0 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockschemCommand.java @@ -20,52 +20,42 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.listener.Check; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserPerm; import net.md_5.bungee.api.ChatMessageType; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @Linked -public class LockschemCommand implements CommandExecutor { +public class LockschemCommand extends FightSWCommand { public LockschemCommand() { - new StateDependentCommand(ArenaMode.All, FightState.Schem, "lockschem", this); + super(ArenaMode.All, FightState.Schem, "lockschem"); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) return false; - Player player = (Player) sender; + protected boolean hasPerm(Player player, SteamwarUser user) { + return Check.checkPermission(user, Config.GameModeConfig); + } - if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.CHECK)) return false; - - if (args.length != 1) { - FightSystem.getMessage().sendPrefixless("LOCKSCHEM_HELP", player); - return false; - } - - String teamName = args[0]; + @Register(description = "LOCKSCHEM_HELP") + public void execute(@Validator Player player, String teamName) { FightTeam fightTeam = Fight.getTeamByName(teamName); if (fightTeam == null) { FightSystem.getMessage().sendPrefixless("UNKNOWN_TEAM", player, ChatMessageType.ACTION_BAR); - return false; + return; } SchematicNode.getSchematicNode(fightTeam.getSchematic()).setSchemtype(SchematicType.Normal); FightSystem.getMessage().sendPrefixless("LOCKSCHEM_LOCKED", player, ChatMessageType.ACTION_BAR); fightTeam.broadcastSystem("LOCKSCHEM_LOCKED_BY", player.getName()); - return false; } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/ReadyCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/ReadyCommand.java index 32386639..8d3d1d9f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/ReadyCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/ReadyCommand.java @@ -21,28 +21,18 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @Linked -public class ReadyCommand implements CommandExecutor { +public class ReadyCommand extends FightSWCommand { public ReadyCommand() { - new StateDependentCommand(ArenaMode.AntiPrepare, FightState.PostSchemSetup, "ready", this); + super(ArenaMode.AntiPrepare, FightState.PostSchemSetup, "ready"); } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - return false; - } - Player player = (Player) sender; - + @Register + public void execute(Player player) { Commands.toggleReady(player); - return false; } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RemoveCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RemoveCommand.java index 60c08339..31fd0bcf 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RemoveCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RemoveCommand.java @@ -20,35 +20,19 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @Linked -public class RemoveCommand implements CommandExecutor { +public class RemoveCommand extends FightSWCommand { public RemoveCommand() { - new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "remove", this); + super(ArenaMode.VariableTeams, FightState.Setup, "remove"); } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - return false; - } - Player player = (Player) sender; - - if (args.length != 1) { - FightSystem.getMessage().sendPrefixless("REMOVE_HELP", player); - return false; - } - - Commands.kick(player, args[0]); - return false; + @Register(description = "REMOVE_HELP") + public void execute(Player player, Player teamMember) { + Commands.kick(player, teamMember.getName()); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java index 36cb8fba..9f66106e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java @@ -26,37 +26,28 @@ import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.JoinRequest; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.function.BiConsumer; @Linked -public class RequestsCommand implements CommandExecutor { +public class RequestsCommand extends FightSWCommand { public RequestsCommand() { - new StateDependentCommand(ArenaMode.VariableTeams, FightState.AntiSpectate, "request", this); - new StateDependentCommand(ArenaMode.VariableTeams, FightState.AntiSpectate, "requests", this); + super(ArenaMode.VariableTeams, FightState.AntiSpectate, "request", "requests"); } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) return false; - Player player = (Player) sender; + @Register + public void execute(Player player) { FightPlayer fp = Fight.getFightPlayer(player); if (fp == null || !(fp.isLeader() || fp.isLiving())) { GUI.joinRequest(player); - return false; + return; } - if (Commands.checkGetLeader(player) == null) return false; - + if (Commands.checkGetLeader(player) == null) return; GUI.chooseJoinRequests(player); - return false; } public static void onJoinRequest(Player player, JoinRequest request, BiConsumer handleJoinRequest) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/SkipCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/SkipCommand.java index 3fef2cb5..90b20a70 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/SkipCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/SkipCommand.java @@ -24,32 +24,22 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.record.PacketProcessor; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @Linked -public class SkipCommand implements CommandExecutor { +public class SkipCommand extends FightSWCommand { public SkipCommand() { - new StateDependentCommand(ArenaMode.AntiPrepare, ArenaMode.Replay.contains(Config.mode) ? FightState.All : FightState.TeamFix, "skip", this); + super(ArenaMode.AntiPrepare, ArenaMode.Replay.contains(Config.mode) ? FightState.All : FightState.TeamFix, "skip"); } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - return false; - } - Player player = (Player) sender; - + @Register + public void execute(Player player) { if (PacketProcessor.isReplaying() && player.getUniqueId().equals(Fight.getBlueTeam().getDesignatedLeader())) { PacketProcessor.currentReplay().skipToSubtitle(); } else { Commands.toggleSkip(player); } - return false; } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/StateCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/StateCommand.java index 338dcd5d..d23b0f85 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/StateCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/StateCommand.java @@ -21,27 +21,18 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @Linked -public class StateCommand implements CommandExecutor { +public class StateCommand extends FightSWCommand { public StateCommand() { - new StateDependentCommand(ArenaMode.Test, FightState.All, "state", this); + super(ArenaMode.Test, FightState.All, "state"); } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - return false; - } - - GUI.state((Player) sender); - return false; + @Register + public void execute(Player player) { + GUI.state(player); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TBCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TBCommand.java index 2e627e4a..958ff383 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TBCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TBCommand.java @@ -22,26 +22,18 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @Linked -public class TBCommand implements CommandExecutor { +public class TBCommand extends FightSWCommand { public TBCommand() { - new StateDependentCommand(ArenaMode.Check, FightState.All, "resettb", this); + super(ArenaMode.Check, FightState.All, "resettb"); } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - return false; - } + @Register + public void execute(Player player) { Fight.getRedTeam().pasteSchem(); - return false; } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TPSWarpCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TPSWarpCommand.java index 6ec55acd..e7f6173c 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TPSWarpCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TPSWarpCommand.java @@ -20,34 +20,20 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; import net.minecraft.server.MinecraftServer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; @Linked -public class TPSWarpCommand implements CommandExecutor { +public class TPSWarpCommand extends FightSWCommand { public TPSWarpCommand() { - new StateDependentCommand(ArenaMode.Prepare, FightState.PostSchemSetup, "tpswarp", this); - new StateDependentCommand(ArenaMode.Prepare, FightState.PostSchemSetup, "tpslimit", this); + super(ArenaMode.Prepare, FightState.PostSchemSetup, "tpswarp", "tpslimit"); } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - float tps; - try { - tps = Float.parseFloat(args[0]); - } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { - FightSystem.getMessage().send("TPSWARP_HELP", sender); - return false; - } - + @Register(description = "TPSWARP_HELP") + public void execute(Player player, float tps) { MinecraftServer.getServer().tickRateManager().setTickRate(tps); - FightSystem.getMessage().broadcastActionbar("TPSWARP_SET", tps); - return false; } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java index 880e1843..145f9271 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechareaCommand.java @@ -19,42 +19,39 @@ package de.steamwar.fightsystem.commands; -import de.steamwar.command.SWCommand; import de.steamwar.entity.CWireframe; import de.steamwar.entity.REntityServer; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; -import org.bukkit.Bukkit; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.OneShotStateDependent; +import de.steamwar.linkage.Linked; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class TechareaCommand extends SWCommand { - private final Map servers = new HashMap<>(); +@Linked +public class TechareaCommand extends FightSWCommand { + private REntityServer entityServer = new REntityServer(); public TechareaCommand() { - super("techarea"); - - Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> servers.forEach((uuid, rEntityServer) -> rEntityServer.tick()), 2, 2); - } - - @Register - public void genericCommand(Player player) { - if (servers.containsKey(player.getUniqueId())) { - servers.get(player.getUniqueId()).close(); - } else { + super(ArenaMode.Check, FightState.All, "techarea"); + new OneShotStateDependent(ArenaMode.Check, FightState.All, () -> { + if (!entityServer.getEntities().isEmpty()) return; REntityServer server = new REntityServer(); CWireframe wireframe = new CWireframe(server); wireframe.setPos1(Config.BlueInsetRegion.getMinLocation(Config.world)); wireframe.setPos2(Config.BlueInsetRegion.getMaxLocation(Config.world).subtract(1, 1, 1)); wireframe.setBlock(Material.RED_CONCRETE.createBlockData()); + }); + } - server.addPlayer(player); - servers.put(player.getUniqueId(), server); + @Register + public void genericCommand(Player player) { + if (entityServer.getPlayers().contains(player)) { + entityServer.removePlayer(player); + } else { + entityServer.addPlayer(player); } } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechhiderbugCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechhiderbugCommand.java index 6e89d727..5527176b 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechhiderbugCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/TechhiderbugCommand.java @@ -25,27 +25,24 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; import de.steamwar.sql.SWException; import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.io.StringWriter; import java.util.Arrays; import java.util.logging.Level; @Linked -public class TechhiderbugCommand implements CommandExecutor { +public class TechhiderbugCommand extends FightSWCommand { public TechhiderbugCommand() { - new StateDependentCommand(ArenaMode.All, FightState.All, "techhiderbug", this); + super(ArenaMode.All, FightState.All, "techhiderbug"); } - @Override - public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) { + @Register + public void execute(Player player, String... args) { StringWriter writer = new StringWriter(); try { @@ -76,7 +73,6 @@ public class TechhiderbugCommand implements CommandExecutor { Bukkit.getLogger().log(Level.SEVERE, "Error while generating bug report", e); } - SWException.log("Techhider-Bug reported by " + sender.getName() + ": " + Arrays.toString(args), writer.toString()); - return false; + SWException.log("Techhider-Bug reported by " + player.getName() + ": " + Arrays.toString(args), writer.toString()); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java index c88ae122..5be6ea6f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WGCommand.java @@ -23,28 +23,20 @@ import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightWorld; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @Linked -public class WGCommand implements CommandExecutor { +public class WGCommand extends FightSWCommand { public WGCommand() { - new StateDependentCommand(ArenaMode.Check, FightState.All, "resetwg", this); + super(ArenaMode.Check, FightState.All, "resetwg"); } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - return false; - } + @Register + public void execute(Player player) { FightWorld.resetWorld(); Fight.getBlueTeam().pasteSchem(); Fight.getRedTeam().pasteSchem(); - return false; } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java index e928faf4..945482fb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java @@ -25,49 +25,34 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; import de.steamwar.linkage.Linked; -import net.md_5.bungee.api.ChatMessageType; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; +import de.steamwar.sql.SteamwarUser; import org.bukkit.entity.Player; @Linked -public class WinCommand implements CommandExecutor { +public class WinCommand extends FightSWCommand { public WinCommand() { - new StateDependentCommand(ArenaMode.Event, FightState.Ingame, "win", this); + super(ArenaMode.Event, FightState.Ingame, "win"); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - return false; - } - Player p = (Player) sender; + protected boolean hasPerm(Player player, SteamwarUser user) { + return Config.isReferee(player); + } - if (!Config.isReferee(p)) { - FightSystem.getMessage().sendPrefixless("NOT_FIGHTLEADER", p, ChatMessageType.ACTION_BAR); - return false; - } - - if (args.length == 0) { - FightSystem.getMessage().sendPrefixless("WIN_HELP", p); - return false; - } - - if (args[0].equalsIgnoreCase("tie")) { + @Register + public void execute(@Validator Player player, String teamName) { + if (teamName.equalsIgnoreCase("tie")) { FightSystem.setSpectateState(null, "Referee", "WIN_FIGHTLEADER"); - return false; + return; } for (FightTeam team : Fight.teams()) { - if (args[0].equalsIgnoreCase(team.getName())) { + if (teamName.equalsIgnoreCase(team.getName())) { FightSystem.setSpectateState(team, "Referee", "WIN_FIGHTLEADER"); - return false; + return; } } - return false; } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Check.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Check.java index fc724087..f8ab148a 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Check.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Check.java @@ -51,6 +51,10 @@ public class Check implements Listener { .findFirst() .orElse(null); if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults(); + return checkPermission(user, gameModeConfig); + } + + public static boolean checkPermission(SteamwarUser user, GameModeConfig gameModeConfig) { if (user.hasPerm(UserPerm.ADMINISTRATION)) return true; if (gameModeConfig.Checkers.isEmpty() && user.hasPerm(UserPerm.CHECK)) return true; return gameModeConfig.Checkers.contains(user.getId()); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/FightState.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/FightState.java index c2fe5790..ee132339 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/FightState.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/FightState.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.states; +import de.steamwar.fightsystem.commands.FightSWCommand; import lombok.Getter; import java.util.*; @@ -62,6 +63,7 @@ public enum FightState { } public static void setFightState(FightState state) { + if (fightState.equals(state)) return; fightState = state; for (Map.Entry feature : stateDependentFeatures.entrySet()) { @@ -77,6 +79,7 @@ public enum FightState { feature.setValue(false); } } + FightSWCommand.postFightStateChange(); } public static boolean setup() { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCommand.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCommand.java deleted file mode 100644 index 53ea244a..00000000 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/states/StateDependentCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2025 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.fightsystem.states; - -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.FightSystem; -import net.md_5.bungee.api.ChatMessageType; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.PluginCommand; - -import java.util.Set; - -public class StateDependentCommand extends StateDependent { - - private static final CommandExecutor unavailable = (sender, cmd, s, strings) -> { - FightSystem.getMessage().sendPrefixless("COMMAND_CURRENTLY_UNAVAILABLE", sender, ChatMessageType.ACTION_BAR); - return false; - }; - - private final PluginCommand command; - private final CommandExecutor executor; - - public StateDependentCommand(Set mode, Set states, String name, CommandExecutor executor) { - super(mode, states); - this.executor = executor; - this.command = FightSystem.getPlugin().getCommand(name); - assert command != null; - disable(); - register(); - } - - @Override - public void enable() { - command.setExecutor(executor); - } - - @Override - public void disable() { - command.setExecutor(unavailable); - } -} diff --git a/FightSystem/FightSystem_Core/src/plugin.yml b/FightSystem/FightSystem_Core/src/plugin.yml index c2a8393b..56035ab1 100644 --- a/FightSystem/FightSystem_Core/src/plugin.yml +++ b/FightSystem/FightSystem_Core/src/plugin.yml @@ -10,22 +10,4 @@ depend: - WorldEdit api-version: "1.13" -commands: - ak: - request: - requests: - fightinfo: - leave: - ready: - kit: - remove: - lockschem: - state: - skip: - win: - resetwg: - resettb: - tpslimit: - tpswarp: - techhiderbug: - unrank: \ No newline at end of file +commands: \ No newline at end of file diff --git a/FightSystem/build.gradle.kts b/FightSystem/build.gradle.kts index 7079e0f1..cc5a3957 100644 --- a/FightSystem/build.gradle.kts +++ b/FightSystem/build.gradle.kts @@ -53,3 +53,15 @@ tasks.register("WarGear21") { config = "WarGear21.yml" jar = "/jars/paper-1.21.6.jar" } + +tasks.register("WarShip21") { + group = "run" + description = "Run a WarShip 1.21 Fight Server" + dependsOn(":SpigotCore:shadowJar") + dependsOn(":FightSystem:shadowJar") + dependsOn(":KotlinCore:shadowJar") + template = "WarShip21" + worldName = "arenas/Artic" + config = "WarShip21.yml" + jar = "/jars/paper-1.21.6.jar" +}