Fixed help and usage descriptions.

Known issue - the help shown when doing a parent help is not using the
child's custom help class for usage/description.
This commit is contained in:
Tastybento 2017-12-26 11:09:00 -08:00
parent 239cf50709
commit f22065fd2c
21 changed files with 140 additions and 52 deletions

View File

@ -34,82 +34,92 @@ commands:
about: "display this help page"
admin:
version:
usage: "display %bsb_plugin_name% and addons versions"
description: "display %bsb_plugin_name% and addons versions"
setrange:
range-updated: "Island range updated to [number]"
island:
about:
usage: "display info about %bsb_plugin_name%"
description: "display info about %bsb_plugin_name%"
go:
usage: "teleport you to your island"
usage: "<home number>"
description: "teleport you to your island"
spawn:
usage: "teleport you to the spawn"
description: "teleport you to the spawn"
create:
usage: "create an island"
description: "create an island"
unable-create-island: "Your island could not be generated, please contact an administrator."
info:
usage: "display info about your island"
description: "display info about your island"
reset:
usage: "restart your island and remove the old one"
description: "restart your island and remove the old one"
must-remove-members: "You must remove all members from your island before you can restart it (/island kick <player>)."
sethome:
usage: "set your teleport point for /island"
description: "set your teleport point for /island"
must-be-on-your-island: "You must be on your island to set home!"
num-homes: "Homes can be 1 to [max]."
home-set: "Your island home has been set to your current location."
usage: "<home number>"
setname:
usage: "set a name for your island"
description: "set a name for your island"
name-too-short: "Too short. Minimum size is [length] characters."
name-too-long: "Too long. Maximum size is [length] characters."
usage: "<name>"
resetname:
usage: "reset your island name"
description: "reset your island name"
team:
usage: "manage your team"
description: "manage your team"
info:
usage: "display detailed info about your team"
description: "display detailed info about your team"
invite:
usage: "invite a player to join your island"
description: "invite a player to join your island"
errors:
island-is-full: "Your island is full, you can't invite anyone else."
none-invited-you: "No one invited you :c."
you-already-are-in-team: "You are already on a team!"
invalid-invite: "That invite is no longer valid, sorry."
usage: "<player>"
you-can-invite: "You can invite [number] more players."
accept:
usage: "accept an invitation"
description: "accept an invitation"
you-joined-island: "You have joined an island! Use /[label] team info to see the other members."
name-joined-your-island: "[name] has joined your island!"
reject:
usage: "reject an invitation"
description: "reject an invitation"
you-rejected-invite: "You have rejected the invitation to join an island."
name-rejected-your-invite: "[name] has rejected your island invite!"
cancel:
usage: "cancel the pending invite to join your island"
description: "cancel the pending invite to join your island"
leave:
usage: "leave your island"
description: "leave your island"
kick:
usage: "remove a member from your island"
description: "remove a member from your island"
usage: "<player>"
promote:
usage: "promote a player on your island to another rank"
description: "promote a player on your island to another rank"
usage: "<player>"
setowner:
usage: "transfer your island ownership to a member"
description: "transfer your island ownership to a member"
errors:
cant-transfer-to-yourself: "You can't transfer ownership to yourself! Well, in facts, you could have been able to do so... But we don't want you to do so. 'Cause it's bad."
target-is-not-member: "That player is not part of your island team!"
name-is-the-owner: "[name] is now the island owner!"
usage: "<player>"
you-are-the-owner: "You are now the island owner!"
ban:
usage: "ban a player from your island"
description: "ban a player from your island"
usage: "<player>"
unban:
usage: "unban a player from your island"
description: "unban a player from your island"
usage: "<player>"
banlist:
usage: "list banned players"
description: "list banned players"
lock:
usage: "lock/unlock your island so visitors cannot enter it"
description: "lock/unlock your island so visitors cannot enter it"
settings:
usage: "display island settings"
description: "display island settings"
language:
usage: "select language"
description: "select language"
usage: "<language>"
protection:
flags:

View File

