From bfefea7f6a31ccee62db732784c602abe55dd372 Mon Sep 17 00:00:00 2001 From: Poslovitch Date: Tue, 8 Aug 2017 17:13:36 +0200 Subject: [PATCH] Implemented basic help. It NEEDS improvements. --- locales/bsb_en_US.yml | 8 +++++- .../api/commands/AbstractCommand.java | 26 +++++++++++++++++-- .../bskyblock/commands/AdminCommand.java | 2 +- .../bskyblock/commands/IslandCommand.java | 4 +-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/locales/bsb_en_US.yml b/locales/bsb_en_US.yml index cdfe01d61..31ea9b402 100755 --- a/locales/bsb_en_US.yml +++ b/locales/bsb_en_US.yml @@ -39,9 +39,15 @@ general: use-in-game: "This command is only available in game." no-team: "You do not have a team!" no-island: "You do not have an island!" + already-have-island: "You already have an island!" not-leader: "You are not the leader of your island!" offline-player: "That player is offline or doesn't exist." - + +help: + header: "&7=========== BSKYBLOCK ===========" + syntax: " &7/&b[label] &c[command] &a[args] &7: &e[info]" + end: "&7=================================" + # TODO: These are legacy strings and should be converted to a better format but will do for now acidBottle: "Acid Bottle" acidBucket: "Acid Bucket" diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java b/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java index 7dcc8869c..b08777721 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java @@ -22,6 +22,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { private final Map aliasesMap; public final String label; + public final String[] aliases; public boolean isPlayer; public boolean inTeam; public UUID teamLeaderUUID; @@ -32,11 +33,12 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { private final boolean help; private static final int MAX_PER_PAGE = 7; - protected AbstractCommand(BSkyBlock plugin, String label, boolean help) { + protected AbstractCommand(BSkyBlock plugin, String label, String[] aliases, boolean help) { this.plugin = plugin; - this.argumentsMap = new HashMap<>(1); + this.argumentsMap = new LinkedHashMap<>(1); this.aliasesMap = new HashMap<>(1); this.label = label; + this.aliases = aliases; this.help = help; this.teamMembers = new HashSet(1); @@ -50,7 +52,27 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { @Override public void execute(CommandSender sender, String[] args) { + List help = new ArrayList<>(); + for(String arg : argumentsMap.keySet()) { + String[] usage = argumentsMap.get(arg).usage(sender); + if (usage == null) usage = new String[2]; + + System.out.println(label); + System.out.println(arg); + System.out.println(usage[0]); + System.out.println(usage[1]); + + String msg = plugin.getLocale(sender).get("help.syntax").replace("[label]", (aliases[0] != null) ? aliases[0] : label) + .replace("[command]", arg) + .replace("[args]", (usage != null && usage[0] != null) ? usage[0] : "") + .replace("[info]", (usage != null && usage[1] != null) ? usage[1] : ""); + help.add(msg); + } + + Util.sendMessage(sender, plugin.getLocale(sender).get("help.header")); + for(String cmd : help) Util.sendMessage(sender, cmd); + Util.sendMessage(sender, plugin.getLocale(sender).get("help.end")); } @Override diff --git a/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java b/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java index b4237375a..f7a8df742 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java @@ -12,7 +12,7 @@ public class AdminCommand extends AbstractCommand { BSkyBlock plugin; public AdminCommand(BSkyBlock plugin) { - super(plugin, Settings.ADMINCOMMAND, true); + super(plugin, Settings.ADMINCOMMAND, new String[0], true); plugin.getCommand(Settings.ADMINCOMMAND).setExecutor(this); plugin.getCommand(Settings.ADMINCOMMAND).setTabCompleter(this); this.plugin = plugin; diff --git a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java index 4fe03a065..7289b6b95 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java @@ -40,7 +40,7 @@ public class IslandCommand extends AbstractCommand { protected Set leavingPlayers = new HashSet(); public IslandCommand(BSkyBlock plugin) { - super(plugin, Settings.ISLANDCOMMAND, true); + super(plugin, Settings.ISLANDCOMMAND, new String[] {"is"}, true); plugin.getCommand(Settings.ISLANDCOMMAND).setExecutor(this); plugin.getCommand(Settings.ISLANDCOMMAND).setTabCompleter(this); this.plugin = plugin; @@ -51,7 +51,7 @@ public class IslandCommand extends AbstractCommand { if(!(sender instanceof Player)){ return new CanUseResp(plugin.getLocale(sender).get("general.errors.use-in-game")); } - + // Basic permission check to even use /island if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.create")){ return new CanUseResp(ChatColor.RED + plugin.getLocale(sender).get("general.errors.no-permission"));