mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 02:35:21 +01:00
Improved sub-command registration for add-ins.
This commit is contained in:
parent
ec5dacfc3a
commit
0dfc32a5b9
@ -24,6 +24,7 @@ general:
|
||||
|
||||
help:
|
||||
admin:
|
||||
delete: "delete an island (removes blocks)"
|
||||
team:
|
||||
command: "info/makeleader/add/kick/delete - admin teams"
|
||||
info: "info <player> - show info player's team"
|
||||
@ -35,6 +36,7 @@ help:
|
||||
syntax: " &7/&b[label] &c[command] &a[args] &7: &e[info]"
|
||||
syntax-alias-separator: "/"
|
||||
end: "&7================================="
|
||||
this: "this help"
|
||||
island:
|
||||
about: "display info about %bsb_plugin_name%"
|
||||
go: "teleport you to your island"
|
||||
|
@ -9,11 +9,13 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.ArgumentHandler;
|
||||
import us.tastybento.bskyblock.commands.AdminCommand;
|
||||
import us.tastybento.bskyblock.commands.IslandCommand;
|
||||
import us.tastybento.bskyblock.config.BSBLocale;
|
||||
@ -44,7 +46,7 @@ import us.tastybento.bskyblock.util.VaultHelper;
|
||||
public class BSkyBlock extends JavaPlugin{
|
||||
|
||||
private static BSkyBlock plugin;
|
||||
|
||||
|
||||
// Databases
|
||||
private PlayersManager playersManager;
|
||||
private IslandsManager islandsManager;
|
||||
@ -60,6 +62,8 @@ public class BSkyBlock extends JavaPlugin{
|
||||
|
||||
protected LocaleManager localeManager;
|
||||
|
||||
private AdminCommand adminCommand;
|
||||
|
||||
@Override
|
||||
public void onEnable(){
|
||||
plugin = this;
|
||||
@ -88,7 +92,8 @@ public class BSkyBlock extends JavaPlugin{
|
||||
|
||||
// Set up commands
|
||||
islandCommand = new IslandCommand(BSkyBlock.this);
|
||||
|
||||
adminCommand = new AdminCommand(BSkyBlock.this);
|
||||
|
||||
// These items have to be loaded when the server has done 1 tick.
|
||||
// Note Worlds are not loaded this early, so any Locations or World reference will be null
|
||||
// at this point. Therefore, the 1 tick scheduler is required.
|
||||
@ -116,8 +121,8 @@ public class BSkyBlock extends JavaPlugin{
|
||||
Settings.defaultLanguage = "en-US";
|
||||
localeManager = new LocaleManager(plugin);
|
||||
|
||||
|
||||
new AdminCommand(BSkyBlock.this);
|
||||
|
||||
|
||||
|
||||
// Register Listeners
|
||||
registerListeners();
|
||||
@ -253,4 +258,22 @@ public class BSkyBlock extends JavaPlugin{
|
||||
return localeManager.getLocale(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new sub command to BSkyBlock
|
||||
* @param argHandler - must specify either the island or admin command
|
||||
* @return true if successful, false if not
|
||||
*/
|
||||
public boolean addSubCommand(ArgumentHandler argHandler) {
|
||||
switch (argHandler.label) {
|
||||
case Settings.ISLANDCOMMAND:
|
||||
islandCommand.addArgument(argHandler);
|
||||
break;
|
||||
case Settings.ADMINCOMMAND:
|
||||
adminCommand.addArgument(argHandler);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
Util.sendMessage(sender, plugin.getLocale(sender).get("help.header"));
|
||||
for(ArgumentHandler handler: handlers){
|
||||
for(ArgumentHandler handler: handlers) {
|
||||
if (handler.canUse(sender).isAllowed()) Util.sendMessage(sender, handler.getShortDescription(sender));
|
||||
}
|
||||
Util.sendMessage(sender, plugin.getLocale(sender).get("help.end"));
|
||||
@ -83,7 +83,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public String[] usage(CommandSender sender) {
|
||||
return new String[] {"", ""};
|
||||
return new String[] {"", plugin.getLocale(sender).get("help.this")};
|
||||
}
|
||||
}.alias("help").alias("?"));
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ public abstract class ArgumentHandler {
|
||||
private BSkyBlock plugin;
|
||||
public Set<String> aliasSet;
|
||||
public final String label;
|
||||
public String command;
|
||||
|
||||
public abstract CanUseResp canUse(CommandSender sender);
|
||||
public abstract void execute(CommandSender sender, String[] args);
|
||||
@ -35,7 +34,11 @@ public abstract class ArgumentHandler {
|
||||
|
||||
String cmds = "";
|
||||
for(String alias : aliasSet) {
|
||||
cmds += plugin.getLocale(sender).get("help.syntax-alias-separator") + alias;
|
||||
if (cmds.isEmpty()) {
|
||||
cmds = alias;
|
||||
} else {
|
||||
cmds += plugin.getLocale(sender).get("help.syntax-alias-separator") + alias;
|
||||
}
|
||||
}
|
||||
|
||||
msg = msg.replace("[command]", cmds);
|
||||
@ -48,11 +51,11 @@ public abstract class ArgumentHandler {
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getAliases() {
|
||||
return aliasSet;
|
||||
}
|
||||
|
||||
|
||||
public ArgumentHandler alias(String alias) {
|
||||
aliasSet.add(alias);
|
||||
return this;
|
||||
|
@ -367,5 +367,4 @@ public class AdminCommand extends AbstractCommand {
|
||||
// TODO: Show help...
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1468,7 +1468,4 @@ public class IslandCommand extends AbstractCommand {
|
||||
getIslands().newIsland(player, schematic);
|
||||
}
|
||||
|
||||
public void addSubCommand(ArgumentHandler handler) {
|
||||
addArgument(handler);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user