Fixed brackets.

This commit is contained in:
Tastybento 2018-02-06 21:43:31 -08:00
parent f4c7a3fe45
commit 219d1e66ab

View File

@ -78,9 +78,9 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
this.subCommands = new LinkedHashMap<>(); this.subCommands = new LinkedHashMap<>();
this.subCommandAliases = new LinkedHashMap<>(); this.subCommandAliases = new LinkedHashMap<>();
this.setup(); this.setup();
if (!this.getSubCommand("help").isPresent() && !label.equals("help")) if (!this.getSubCommand("help").isPresent() && !label.equals("help")) {
new DefaultHelpCommand(this); new DefaultHelpCommand(this);
}
} }
@ -106,11 +106,12 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
setUsage(""); setUsage("");
this.setup(); this.setup();
// If this command does not define its own help class, then use the default help command // If this command does not define its own help class, then use the default help command
if (!this.getSubCommand("help").isPresent() && !label.equals("help")) if (!this.getSubCommand("help").isPresent() && !label.equals("help")) {
new DefaultHelpCommand(this); new DefaultHelpCommand(this);
}
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: registering command " + label); Bukkit.getLogger().info("DEBUG: registering command " + label);
}
} }
/** /**
@ -120,8 +121,9 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
*/ */
public CompositeCommand(String label, String... aliases) { public CompositeCommand(String label, String... aliases) {
super(label); super(label);
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: top level command registering..." + label); Bukkit.getLogger().info("DEBUG: top level command registering..." + label);
}
this.setAliases(new ArrayList<>(Arrays.asList(aliases))); this.setAliases(new ArrayList<>(Arrays.asList(aliases)));
this.parent = null; this.parent = null;
setUsage(""); setUsage("");
@ -133,9 +135,9 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
getPlugin().getCommandsManager().registerCommand(this); getPlugin().getCommandsManager().registerCommand(this);
} }
this.setup(); this.setup();
if (!this.getSubCommand("help").isPresent() && !label.equals("help")) if (!this.getSubCommand("help").isPresent() && !label.equals("help")) {
new DefaultHelpCommand(this); new DefaultHelpCommand(this);
}
} }
@ -145,8 +147,9 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
*/ */
@Override @Override
public boolean execute(CommandSender sender, String label, String[] args) { public boolean execute(CommandSender sender, String label, String[] args) {
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: executing command " + label); Bukkit.getLogger().info("DEBUG: executing command " + label);
}
// Get the User instance for this sender // Get the User instance for this sender
User user = User.getInstance(sender); User user = User.getInstance(sender);
CompositeCommand cmd = getCommandFromArgs(args); CompositeCommand cmd = getCommandFromArgs(args);
@ -186,30 +189,35 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
private CompositeCommand getCommandFromArgs(String[] args) { private CompositeCommand getCommandFromArgs(String[] args) {
CompositeCommand subCommand = this; CompositeCommand subCommand = this;
// Run through any arguments // Run through any arguments
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: Running through args: " + Arrays.asList(args).toString()); Bukkit.getLogger().info("DEBUG: Running through args: " + Arrays.asList(args).toString());
}
if (args.length > 0) { if (args.length > 0) {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: Argument " + i); Bukkit.getLogger().info("DEBUG: Argument " + i);
}
// get the subcommand corresponding to the arg // get the subcommand corresponding to the arg
if (subCommand.hasSubCommmands()) { if (subCommand.hasSubCommmands()) {
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: This command has subcommands"); Bukkit.getLogger().info("DEBUG: This command has subcommands");
}
Optional<CompositeCommand> sub = subCommand.getSubCommand(args[i]); Optional<CompositeCommand> sub = subCommand.getSubCommand(args[i]);
if (!sub.isPresent()) { if (!sub.isPresent()) {
return subCommand; return subCommand;
} }
// Step down one // Step down one
subCommand = sub.orElse(subCommand); subCommand = sub.orElse(subCommand);
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: Moved to " + subCommand.getLabel()); Bukkit.getLogger().info("DEBUG: Moved to " + subCommand.getLabel());
}
// Set the label // Set the label
subCommand.setLabel(args[i]); subCommand.setLabel(args[i]);
} else { } else {
// We are at the end of the walk // We are at the end of the walk
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: End of traversal"); Bukkit.getLogger().info("DEBUG: End of traversal");
}
return subCommand; return subCommand;
} }
// else continue the loop // else continue the loop
@ -294,17 +302,20 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* @return CompositeCommand or null if none found * @return CompositeCommand or null if none found
*/ */
public Optional<CompositeCommand> getSubCommand(String label) { public Optional<CompositeCommand> getSubCommand(String label) {
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: label = " + label); Bukkit.getLogger().info("DEBUG: label = " + label);
}
for (Map.Entry<String, CompositeCommand> entry : subCommands.entrySet()) { for (Map.Entry<String, CompositeCommand> entry : subCommands.entrySet()) {
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: " + entry.getKey()); Bukkit.getLogger().info("DEBUG: " + entry.getKey());
}
if (entry.getKey().equalsIgnoreCase(label)) return Optional.of(subCommands.get(label)); if (entry.getKey().equalsIgnoreCase(label)) return Optional.of(subCommands.get(label));
} }
// Try aliases // Try aliases
for (Map.Entry<String, CompositeCommand> entry : subCommandAliases.entrySet()) { for (Map.Entry<String, CompositeCommand> entry : subCommandAliases.entrySet()) {
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: alias " + entry.getKey()); Bukkit.getLogger().info("DEBUG: alias " + entry.getKey());
}
if (entry.getKey().equalsIgnoreCase(label)) return Optional.of(subCommandAliases.get(label)); if (entry.getKey().equalsIgnoreCase(label)) return Optional.of(subCommandAliases.get(label));
} }
return Optional.empty(); return Optional.empty();
@ -422,13 +433,15 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
} }
// Check for console and permissions // Check for console and permissions
if (cmd.onlyPlayer && !(sender instanceof Player)) { if (cmd.onlyPlayer && !(sender instanceof Player)) {
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: returning, only for player"); Bukkit.getLogger().info("DEBUG: returning, only for player");
}
return options; return options;
} }
if (!cmd.getPermission().isEmpty() && !sender.hasPermission(cmd.getPermission())) { if (!cmd.getPermission().isEmpty() && !sender.hasPermission(cmd.getPermission())) {
if (DEBUG) if (DEBUG) {
Bukkit.getLogger().info("DEBUG: failed perm check"); Bukkit.getLogger().info("DEBUG: failed perm check");
}
return options; return options;
} }
// Add any tab completion from the subcommand // Add any tab completion from the subcommand