/** * Create a new builder. * * <p>This method will install {@link PrimitiveBindings} and * {@link StandardBindings} and default bindings.</p> */ public ParametricBuilder() { addBinding(new PrimitiveBindings()); addBinding(new StandardBindings()); }
/** * Build a list of commands from methods specially annotated with {@link Command} * (and other relevant annotations) and register them all with the given * {@link Dispatcher}. * * @param dispatcher the dispatcher to register commands with * @param object the object contain the methods * @throws ParametricException thrown if the commands cannot be registered */ public void registerMethodsAsCommands(Dispatcher dispatcher, Object object) throws ParametricException { for (Method method : object.getClass().getDeclaredMethods()) { Command definition = method.getAnnotation(Command.class); if (definition != null) { CommandCallable callable = build(object, method, definition); dispatcher.registerCommand(callable, definition.aliases()); } } }
@Override public boolean testPermission(CommandLocals locals) { if (commandPermissions != null) { for (String perm : commandPermissions.value()) { if (builder.getAuthorizer().testPermission(locals, perm)) { return true; } } return false; } else { return true; } }
ParametricBuilder builder = new ParametricBuilder(); builder.setAuthorizer(new ActorAuthorizer()); builder.setDefaultCompleter(new UserCommandCompleter(platformManager)); builder.addBinding(new WorldEditBinding(worldEdit)); builder.addInvokeListener(new LegacyCommandsHandler()); builder.addInvokeListener(new CommandLoggingHandler(worldEdit, commandLog));
String[] names = builder.getParanamer().lookupParameterNames(method, false); Type[] types = method.getGenericParameterTypes(); parameters = new ParameterData[types.length]; parameter.setBinding(builder.getBindings().get(annotation.annotationType())); parameter.setClassifier(annotation); parameter.setBinding(builder.getBindings().get(type)); description.overrideUsage(!definition.usage().isEmpty() ? definition.usage() : null); for (InvokeListener listener : builder.getInvokeListeners()) { listener.updateDescription(object, method, parameters, description);
@Override public List<String> getSuggestions(String arguments, CommandLocals locals) throws CommandException { return builder.getDefaultCompleter().getSuggestions(arguments, locals); }
/** * Build and register a command with this dispatcher using the * {@link ParametricBuilder} assigned on the root {@link CommandGraph}. * * @param object the object provided to the {@link ParametricBuilder} * @return this object * @see ParametricBuilder#registerMethodsAsCommands(com.sk89q.worldedit.util.command.Dispatcher, Object) */ public DispatcherNode registerMethods(Object object) { ParametricBuilder builder = graph.getBuilder(); if (builder == null) { throw new RuntimeException("No ParametricBuilder set"); } builder.registerMethodsAsCommands(getDispatcher(), object); return this; }
for (InvokeListener listener : builder.getInvokeListeners()) { InvokeHandler handler = listener.createInvokeHandler(); handlers.add(handler);