@ -71,9 +71,12 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
this.setAliases(new ArrayList<>(Arrays.asList(aliases)));
this.subCommands = new LinkedHashMap<>();
setUsage("");
if (!label.equals("help"))
new DefaultHelpCommand(this);
setDescription("");
this.setup();
// If this command does not define its own help class, then use the default help command
if (!this.getSubCommand("help").isPresent() && !label.equals("help"))
new DefaultHelpCommand(this);
if (DEBUG)
Bukkit.getLogger().info("DEBUG: registering command " + label);
}
@ -155,7 +158,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
Bukkit.getLogger().info("DEBUG: This command has subcommands");
if (subCommand.hasSubCommand(args[i])) {
// Step down one
subCommand = subCommand.getSubCommand(args[i]);
subCommand = subCommand.getSubCommand(args[i]).get();
if (DEBUG)
Bukkit.getLogger().info("DEBUG: Moved to " + subCommand.getLabel());
} else {
@ -229,12 +232,12 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* @param label - command label or alias
* @return CompositeCommand or null if none found
*/
public CompositeCommand getSubCommand(String label) {
public Optional<CompositeCommand> getSubCommand(String label) {
for (Map.Entry<String, CompositeCommand> entry : subCommands.entrySet()) {
if (entry.getKey().equalsIgnoreCase(label)) return subCommands.get(label);
else if (entry.getValue().getAliases().contains(label)) return subCommands.get(entry.getValue().getLabel());
if (entry.getKey().equalsIgnoreCase(label)) return Optional.of(subCommands.get(label));
else if (entry.getValue().getAliases().contains(label)) return Optional.of(subCommands.get(entry.getValue().getLabel()));
}
return null;
return Optional.empty();
}
/**

View File

@ -1,5 +1,6 @@
package us.tastybento.bskyblock.api.commands;
import java.util.ArrayList;
import java.util.List;
/**
@ -19,29 +20,35 @@ public class DefaultHelpCommand extends CompositeCommand {
@Override
public boolean execute(User user, List<String> args) {
if (args.isEmpty()) {
// Show the top level help
if (user.isPlayer()) {
// Player. Check perms
if (user.hasPermission(parent.getPermission()) && user.hasPermission(parent.getPermission())) {
user.sendMessage(parent.getUsage());
if (user.hasPermission(parent.getPermission())) {
user.sendMessage((parent.getUsage().isEmpty() ? "" : parent.getUsage() + " ") + parent.getDescription());
} else {
user.sendMessage("errors.no-permission");
return true;
}
} else if (!parent.isOnlyPlayer() && !parent.isOnlyPlayer()) {
} else if (!parent.isOnlyPlayer()) {
// Console. Only show if it is a console command
user.sendMessage(parent.getUsage());
user.sendMessage((parent.getUsage().isEmpty() ? "" : parent.getUsage() + " ") + parent.getDescription());
}
// Run through any subcommands
for (CompositeCommand subCommand : parent.getSubCommands().values()) {
// Ignore the help command
if (!subCommand.getLabel().equals("help")) {
String usage = subCommand.getUsage();
String desc = subCommand.getDescription();
if (user.isPlayer()) {
// Player. Check perms
if (user.hasPermission(parent.getPermission()) && user.hasPermission(subCommand.getPermission())) {
user.sendMessage(subCommand.getUsage());
user.sendMessage((usage.isEmpty() ? "" : usage + " ") + desc);
}
} else if (!subCommand.isOnlyPlayer()) {
// Console
user.sendMessage(subCommand.getUsage());
user.sendMessage((usage.isEmpty() ? "" : usage + " ") + desc);
}
}
}

View File

@ -22,7 +22,7 @@ public class AdminCommand extends CompositeCommand {
@Override
public boolean execute(User user, List<String> args) {
return false;
return true;
}
}

View File

@ -45,10 +45,10 @@ public class IslandCommand extends CompositeCommand {
public boolean execute(User user, List<String> args) {
user.sendLegacyMessage("You successfully did /is !");
if (!getPlugin().getIslands().hasIsland(user.getUniqueId())) {
return this.getSubCommand("create").execute(user, args);
return this.getSubCommand("create").get().execute(user, args);
}
// Currently, just go home
return this.getSubCommand("go").execute(user, args);
return this.getSubCommand("go").get().execute(user, args);
}
}

View File

@ -14,7 +14,7 @@ public class IslandAboutCommand extends CompositeCommand {
*/
public IslandAboutCommand(CompositeCommand islandCommand) {
super(islandCommand, "about", "ab");
this.setUsage("commands.island.about.usage");
this.setDescription("commands.island.about.description");
}
@Override

View File

@ -23,7 +23,7 @@ public class IslandCreateCommand extends CompositeCommand {
super(islandCommand, "create", "auto");
this.setPermission(Settings.PERMPREFIX + "island.create");
this.setOnlyPlayer(true);
this.setUsage("commands.island.create.usage");
this.setDescription("commands.island.create.description");
}
/* (non-Javadoc)

View File

@ -25,6 +25,12 @@ public class IslandGoCommand extends CompositeCommand {
this.setPermission(Settings.PERMPREFIX + "island.home");
this.setOnlyPlayer(true);
this.setUsage("commands.island.go.usage");
this.setDescription("commands.island.go.description");
}
@Override
public void setup() {
new IslandMultiHomeHelp(this);
}
/* (non-Javadoc)

View File

@ -0,0 +1,49 @@
package us.tastybento.bskyblock.commands.island;
import java.util.List;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.Util;
/**
* This is a customer help for the /island go and /island sethome commands. It overrides the default help sub command.
* The number of homes can change depending on the player's permissions and config.yml settings.
* @author ben
*
*/
public class IslandMultiHomeHelp extends CompositeCommand {
private CompositeCommand parent;
public IslandMultiHomeHelp(CompositeCommand parent) {
super(parent, "help");
this.parent = parent;
this.setOnlyPlayer(true);
}
@Override
public boolean execute(User user, List<String> args) {
if (user.isPlayer()) {
user.sendLegacyMessage("DEBUG: Custom help");
// Player. Check perms
if (user.hasPermission(parent.getPermission())) {
int maxHomes = Util.getPermValue(user.getPlayer(), Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
if (maxHomes > 1) {
user.sendMessage((parent.getUsage().isEmpty() ? "" : parent.getUsage() + " ") + parent.getDescription());
} else {
user.sendMessage(parent.getDescription());
}
return true;
} else {
user.sendMessage("errors.no-permission");
return true;
}
}
return false;
}
}

View File

@ -21,7 +21,7 @@ public class IslandResetCommand extends CompositeCommand {
super(islandCommand, "reset", "restart");
this.setPermission(Settings.PERMPREFIX + "island.create");
this.setOnlyPlayer(true);
this.setUsage("commands.island.reset.usage");
this.setDescription("commands.island.reset.description");
}
@Override

View File

@ -21,6 +21,7 @@ public class IslandResetnameCommand extends CompositeCommand {
this.setPermission(Settings.PERMPREFIX + "island.name");
this.setOnlyPlayer(true);
this.setUsage("commands.island.resetname.usage");
this.setDescription("commands.island.resetname.description");
}

View File

@ -15,6 +15,12 @@ public class IslandSethomeCommand extends CompositeCommand {
this.setPermission(Settings.PERMPREFIX + "island.sethome");
this.setOnlyPlayer(true);
this.setUsage("commands.island.sethome.usage");
this.setDescription("commands.island.sethome.description");
}
@Override
public void setup() {
new IslandMultiHomeHelp(this);
}
@Override

View File

@ -25,7 +25,7 @@ public class IslandSetnameCommand extends CompositeCommand {
this.setPermission(Settings.PERMPREFIX + "island.name");
this.setOnlyPlayer(true);
this.setUsage("commands.island.setname.usage");
this.setDescription("commands.island.setname.description");
}
/* (non-Javadoc)

View File

@ -22,7 +22,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
super(islandCommand, "team");
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setUsage("commands.island.team.usage");
this.setDescription("commands.island.team.description");
}
@Override

View File

@ -21,6 +21,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setUsage("commands.island.team.invite.accept.usage");
this.setDescription("commands.island.team.invite.accept.description");
}
@Override

View File

@ -25,6 +25,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setUsage("commands.island.team.invite.usage");
this.setDescription("commands.island.team.invite.description");
}
@Override

View File

@ -16,6 +16,7 @@ public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setUsage("commands.island.team.invite.reject.usage");
this.setDescription("commands.island.team.invite.reject.description");
}
@Override

View File

@ -12,6 +12,7 @@ public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setUsage("command.island.team.leave.usage");
this.setDescription("commands.island.team.leave.description");
}

View File

@ -12,6 +12,7 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setUsage("island.team.promote.usage");
this.setDescription("commands.island.team.promote.description");
}
@Override

View File

@ -24,6 +24,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
this.setUsage("commands.island.team.setowner.usage");
this.setDescription("commands.island.team.setowner.description");
}
@Override

View File

@ -91,10 +91,10 @@ public class TestBSkyBlock {
assertEquals(Settings.PERMPREFIX + "default.permission", testCommand.getPermission());
// Check commands and aliases match to correct class
for (Entry<String, CompositeCommand> command : testCommand.getSubCommands().entrySet()) {
assertEquals(testCommand.getSubCommand(command.getKey()), command.getValue());
assertEquals(testCommand.getSubCommand(command.getKey()), Optional.of(command.getValue()));
// Check aliases
for (String alias : command.getValue().getAliases()) {
assertEquals(testCommand.getSubCommand(alias), command.getValue());
assertEquals(testCommand.getSubCommand(alias), Optional.of(command.getValue()));
}
}
String[] args = {""};
@ -107,11 +107,11 @@ public class TestBSkyBlock {
args[0] = "sub1";
assertEquals(Arrays.asList(), testCommand.tabComplete(player, "test", args));
String[] args2 = {"sub2",""};
assertEquals(Arrays.asList("help", "subsub"), testCommand.tabComplete(player, "test", args2));
assertEquals(Arrays.asList("subsub", "help"), testCommand.tabComplete(player, "test", args2));
args2[1] = "s";
assertEquals(Arrays.asList("subsub"), testCommand.tabComplete(player, "test", args2));
String[] args3 = {"sub2","subsub", ""};
assertEquals(Arrays.asList("help", "subsubsub"), testCommand.tabComplete(player, "test", args3));
assertEquals(Arrays.asList("subsubsub", "help"), testCommand.tabComplete(player, "test", args3));
// Test for overridden tabcomplete
assertEquals(Arrays.asList(new String[] {"Florian", "Ben", "Bill", "Ted", "help"}),
testCommand.tabComplete(player, "test", new String[] {"sub2", "subsub", "subsubsub", ""}));