From 9e867a74578e51c51a618d90d6eb88a0427cda5f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 16 Jun 2022 12:15:50 +0200 Subject: [PATCH] Update TutorialCommand --- .../bungeecore/commands/TutorialCommand.java | 93 +++++++++---------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TutorialCommand.java b/src/de/steamwar/bungeecore/commands/TutorialCommand.java index 4f55742..8ad1393 100644 --- a/src/de/steamwar/bungeecore/commands/TutorialCommand.java +++ b/src/de/steamwar/bungeecore/commands/TutorialCommand.java @@ -26,7 +26,9 @@ import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Tutorial; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.command.GuardChecker; +import de.steamwar.command.GuardResult; +import de.steamwar.command.SWCommand; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -38,66 +40,63 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.stream.Collectors; -public class TutorialCommand extends BasicCommand { +public class TutorialCommand extends SWCommand { public TutorialCommand() { super("tutorial", null); + addDefaultHelpMessage("TUTORIAL_CREATE_HELP"); + addDefaultHelpMessage("TUTORIAL_OWN_HELP"); } - @Override - public void execute(CommandSender sender, String[] args) { - if(!(sender instanceof ProxiedPlayer)) - return; - ProxiedPlayer player = (ProxiedPlayer) sender; + @Register + public void genericCommand(ProxiedPlayer player) { + openInventory(player, true, false); + } - if(args.length == 0) { - openInventory(player, true, false); + @Register("rate") + public void rate(ProxiedPlayer player) { + player.chat("/tutorial rate"); + } + + @Register("rate") + public void rate(ProxiedPlayer player, int id) { + Tutorial tutorial = Tutorial.get(id); + if(tutorial == null) { + BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with nonexistent id: " + id); return; } - switch(args[0].toLowerCase()) { - case "rate": - if(args.length < 2) { - player.chat("/tutorial rate"); - return; - } + rate(player, tutorial); + } - int id; - try { - id = Integer.parseInt(args[1]); - } catch (NumberFormatException e) { - BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with non number: " + args[1]); - return; - } + @Register(value = "create", description = "TUTORIAL_CREATE_HELP") + public void create(ProxiedPlayer player, String material, String... name) { + create(player, String.join(" ", name), material.toUpperCase()); + } - Tutorial tutorial = Tutorial.get(id); - if(tutorial == null) { - BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with nonexistent id: " + id); - return; - } + @Register("own") + public void own(ProxiedPlayer player) { + openInventory(player, false, true); + } - rate(player, tutorial); - break; - case "create": - if(args.length < 3) { - Message.send("TUTORIAL_CREATE_HELP", player); - return; - } + @Register("unreleased") + public void unreleased(@Guard("unreleased") ProxiedPlayer player) { + openInventory(player, false, false); + } - create(player, Arrays.stream(args).skip(2).collect(Collectors.joining(" ")), args[1].toUpperCase()); - break; - case "own": - openInventory(player, false, true); - break; - case "unreleased": - if (SteamwarUser.get(player.getUniqueId()).getUserGroup().isTeamGroup()) { - openInventory(player, false, false); - break; + @Guard("unreleased") + public GuardChecker unreleasedChecker() { + return (commandSender, guardCheckType, previousArguments, s) -> { + if (commandSender instanceof ProxiedPlayer) { + if (SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup().isTeamGroup()) { + return GuardResult.ALLOWED; + } else { + return GuardResult.DENIED_WITH_HELP; } - default: - Message.send("TUTORIAL_CREATE_HELP", player); - Message.send("TUTORIAL_OWN_HELP", player); - } + } else { + return GuardResult.ALLOWED; + } + }; } private void openInventory(ProxiedPlayer player, boolean released, boolean own) {