summaryrefslogtreecommitdiff
path: root/dicore3/command/src/main/java/io/dico/dicore/command/predef
diff options
context:
space:
mode:
Diffstat (limited to 'dicore3/command/src/main/java/io/dico/dicore/command/predef')
-rw-r--r--dicore3/command/src/main/java/io/dico/dicore/command/predef/DefaultGroupCommand.java112
-rw-r--r--dicore3/command/src/main/java/io/dico/dicore/command/predef/HelpCommand.java152
-rw-r--r--dicore3/command/src/main/java/io/dico/dicore/command/predef/PredefinedCommand.java100
-rw-r--r--dicore3/command/src/main/java/io/dico/dicore/command/predef/SyntaxCommand.java72
4 files changed, 218 insertions, 218 deletions
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/predef/DefaultGroupCommand.java b/dicore3/command/src/main/java/io/dico/dicore/command/predef/DefaultGroupCommand.java
index e664cef..6828fcc 100644
--- a/dicore3/command/src/main/java/io/dico/dicore/command/predef/DefaultGroupCommand.java
+++ b/dicore3/command/src/main/java/io/dico/dicore/command/predef/DefaultGroupCommand.java
@@ -1,56 +1,56 @@
-package io.dico.dicore.command.predef;
-
-import io.dico.dicore.command.CommandException;
-import io.dico.dicore.command.ExecutionContext;
-import io.dico.dicore.command.IContextFilter;
-import org.bukkit.command.CommandSender;
-
-public class DefaultGroupCommand extends PredefinedCommand<DefaultGroupCommand> {
- private static final DefaultGroupCommand instance;
- private static final IContextFilter noArgumentFilter;
-
- public static DefaultGroupCommand getInstance() {
- return instance;
- }
-
- private DefaultGroupCommand(boolean modifiable) {
- addContextFilter(IContextFilter.INHERIT_PERMISSIONS);
- addContextFilter(noArgumentFilter);
- this.modifiable = modifiable;
- }
-
- public DefaultGroupCommand() {
- this(true);
- }
-
- @Override
- protected DefaultGroupCommand newModifiableInstance() {
- return new DefaultGroupCommand(true);
- }
-
- @Override
- public String execute(CommandSender sender, ExecutionContext context) throws CommandException {
- context.getAddress().getChatHandler().sendHelpMessage(sender, context, context.getAddress(), 1);
- return null;
- }
-
- static {
- noArgumentFilter = new IContextFilter() {
- @Override
- public void filterContext(ExecutionContext context) throws CommandException {
- if (context.getBuffer().hasNext()) {
- throw new CommandException("No such command: /" + context.getAddress().getAddress()
- + " " + context.getBuffer().next());
- }
- }
-
- @Override
- public Priority getPriority() {
- return Priority.EARLY;
- }
- };
-
- instance = new DefaultGroupCommand(false);
- }
-
-}
+package io.dico.dicore.command.predef;
+
+import io.dico.dicore.command.CommandException;
+import io.dico.dicore.command.ExecutionContext;
+import io.dico.dicore.command.IContextFilter;
+import org.bukkit.command.CommandSender;
+
+public class DefaultGroupCommand extends PredefinedCommand<DefaultGroupCommand> {
+ private static final DefaultGroupCommand instance;
+ private static final IContextFilter noArgumentFilter;
+
+ public static DefaultGroupCommand getInstance() {
+ return instance;
+ }
+
+ private DefaultGroupCommand(boolean modifiable) {
+ addContextFilter(IContextFilter.INHERIT_PERMISSIONS);
+ addContextFilter(noArgumentFilter);
+ this.modifiable = modifiable;
+ }
+
+ public DefaultGroupCommand() {
+ this(true);
+ }
+
+ @Override
+ protected DefaultGroupCommand newModifiableInstance() {
+ return new DefaultGroupCommand(true);
+ }
+
+ @Override
+ public String execute(CommandSender sender, ExecutionContext context) throws CommandException {
+ context.getAddress().getChatHandler().sendHelpMessage(sender, context, context.getAddress(), 1);
+ return null;
+ }
+
+ static {
+ noArgumentFilter = new IContextFilter() {
+ @Override
+ public void filterContext(ExecutionContext context) throws CommandException {
+ if (context.getBuffer().hasNext()) {
+ throw new CommandException("No such command: /" + context.getAddress().getAddress()
+ + " " + context.getBuffer().next());
+ }
+ }
+
+ @Override
+ public Priority getPriority() {
+ return Priority.EARLY;
+ }
+ };
+
+ instance = new DefaultGroupCommand(false);
+ }
+
+}
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/predef/HelpCommand.java b/dicore3/command/src/main/java/io/dico/dicore/command/predef/HelpCommand.java
index def0db1..985e055 100644
--- a/dicore3/command/src/main/java/io/dico/dicore/command/predef/HelpCommand.java
+++ b/dicore3/command/src/main/java/io/dico/dicore/command/predef/HelpCommand.java
@@ -1,76 +1,76 @@
-package io.dico.dicore.command.predef;
-
-import io.dico.dicore.command.*;
-import io.dico.dicore.command.annotation.Range;
-import io.dico.dicore.command.parameter.ArgumentBuffer;
-import io.dico.dicore.command.parameter.Parameter;
-import io.dico.dicore.command.parameter.type.NumberParameterType;
-import org.bukkit.command.CommandSender;
-
-/**
- * The help command
- */
-public class HelpCommand extends PredefinedCommand<HelpCommand> {
- private static final Parameter<Integer, Range.Memory> pageParameter;
- public static final HelpCommand INSTANCE;
-
- private HelpCommand(boolean modifiable) {
- super(modifiable);
- getParameterList().addParameter(pageParameter);
- getParameterList().setRequiredCount(0);
- setDescription("Shows this help page");
- }
-
- @Override
- protected HelpCommand newModifiableInstance() {
- return new HelpCommand(true);
- }
-
- @Override
- public String execute(CommandSender sender, ExecutionContext context) throws CommandException {
- ICommandAddress target = context.getAddress();
- if (context.getAddress().getCommand() == this) {
- target = target.getParent();
- }
-
- context.getAddress().getChatHandler().sendHelpMessage(sender, context, target, context.<Integer>get("page") - 1);
- return null;
- }
-
- public static void registerAsChild(ICommandAddress address) {
- registerAsChild(address, "help");
- }
-
- public static void registerAsChild(ICommandAddress address, String main, String... aliases) {
- ((ModifiableCommandAddress) address).addChild(new ChildCommandAddress(INSTANCE, main, aliases));
- }
-
- static {
- pageParameter = new Parameter<>("page", "the page number",
- new NumberParameterType<Integer>(Integer.TYPE) {
- @Override
- protected Integer parse(String input) throws NumberFormatException {
- return Integer.parseInt(input);
- }
-
- @Override
- protected Integer select(Number number) {
- return number.intValue();
- }
-
- @Override
- public Integer parseForContext(Parameter<Integer, Range.Memory> parameter, ExecutionContext context, ArgumentBuffer buffer) throws CommandException {
- if (context.getAddress().getCommand() == null || context.getAddress().getCommand().getClass() != HelpCommand.class) {
- // An address was executed with its help command as target
- buffer.next();
- return 1;
- }
- return parse(parameter, context.getSender(), buffer);
- }
- },
- new Range.Memory(1, Integer.MAX_VALUE, 1));
-
- INSTANCE = new HelpCommand(false);
- }
-
-}
+package io.dico.dicore.command.predef;
+
+import io.dico.dicore.command.*;
+import io.dico.dicore.command.annotation.Range;
+import io.dico.dicore.command.parameter.ArgumentBuffer;
+import io.dico.dicore.command.parameter.Parameter;
+import io.dico.dicore.command.parameter.type.NumberParameterType;
+import org.bukkit.command.CommandSender;
+
+/**
+ * The help command
+ */
+public class HelpCommand extends PredefinedCommand<HelpCommand> {
+ private static final Parameter<Integer, Range.Memory> pageParameter;
+ public static final HelpCommand INSTANCE;
+
+ private HelpCommand(boolean modifiable) {
+ super(modifiable);
+ getParameterList().addParameter(pageParameter);
+ getParameterList().setRequiredCount(0);
+ setDescription("Shows this help page");
+ }
+
+ @Override
+ protected HelpCommand newModifiableInstance() {
+ return new HelpCommand(true);
+ }
+
+ @Override
+ public String execute(CommandSender sender, ExecutionContext context) throws CommandException {
+ ICommandAddress target = context.getAddress();
+ if (context.getAddress().getCommand() == this) {
+ target = target.getParent();
+ }
+
+ context.getAddress().getChatHandler().sendHelpMessage(sender, context, target, context.<Integer>get("page") - 1);
+ return null;
+ }
+
+ public static void registerAsChild(ICommandAddress address) {
+ registerAsChild(address, "help");
+ }
+
+ public static void registerAsChild(ICommandAddress address, String main, String... aliases) {
+ ((ModifiableCommandAddress) address).addChild(new ChildCommandAddress(INSTANCE, main, aliases));
+ }
+
+ static {
+ pageParameter = new Parameter<>("page", "the page number",
+ new NumberParameterType<Integer>(Integer.TYPE) {
+ @Override
+ protected Integer parse(String input) throws NumberFormatException {
+ return Integer.parseInt(input);
+ }
+
+ @Override
+ protected Integer select(Number number) {
+ return number.intValue();
+ }
+
+ @Override
+ public Integer parseForContext(Parameter<Integer, Range.Memory> parameter, ExecutionContext context, ArgumentBuffer buffer) throws CommandException {
+ if (context.getAddress().getCommand() == null || context.getAddress().getCommand().getClass() != HelpCommand.class) {
+ // An address was executed with its help command as target
+ buffer.next();
+ return 1;
+ }
+ return parse(parameter, context.getSender(), buffer);
+ }
+ },
+ new Range.Memory(1, Integer.MAX_VALUE, 1));
+
+ INSTANCE = new HelpCommand(false);
+ }
+
+}
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/predef/PredefinedCommand.java b/dicore3/command/src/main/java/io/dico/dicore/command/predef/PredefinedCommand.java
index 4340356..b7c5587 100644
--- a/dicore3/command/src/main/java/io/dico/dicore/command/predef/PredefinedCommand.java
+++ b/dicore3/command/src/main/java/io/dico/dicore/command/predef/PredefinedCommand.java
@@ -1,50 +1,50 @@
-package io.dico.dicore.command.predef;
-
-import io.dico.dicore.command.CommandBuilder;
-import io.dico.dicore.command.ExtendedCommand;
-import io.dico.dicore.command.ICommandAddress;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.Consumer;
-
-/**
- * Marker class for commands that are generated. These commands can be replaced using methods in {@link CommandBuilder}
- */
-public abstract class PredefinedCommand<T extends PredefinedCommand<T>> extends ExtendedCommand<T> {
- static final Map<String, Consumer<ICommandAddress>> predefinedCommandGenerators = new HashMap<>();
-
- /**
- * Get a predefined command
- *
- * @param name the name
- * @return the subscriber
- */
- public static Consumer<ICommandAddress> getPredefinedCommandGenerator(String name) {
- return predefinedCommandGenerators.get(name);
- }
-
- /**
- * Register a predefined command
- *
- * @param name the name
- * @param consumer the generator which adds the child to the address
- * @return true if and only if the subscriber was registered (false if the name exists)
- */
- public static boolean registerPredefinedCommandGenerator(String name, Consumer<ICommandAddress> consumer) {
- return predefinedCommandGenerators.putIfAbsent(name, consumer) == null;
- }
-
- static {
- registerPredefinedCommandGenerator("help", HelpCommand::registerAsChild);
- //noinspection StaticInitializerReferencesSubClass
- registerPredefinedCommandGenerator("syntax", SyntaxCommand::registerAsChild);
- }
-
- public PredefinedCommand() {
- }
-
- public PredefinedCommand(boolean modifiable) {
- super(modifiable);
- }
-}
+package io.dico.dicore.command.predef;
+
+import io.dico.dicore.command.CommandBuilder;
+import io.dico.dicore.command.ExtendedCommand;
+import io.dico.dicore.command.ICommandAddress;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
+
+/**
+ * Marker class for commands that are generated. These commands can be replaced using methods in {@link CommandBuilder}
+ */
+public abstract class PredefinedCommand<T extends PredefinedCommand<T>> extends ExtendedCommand<T> {
+ static final Map<String, Consumer<ICommandAddress>> predefinedCommandGenerators = new HashMap<>();
+
+ /**
+ * Get a predefined command
+ *
+ * @param name the name
+ * @return the subscriber
+ */
+ public static Consumer<ICommandAddress> getPredefinedCommandGenerator(String name) {
+ return predefinedCommandGenerators.get(name);
+ }
+
+ /**
+ * Register a predefined command
+ *
+ * @param name the name
+ * @param consumer the generator which adds the child to the address
+ * @return true if and only if the subscriber was registered (false if the name exists)
+ */
+ public static boolean registerPredefinedCommandGenerator(String name, Consumer<ICommandAddress> consumer) {
+ return predefinedCommandGenerators.putIfAbsent(name, consumer) == null;
+ }
+
+ static {
+ registerPredefinedCommandGenerator("help", HelpCommand::registerAsChild);
+ //noinspection StaticInitializerReferencesSubClass
+ registerPredefinedCommandGenerator("syntax", SyntaxCommand::registerAsChild);
+ }
+
+ public PredefinedCommand() {
+ }
+
+ public PredefinedCommand(boolean modifiable) {
+ super(modifiable);
+ }
+}
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/predef/SyntaxCommand.java b/dicore3/command/src/main/java/io/dico/dicore/command/predef/SyntaxCommand.java
index 7ae8638..8532584 100644
--- a/dicore3/command/src/main/java/io/dico/dicore/command/predef/SyntaxCommand.java
+++ b/dicore3/command/src/main/java/io/dico/dicore/command/predef/SyntaxCommand.java
@@ -1,36 +1,36 @@
-package io.dico.dicore.command.predef;
-
-import io.dico.dicore.command.*;
-import org.bukkit.command.CommandSender;
-
-/**
- * The syntax command
- */
-public class SyntaxCommand extends PredefinedCommand<SyntaxCommand> {
- public static final SyntaxCommand INSTANCE = new SyntaxCommand(false);
-
- private SyntaxCommand(boolean modifiable) {
- super(modifiable);
- setDescription("Describes how to use the command");
- }
-
- @Override
- protected SyntaxCommand newModifiableInstance() {
- return new SyntaxCommand(true);
- }
-
- @Override
- public String execute(CommandSender sender, ExecutionContext context) throws CommandException {
- context.getAddress().getChatHandler().sendSyntaxMessage(sender, context, context.getAddress().getParent());
- return null;
- }
-
- public static void registerAsChild(ICommandAddress address) {
- registerAsChild(address, "syntax");
- }
-
- public static void registerAsChild(ICommandAddress address, String main, String... aliases) {
- ((ModifiableCommandAddress) address).addChild(new ChildCommandAddress(INSTANCE, main, aliases));
- }
-
-}
+package io.dico.dicore.command.predef;
+
+import io.dico.dicore.command.*;
+import org.bukkit.command.CommandSender;
+
+/**
+ * The syntax command
+ */
+public class SyntaxCommand extends PredefinedCommand<SyntaxCommand> {
+ public static final SyntaxCommand INSTANCE = new SyntaxCommand(false);
+
+ private SyntaxCommand(boolean modifiable) {
+ super(modifiable);
+ setDescription("Describes how to use the command");
+ }
+
+ @Override
+ protected SyntaxCommand newModifiableInstance() {
+ return new SyntaxCommand(true);
+ }
+
+ @Override
+ public String execute(CommandSender sender, ExecutionContext context) throws CommandException {
+ context.getAddress().getChatHandler().sendSyntaxMessage(sender, context, context.getAddress().getParent());
+ return null;
+ }
+
+ public static void registerAsChild(ICommandAddress address) {
+ registerAsChild(address, "syntax");
+ }
+
+ public static void registerAsChild(ICommandAddress address, String main, String... aliases) {
+ ((ModifiableCommandAddress) address).addChild(new ChildCommandAddress(INSTANCE, main, aliases));
+ }
+
+}