Renamed some command manager methods to be more descriptive.

This commit is contained in:
sk89q 2014-06-28 16:39:20 -07:00
parent 620a4a21a1
commit 205fee3c36
6 changed files with 46 additions and 46 deletions

View File

@ -97,43 +97,43 @@ public final class CommandManager {
dispatcher = new CommandGraph() dispatcher = new CommandGraph()
.builder(builder) .builder(builder)
.commands() .commands()
.build(new BiomeCommands(worldEdit)) .registerMethods(new BiomeCommands(worldEdit))
.build(new ChunkCommands(worldEdit)) .registerMethods(new ChunkCommands(worldEdit))
.build(new ClipboardCommands(worldEdit)) .registerMethods(new ClipboardCommands(worldEdit))
.build(new GeneralCommands(worldEdit)) .registerMethods(new GeneralCommands(worldEdit))
.build(new GenerationCommands(worldEdit)) .registerMethods(new GenerationCommands(worldEdit))
.build(new HistoryCommands(worldEdit)) .registerMethods(new HistoryCommands(worldEdit))
.build(new NavigationCommands(worldEdit)) .registerMethods(new NavigationCommands(worldEdit))
.build(new RegionCommands(worldEdit)) .registerMethods(new RegionCommands(worldEdit))
.build(new ScriptingCommands(worldEdit)) .registerMethods(new ScriptingCommands(worldEdit))
.build(new SelectionCommands(worldEdit)) .registerMethods(new SelectionCommands(worldEdit))
.build(new SnapshotUtilCommands(worldEdit)) .registerMethods(new SnapshotUtilCommands(worldEdit))
.build(new ToolUtilCommands(worldEdit)) .registerMethods(new ToolUtilCommands(worldEdit))
.build(new ToolCommands(worldEdit)) .registerMethods(new ToolCommands(worldEdit))
.build(new UtilityCommands(worldEdit)) .registerMethods(new UtilityCommands(worldEdit))
.group("worldedit", "we") .group("worldedit", "we")
.describe("WorldEdit commands") .describeAs("WorldEdit commands")
.build(new WorldEditCommands(worldEdit)) .registerMethods(new WorldEditCommands(worldEdit))
.parent() .parent()
.group("schematic", "schem", "/schematic", "/schem") .group("schematic", "schem", "/schematic", "/schem")
.describe("Schematic commands for saving/loading areas") .describeAs("Schematic commands for saving/loading areas")
.build(new SchematicCommands(worldEdit)) .registerMethods(new SchematicCommands(worldEdit))
.parent() .parent()
.group("snapshot", "snap") .group("snapshot", "snap")
.describe("Schematic commands for saving/loading areas") .describeAs("Schematic commands for saving/loading areas")
.build(new SnapshotCommands(worldEdit)) .registerMethods(new SnapshotCommands(worldEdit))
.parent() .parent()
.group("brush", "br") .group("brush", "br")
.describe("Brushing commands") .describeAs("Brushing commands")
.build(new BrushCommands(worldEdit)) .registerMethods(new BrushCommands(worldEdit))
.parent() .parent()
.group("superpickaxe", "pickaxe", "sp") .group("superpickaxe", "pickaxe", "sp")
.describe("Super-pickaxe commands") .describeAs("Super-pickaxe commands")
.build(new SuperPickaxeCommands(worldEdit)) .registerMethods(new SuperPickaxeCommands(worldEdit))
.parent() .parent()
.group("tool") .group("tool")
.describe("Bind functions to held items") .describeAs("Bind functions to held items")
.build(new ToolCommands(worldEdit)) .registerMethods(new ToolCommands(worldEdit))
.parent() .parent()
.graph() .graph()
.getDispatcher(); .getDispatcher();

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.util.command; package com.sk89q.worldedit.util.command;
import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
/** /**
@ -32,7 +33,7 @@ public interface Dispatcher extends CommandCallable {
* @param callable the command executor * @param callable the command executor
* @param alias a list of aliases, where the first alias is the primary name * @param alias a list of aliases, where the first alias is the primary name
*/ */
void register(CommandCallable callable, String... alias); void registerCommand(CommandCallable callable, String... alias);
/** /**
* Get a list of command registrations. * Get a list of command registrations.
@ -53,22 +54,23 @@ public interface Dispatcher extends CommandCallable {
Collection<String> getPrimaryAliases(); Collection<String> getPrimaryAliases();
/** /**
* Get a list of all the command aliases. * Get a list of all the command aliases, which includes the primary alias.
* *
* <p>A command may have more than one alias assigned to it. The returned * <p>A command may have more than one alias assigned to it. The returned
* collection cannot be modified.</p> * collection cannot be modified.</p>
* *
* @return a list of aliases * @return a list of aliases
*/ */
Collection<String> getAllAliases(); Collection<String> getAliases();
/** /**
* Get the {@link CommandCallable} associated with an alias. * Get the {@link CommandCallable} associated with an alias. Returns
* null if no command is named by the given alias.
* *
* @param alias the alias * @param alias the alias
* @return the command mapping * @return the command mapping (null if not found)
*/ */
CommandMapping get(String alias); @Nullable CommandMapping get(String alias);
/** /**
* Returns whether the dispatcher contains a registered command for the given alias. * Returns whether the dispatcher contains a registered command for the given alias.

View File

@ -37,7 +37,7 @@ public class SimpleDispatcher implements Dispatcher {
private final SimpleDescription description = new SimpleDescription(); private final SimpleDescription description = new SimpleDescription();
@Override @Override
public void register(CommandCallable callable, String... alias) { public void registerCommand(CommandCallable callable, String... alias) {
CommandMapping mapping = new CommandMapping(callable, alias); CommandMapping mapping = new CommandMapping(callable, alias);
// Check for replacements // Check for replacements
@ -61,7 +61,7 @@ public class SimpleDispatcher implements Dispatcher {
} }
@Override @Override
public Set<String> getAllAliases() { public Set<String> getAliases() {
return Collections.unmodifiableSet(commands.keySet()); return Collections.unmodifiableSet(commands.keySet());
} }
@ -124,13 +124,13 @@ public class SimpleDispatcher implements Dispatcher {
String[] split = CommandContext.split(arguments); String[] split = CommandContext.split(arguments);
if (split.length == 0) { if (split.length == 0) {
return new ArrayList<String>(getAllAliases()); return new ArrayList<String>(getAliases());
} else if (split.length == 1) { } else if (split.length == 1) {
String prefix = split[0]; String prefix = split[0];
if (!prefix.isEmpty()) { if (!prefix.isEmpty()) {
List<String> suggestions = new ArrayList<String>(); List<String> suggestions = new ArrayList<String>();
for (String alias : getAllAliases()) { for (String alias : getAliases()) {
if (alias.startsWith(prefix)) { if (alias.startsWith(prefix)) {
suggestions.add(alias); suggestions.add(alias);
} }
@ -138,7 +138,7 @@ public class SimpleDispatcher implements Dispatcher {
return suggestions; return suggestions;
} else { } else {
return new ArrayList<String>(getAllAliases()); return new ArrayList<String>(getAliases());
} }
} else { } else {
String subCommand = split[0]; String subCommand = split[0];

View File

@ -62,7 +62,7 @@ public class CommandGraph {
/** /**
* Set the {@link ParametricBuilder} used for calls to * Set the {@link ParametricBuilder} used for calls to
* {@link DispatcherNode#build(Object)}. * {@link DispatcherNode#registerMethods(Object)}.
* *
* @param builder the builder, or null * @param builder the builder, or null
* @return this object * @return this object

View File

@ -56,10 +56,8 @@ public class DispatcherNode {
* @param description the description * @param description the description
* @return this object * @return this object
*/ */
public DispatcherNode describe(String description) { public DispatcherNode describeAs(String description) {
if (dispatcher instanceof SimpleDispatcher) { dispatcher.getDescription().setDescription(description);
((SimpleDispatcher) dispatcher).getDescription().setDescription(description);
}
return this; return this;
} }
@ -70,7 +68,7 @@ public class DispatcherNode {
* @param alias the list of aliases, where the first alias is the primary one * @param alias the list of aliases, where the first alias is the primary one
*/ */
public void register(CommandCallable callable, String... alias) { public void register(CommandCallable callable, String... alias) {
dispatcher.register(callable, alias); dispatcher.registerCommand(callable, alias);
} }
/** /**
@ -81,7 +79,7 @@ public class DispatcherNode {
* @return this object * @return this object
* @see ParametricBuilder#registerMethodsAsCommands(com.sk89q.worldedit.util.command.Dispatcher, Object) * @see ParametricBuilder#registerMethodsAsCommands(com.sk89q.worldedit.util.command.Dispatcher, Object)
*/ */
public DispatcherNode build(Object object) { public DispatcherNode registerMethods(Object object) {
ParametricBuilder builder = graph.getBuilder(); ParametricBuilder builder = graph.getBuilder();
if (builder == null) { if (builder == null) {
throw new RuntimeException("No ParametricBuilder set"); throw new RuntimeException("No ParametricBuilder set");
@ -101,7 +99,7 @@ public class DispatcherNode {
*/ */
public DispatcherNode group(String... alias) { public DispatcherNode group(String... alias) {
SimpleDispatcher command = new SimpleDispatcher(); SimpleDispatcher command = new SimpleDispatcher();
getDispatcher().register(command, alias); getDispatcher().registerCommand(command, alias);
return new DispatcherNode(graph, this, command); return new DispatcherNode(graph, this, command);
} }

View File

@ -151,7 +151,7 @@ public class ParametricBuilder {
Command definition = method.getAnnotation(Command.class); Command definition = method.getAnnotation(Command.class);
if (definition != null) { if (definition != null) {
CommandCallable callable = build(object, method, definition); CommandCallable callable = build(object, method, definition);
dispatcher.register(callable, definition.aliases()); dispatcher.registerCommand(callable, definition.aliases());
} }
} }
} }