From 72cf3f63b5b2ffe714addcbcb61d7b192e3cc42e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 27 Dec 2021 13:48:20 +0100 Subject: [PATCH] Update WarpCommand to new CommandFramework Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 12 ++-- .../bausystem/features/warp/WarpCommand.java | 57 ++++++++----------- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 3c187e4a..81e705bf 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -1077,12 +1077,12 @@ WARP_GUI_DISTANCE=§7Distanz: §e{0} §7Blöcke WARP_GUI_LCLICK=§7Links klicken zum teleportieren WARP_GUI_RCLICK=§7Rechts klicken zum editieren WARP_INFO_NAME=§7Name: §e{0} -WARP_HELP_1=§8/§ewarp add §8[§7Name§8] - §7Erstelle einen neuen Warp Punkt -WARP_HELP_2=§8/§ewarp §8[§7Name§8] - §7Teleportiere dich zu einen Warp-Punkt -WARP_HELP_3=§8/§ewarp info §8[§7Name§8] - §7Infos zu einem Punkt -WARP_HELP_4=§8/§ewarp delete §8[§7Name§8] - §7Lösche einen Warp -WARP_HELP_5=§8/§ewarp gui - §7Öffne die Warp-GUI -WARP_HELP_6=§8/§ewarp list - §7Liste alle Warp-Punkt auf +WARP_HELP_ADD=§8/§ewarp add §8[§7Name§8] §8- §7Erstelle einen neuen Warp Punkt +WARP_HELP_TELEPORT=§8/§ewarp §8[§7Name§8] §8- §7Teleportiere dich zu einen Warp-Punkt +WARP_HELP_INFO=§8/§ewarp info §8[§7Name§8] §8- §7Infos zu einem Punkt +WARP_HELP_DELETE=§8/§ewarp delete §8[§7Name§8] §8- §7Lösche einen Warp +WARP_HELP_GUI=§8/§ewarp gui §8- §7Öffne die Warp-GUI +WARP_HELP_LIST=§8/§ewarp list §8- §7Liste alle Warp-Punkt auf WARP_MOON_ITEM_NAME=§3Atemkugel WARP_MOON_COUNTDOOWN=§7Noch §e§l{0} §7Sekunden! diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java index e18f9940..0234ea42 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java @@ -27,9 +27,7 @@ import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.utils.ListChatView; import de.steamwar.bausystem.worlddata.WorldData; -import de.steamwar.command.SWCommand; -import de.steamwar.command.SWCommandUtils; -import de.steamwar.command.TypeMapper; +import de.steamwar.command.*; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; @@ -58,25 +56,14 @@ public class WarpCommand extends SWCommand implements Disable, Enable { return SWCommandUtils.createMapper(Warp::getWarp, (commandSender, s) -> new ArrayList<>(Warp.getWarpNames())); } - @Register(help = true) - public void genericHelp(Player player, String... args) { - if (args.length > 0 && args[0].equals("moon")) { - Moon.startMoon(player); - return; - } - BauSystem.MESSAGE.sendPrefixless("COMMAND_HELP_HEAD", player, "Warp"); - BauSystem.MESSAGE.sendPrefixless("WARP_HELP_1", player); - BauSystem.MESSAGE.sendPrefixless("WARP_HELP_2", player); - BauSystem.MESSAGE.sendPrefixless("WARP_HELP_3", player); - BauSystem.MESSAGE.sendPrefixless("WARP_HELP_4", player); - BauSystem.MESSAGE.sendPrefixless("WARP_HELP_5", player); - BauSystem.MESSAGE.sendPrefixless("WARP_HELP_6", player); + @Register(value = "moon", noTabComplete = true) + public void tpMoon(Player p) { + Moon.startMoon(p); } - @Register("add") + @Register(value = "add", description = "WARP_HELP_ADD") @Register("create") - public void addWarp(Player player, String name) { - if (!permissionCheck(player)) return; + public void addWarp(@Guard Player player, String name) { for (String forbiddenName : FORBIDDEN_NAMES) { if (name.equalsIgnoreCase(forbiddenName)) { BauSystem.MESSAGE.send("WARP_NAME_RESERVED", player, name); @@ -91,24 +78,23 @@ public class WarpCommand extends SWCommand implements Disable, Enable { BauSystem.MESSAGE.send("WARP_CREATED", player, name); } - @Register + @Register(description = "WARP_HELP_TELEPORT") public void tpWarp(Player player, Warp warp) { warp.teleport(player); } - @Register("delete") - public void deleteWarp(Player player, Warp warp) { - if (!permissionCheck(player)) return; + @Register(value = "delete", description = "WARP_HELP_DELETE") + public void deleteWarp(@Guard Player player, Warp warp) { warp.delete(); BauSystem.MESSAGE.send("WARP_DELETED", player, warp.getName()); } - @Register("gui") + @Register(value = "gui", description = "WARP_HELP_GUI") public void gui(Player player) { WarpGui.openGui(player); } - @Register("list") + @Register(value = "list", description = "WARP_HELP_LIST") public void listWarps(Player player) { listWarps(player, 0); } @@ -131,7 +117,7 @@ public class WarpCommand extends SWCommand implements Disable, Enable { }); } - @Register("info") + @Register(value = "info", description = "WARP_HELP_INFO") public void warpInfo(Player player, Warp warp) { BauSystem.MESSAGE.send("COMMAND_HELP_HEAD", player, warp.getName()); BauSystem.MESSAGE.sendPrefixless("WARP_INFO_NAME", player, warp.getName()); @@ -141,13 +127,18 @@ public class WarpCommand extends SWCommand implements Disable, Enable { BauSystem.MESSAGE.sendPrefixless("WARP_GUI_DISTANCE", player, warp.getLocation().distance(player.getLocation())); } - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - private boolean permissionCheck(Player player) { - if (!Permission.hasPermission(player, Permission.WORLD)) { - BauSystem.MESSAGE.send("WARP_DISALLOWED", player); - return false; - } - return true; + @ClassGuard(value = Player.class, local = true) + public GuardChecker commandGuard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLD)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("WARP_DISALLOWED", player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; } @Linked(LinkageType.COMMAND)