diff options
author | Dico Karssiens <dico.karssiens@gmail.com> | 2019-01-10 18:52:51 +0000 |
---|---|---|
committer | Dico Karssiens <dico.karssiens@gmail.com> | 2019-01-10 18:52:51 +0000 |
commit | 37fa1f9bbfc852dfa67862cde3d11a4e5415db11 (patch) | |
tree | 9350ab43d11b294cd7218fec3b61fa83ea3beda8 /dicore3/command/src/main/java/io/dico/dicore/command/predef/HelpCommand.java | |
parent | d80f69488656485a8b93b4982e678ed62c5df96b (diff) | |
parent | 778e301efc09eb8326146a084bb6788be748e6f1 (diff) |
Diffstat (limited to 'dicore3/command/src/main/java/io/dico/dicore/command/predef/HelpCommand.java')
-rw-r--r-- | dicore3/command/src/main/java/io/dico/dicore/command/predef/HelpCommand.java | 152 |
1 files changed, 76 insertions, 76 deletions
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);
+ }
+
+}
|