mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-22 09:08:03 +01:00
Implemented basic help. It NEEDS improvements.
This commit is contained in:
parent
4970a43b00
commit
bfefea7f6a
@ -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"
|
||||
|
@ -22,6 +22,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
||||
private final Map<String, String> 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<UUID>(1);
|
||||
|
||||
@ -50,7 +52,27 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
List<String> 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
|
||||
|
@ -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;
|
||||
|
@ -40,7 +40,7 @@ public class IslandCommand extends AbstractCommand {
|
||||
protected Set<UUID> leavingPlayers = new HashSet<UUID>();
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user