From 40c1e13435b5cb26fdc7a9161bb477813a3c021c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 27 Dec 2021 14:23:07 +0100 Subject: [PATCH] Update TraceCommand Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 + .../features/tracer/TraceCommand.java | 123 ++++++------------ 2 files changed, 40 insertions(+), 84 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 4ad139fb..ee2cac0f 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -666,6 +666,7 @@ TRACE_MESSAGE_HIDE = §cAlle TNT-Positionen ausgeblendet TRACE_MESSAGE_DISALLOWED = §cDu darfst hier nicht den TNT-Tracer nutzen TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen +TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Startet eine einzelne Aufnahme aller TNT-Positionen TRACE_COMMAND_HELP_STOP = §8/§etrace stop §8- §7Stoppt den TNT-Tracer TRACE_COMMAND_HELP_AUTO = §8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart TRACE_COMMAND_HELP_SHOW_GUI = §8/§etrace show gui §8- §7Zeigt die Trace show gui diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index 882d300e..d627af28 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -34,8 +34,7 @@ import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.shared.ShowMode; import de.steamwar.bausystem.utils.ListChatView; -import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeMapper; +import de.steamwar.command.*; import lombok.AllArgsConstructor; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; @@ -46,7 +45,6 @@ import org.bukkit.entity.Player; import java.util.*; import java.util.function.BiFunction; -import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -105,35 +103,14 @@ public class TraceCommand extends SWCommand { }; } - @Register(help = true) - public void genericHelp(Player p, String... args) { - BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_START", p); - BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_STOP", p); - BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_AUTO", p); - BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_SHOW_GUI", p); - BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_SHOW", p); - BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_HIDE", p); - BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_DELETE", p); - BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_LIST", p); - BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_GUI", p); - } - - @Register({"gui"}) - public void guiCommand(Player p) { - if (!permissionCheck(p)) return; + @Register(value = {"gui"}, description = "TRACE_COMMAND_HELP_GUI") + public void guiCommand(@Guard Player p) { TraceGui.openGui(p); } - @Register({"record", "list"}) - @Register({"list"}) - public void listCommand(Player p) { - listCommand(p, 0); - } - - @Register(value = {"record", "list"}, noTabComplete = true) - @Register(value = {"list"}, noTabComplete = true) - public void listCommand(Player player, int page) { - if (!permissionCheck(player)) return; + @Register(value = {"record", "list"}) + @Register(value = {"list"}, description = "TRACE_COMMAND_HELP_LIST") + public void listCommand(@Guard Player player, @OptionalValue("0") int page) { ListChatView.chatView(player, StoredRecords.getRecords(), page, record -> { TextComponent component = new TextComponent(); component.setText(BauSystem.MESSAGE.parse("TRACE_RECORD_LIST_ELEMENT", player, record.size())); @@ -156,20 +133,13 @@ public class TraceCommand extends SWCommand { } @Register(value = {"record", "delete"}, noTabComplete = true) - public void recordDelete(Player p, int id) { - if (!permissionCheck(p)) return; + public void recordDelete(@Guard Player p, int id) { StoredRecords.remove(id); BauSystem.MESSAGE.send("TRACE_RECORD_DELETE", p); } @Register(value = "record", noTabComplete = true) - public void recordList(Player p, int record) { - recordList(p, record, 0); - } - - @Register(value = "record", noTabComplete = true) - public void recordList(Player player, int recordID, int page) { - if (!permissionCheck(player)) return; + public void recordList(@Guard Player player, int recordID, @OptionalValue("0") int page) { Record traceRecord = StoredRecords.get(recordID); if (traceRecord == null) { BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); @@ -197,8 +167,7 @@ public class TraceCommand extends SWCommand { } @Register(value = {"record", "tnt", "delete"}, noTabComplete = true) - public void deleteRecordTNT(Player player, int recordID, int tntID) { - if (!permissionCheck(player)) return; + public void deleteRecordTNT(@Guard Player player, int recordID, int tntID) { Record record = StoredRecords.get(recordID); if (record == null) { BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); @@ -209,13 +178,7 @@ public class TraceCommand extends SWCommand { } @Register(value = "record", noTabComplete = true) - public void recordTNTPositions(Player player, int recordID, @StaticValue("tnt") String tnt, int tntID) { - recordTNTPositions(player, recordID, tnt, tntID, 0); - } - - @Register(value = "record", noTabComplete = true) - public void recordTNTPositions(Player player, int recordID, @StaticValue("tnt") String tnt, int tntID, int page) { - if (!permissionCheck(player)) return; + public void recordTNTPositions(@Guard Player player, int recordID, @StaticValue("tnt") String tnt, int tntID, @OptionalValue("0") int page) { Record record = StoredRecords.get(recordID); if (record == null) { BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); @@ -242,8 +205,7 @@ public class TraceCommand extends SWCommand { } @Register(value = "record", noTabComplete = true) - public void recordTNTPositions(Player player, int recordID, @StaticValue("tnt") String tnt, int tntID, @StaticValue("fuse") String fuse, int fuseTicks) { - if (!permissionCheck(player)) return; + public void recordTNTPositions(@Guard Player player, int recordID, @StaticValue("tnt") String tnt, int tntID, @StaticValue("fuse") String fuse, int fuseTicks) { Record record = StoredRecords.get(recordID); if (record == null) { BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); @@ -266,50 +228,40 @@ public class TraceCommand extends SWCommand { BauSystem.MESSAGE.sendPrefixless("TRACE_CHAT_POSITION_EXPLODED", player, tntPosition.isExploded()); } - @Register({"start"}) - public void startCommand(Player p) { - if (!permissionCheck(p)) return; + @Register(value = {"start"}, description = "TRACE_COMMAND_HELP_START") + public void startCommand(@Guard Player p) { RecordStateMachine.commandStart(); BauSystem.MESSAGE.send("TRACE_MESSAGE_START", p); } - @Register({"single"}) - public void singleCommand(Player p) { - if (!permissionCheck(p)) return; + @Register(value = {"single"}, description = "TRACE_COMMAND_HELP_SINGLE") + public void singleCommand(@Guard Player p) { RecordStateMachine.commandSingle(); BauSystem.MESSAGE.send("TRACE_MESSAGE_SINGLE", p); } - @Register({"stop"}) - public void stopCommand(Player p) { - if (!permissionCheck(p)) return; + @Register(value = {"stop"}, description = "TRACE_COMMAND_HELP_STOP") + public void stopCommand(@Guard Player p) { RecordStateMachine.commandStop(); BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", p); } - @Register({"auto"}) + @Register(value = {"auto"}, description = "TRACE_COMMAND_HELP_AUTO") @Register({"toggleauto"}) - public void autoCommand(Player p) { - if (!permissionCheck(p)) return; + public void autoCommand(@Guard Player p) { RecordStateMachine.commandAuto(); BauSystem.MESSAGE.send(RecordStateMachine.getRecordStatus().getAutoMessage(), p); } + @Register(value = {"delete"}, description = "TRACE_COMMAND_HELP_DELETE") @Register({"clear"}) - public void clearCommand(Player p) { - deleteCommand(p); - } - - @Register({"delete"}) - public void deleteCommand(Player p) { - if (!permissionCheck(p)) return; + public void deleteCommand(@Guard Player p) { StoredRecords.clear(); BauSystem.MESSAGE.send("TRACE_MESSAGE_DELETE", p); } - @Register({"show"}) - public void showCommand(Player p, @OptionalValue("entity") ShowModeType showModeType, ShowModeParameterType... showModeParameterTypes) { - if (!permissionCheck(p)) return; + @Register(value = {"show"}, description = "TRACE_COMMAND_HELP_SHOW") + public void showCommand(@Guard Player p, @OptionalValue("entity") ShowModeType showModeType, ShowModeParameterType... showModeParameterTypes) { ShowModeParameter showModeParameter = new ShowModeParameter(); for (ShowModeParameterType showModeParameterType : showModeParameterTypes) { showModeParameterType.getShowModeParameterConsumer().accept(showModeParameter); @@ -329,25 +281,28 @@ public class TraceCommand extends SWCommand { private ShowModeParameterType[] removedTypes; } - @Register({"show", "gui"}) - public void showGuiCommand(Player p) { - if (!permissionCheck(p)) return; + @Register(value = {"show", "gui"}, description = "TRACE_COMMAND_HELP_SHOW_GUI") + public void showGuiCommand(@Guard Player p) { TraceShowGui.openGui(p); } - @Register({"hide"}) - public void hideCommand(Player p) { - if (!permissionCheck(p)) return; + @Register(value = {"hide"}, description = "TRACE_COMMAND_HELP_HIDE") + public void hideCommand(@Guard Player p) { TraceShowManager.hide(p); BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", p); } - - private boolean permissionCheck(Player player) { - if (!Permission.hasPermission(player, Permission.WORLD)) { - BauSystem.MESSAGE.send("TRACE_MESSAGE_DISALLOWED", player); - return false; - } - return true; + @ClassGuard(value = Player.class, local = true) + public GuardChecker guardChecker() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (Permission.hasPermission(player, Permission.WORLD)) { + return GuardResult.ALLOWED; + } + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("TRACE_MESSAGE_DISALLOWED", player); + } + return GuardResult.DENIED; + }; } }