mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-03-02 11:12:28 +01:00
Made help argument optionable (to support the NotSetup)
This commit is contained in:
parent
bafff8cdee
commit
0980ab8358
@ -7,7 +7,7 @@ import us.tastybento.bskyblock.BSkyBlock;
|
|||||||
public class AdminCommand extends BSBCommand{
|
public class AdminCommand extends BSBCommand{
|
||||||
|
|
||||||
public AdminCommand(BSkyBlock plugin) {
|
public AdminCommand(BSkyBlock plugin) {
|
||||||
super(plugin);
|
super(plugin, true);
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.util.Util;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class that handles commands and tabs. It makes the commands code modular
|
* Abstract class that handles commands and tabs. It makes the commands code modular
|
||||||
@ -23,11 +22,14 @@ import us.tastybento.bskyblock.util.Util;
|
|||||||
*/
|
*/
|
||||||
public abstract class BSBCommand implements CommandExecutor, TabCompleter{
|
public abstract class BSBCommand implements CommandExecutor, TabCompleter{
|
||||||
private Map<String, CommandArgumentHandler> arguments;
|
private Map<String, CommandArgumentHandler> arguments;
|
||||||
|
private boolean help;
|
||||||
|
|
||||||
protected BSBCommand(BSkyBlock plugin){
|
protected BSBCommand(BSkyBlock plugin, boolean help){
|
||||||
arguments = new HashMap<String, CommandArgumentHandler>();
|
arguments = new HashMap<String, CommandArgumentHandler>();
|
||||||
|
this.help = help;
|
||||||
|
|
||||||
// Automatically register the help argument
|
// Register a help argument if needed
|
||||||
|
if(help){
|
||||||
registerArgument(new String[] {"help", "?"}, new CommandArgumentHandler() {
|
registerArgument(new String[] {"help", "?"}, new CommandArgumentHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -37,19 +39,7 @@ public abstract class BSBCommand implements CommandExecutor, TabCompleter{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onExecute(CommandSender sender, String label, String[] args) {
|
public void onExecute(CommandSender sender, String label, String[] args) {
|
||||||
// Generate help
|
// TODO send help
|
||||||
String help = plugin.getLocale(sender).get("help.header") + "\n";
|
|
||||||
|
|
||||||
for(String argument : arguments.keySet()){
|
|
||||||
CommandArgumentHandler cah = getArgumentHandler(argument);
|
|
||||||
if(cah.canExecute(sender, label, args) && cah.getHelp(sender, label) != null) {
|
|
||||||
help += getHelpMessage(sender, label, argument, cah.getHelp(sender, label)) + "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: multiple pages
|
|
||||||
|
|
||||||
Util.sendMessage(sender, help);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -63,6 +53,7 @@ public abstract class BSBCommand implements CommandExecutor, TabCompleter{
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Register other arguments
|
// Register other arguments
|
||||||
setup();
|
setup();
|
||||||
@ -93,12 +84,12 @@ public abstract class BSBCommand implements CommandExecutor, TabCompleter{
|
|||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
|
||||||
if(this.canExecute(sender, label)){
|
if(this.canExecute(sender, label)){
|
||||||
if(args.length >= 1){
|
if(args.length >= 1){
|
||||||
if(arguments.get(args[0]) != null){
|
if(arguments.containsKey(args[0]) && arguments.get(args[0]).canExecute(sender, label, args)){
|
||||||
if(arguments.get(args[0]).canExecute(sender, label, args)){
|
|
||||||
arguments.get(args[0]).onExecute(sender, label, args);
|
arguments.get(args[0]).onExecute(sender, label, args);
|
||||||
}
|
} else if(help) {
|
||||||
|
arguments.get("?").onExecute(sender, label, args);
|
||||||
} else {
|
} else {
|
||||||
arguments.get("help").onExecute(sender, label, args);
|
this.onExecuteDefault(sender, label, args);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.onExecuteDefault(sender, label, args);
|
this.onExecuteDefault(sender, label, args);
|
||||||
@ -177,8 +168,4 @@ public abstract class BSBCommand implements CommandExecutor, TabCompleter{
|
|||||||
public CommandArgumentHandler getArgumentHandler(String argument){
|
public CommandArgumentHandler getArgumentHandler(String argument){
|
||||||
return arguments.get(argument);
|
return arguments.get(argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHelpMessage(CommandSender sender, String label, String argument, String[] helpData){
|
|
||||||
return ""; //TODO help
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class IslandCommand extends BSBCommand{
|
|||||||
private BSkyBlock plugin;
|
private BSkyBlock plugin;
|
||||||
|
|
||||||
public IslandCommand(BSkyBlock plugin) {
|
public IslandCommand(BSkyBlock plugin) {
|
||||||
super(plugin);
|
super(plugin, true);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +310,7 @@ public class IslandCommand extends BSBCommand{
|
|||||||
|
|
||||||
// Explain command
|
// Explain command
|
||||||
if(args.length == 1){
|
if(args.length == 1){
|
||||||
Util.sendMessage(player, getHelpMessage(player, label, args[0], getHelp(sender, label)));
|
//TODO Util.sendMessage(player, getHelpMessage(player, label, args[0], getHelp(sender, label)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user