diff options
Diffstat (limited to 'dicore3/command/src/main/java/io/dico')
6 files changed, 58 insertions, 4 deletions
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/ChildCommandAddress.java b/dicore3/command/src/main/java/io/dico/dicore/command/ChildCommandAddress.java index 7593492..73d82ca 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/ChildCommandAddress.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/ChildCommandAddress.java @@ -1,5 +1,6 @@ package io.dico.dicore.command; +import io.dico.dicore.command.predef.DefaultGroupCommand; import io.dico.dicore.command.predef.HelpCommand; import java.util.*; @@ -23,7 +24,7 @@ public class ChildCommandAddress extends ModifiableCommandAddress { } public static ChildCommandAddress newPlaceHolderCommand(String name, String... aliases) { - ChildCommandAddress rv = new ChildCommandAddress(null, name, aliases); + ChildCommandAddress rv = new ChildCommandAddress(DefaultGroupCommand.getInstance(), name, aliases); HelpCommand.registerAsChild(rv); return rv; } diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/CommandBuilder.java b/dicore3/command/src/main/java/io/dico/dicore/command/CommandBuilder.java index 0ffc960..e72d478 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/CommandBuilder.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/CommandBuilder.java @@ -210,9 +210,11 @@ public final class CommandBuilder { * @param shortDescription a short description * @param description the lines of a full description. * @return this + * @throws IllegalStateException if the current group has no command */ public CommandBuilder setGroupDescription(String shortDescription, String... description) { Command command = cur.getCommand(); + if (command == null) throw new IllegalStateException(); cur.setCommand(command .setShortDescription(shortDescription) .setDescription(description)); @@ -220,6 +222,28 @@ public final class CommandBuilder { } /** + * Add a context filter to the command of the current group + * @return this + * @throws IllegalStateException if the current group has no command + */ + public CommandBuilder addContextFilter(IContextFilter contextFilter) { + Command command = cur.getCommand(); + if (command == null) throw new IllegalStateException(); + cur.setCommand(command + .addContextFilter(contextFilter)); + return this; + } + + /** + * Add a required permission to the command of the current group + * @return this + * @throws IllegalStateException if the current group has no command + */ + public CommandBuilder addRequiredPermission(String permission) { + return addContextFilter(IContextFilter.permission(permission)); + } + + /** * Jump up a level in the address * * @return this diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/ModifiableCommandAddress.java b/dicore3/command/src/main/java/io/dico/dicore/command/ModifiableCommandAddress.java index 698eee8..8c2ab67 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/ModifiableCommandAddress.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/ModifiableCommandAddress.java @@ -2,6 +2,7 @@ package io.dico.dicore.command; import io.dico.dicore.command.chat.ChatControllers; import io.dico.dicore.command.chat.IChatController; +import io.dico.dicore.command.predef.DefaultGroupCommand; import io.dico.dicore.command.predef.HelpCommand; import io.dico.dicore.command.predef.PredefinedCommand; @@ -32,7 +33,7 @@ public abstract class ModifiableCommandAddress implements ICommandAddress { @Override public boolean hasUserDeclaredCommand() { Command command = getCommand(); - return command != null && !(command instanceof PredefinedCommand); + return command != null && !(command instanceof PredefinedCommand) && !(command instanceof DefaultGroupCommand); } @Override diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/RootCommandAddress.java b/dicore3/command/src/main/java/io/dico/dicore/command/RootCommandAddress.java index 91dcc5b..6d38174 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/RootCommandAddress.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/RootCommandAddress.java @@ -1,6 +1,7 @@ package io.dico.dicore.command; import io.dico.dicore.command.parameter.ArgumentBuffer; +import io.dico.dicore.command.predef.DefaultGroupCommand; import io.dico.dicore.command.registration.BukkitCommand; import org.bukkit.Location; import org.bukkit.command.CommandSender; @@ -167,10 +168,10 @@ public class RootCommandAddress extends ModifiableCommandAddress implements ICom ModifiableCommandAddress targetAddress = getCommandTarget(sender, buffer); Command target = targetAddress.getCommand(); - if (target == null) { + if (target == null || target instanceof DefaultGroupCommand) { if (targetAddress.hasHelpCommand()) { target = targetAddress.getHelpCommand().getCommand(); - } else { + } else if (target == null){ return false; } } diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/annotation/RequirePermissions.java b/dicore3/command/src/main/java/io/dico/dicore/command/annotation/RequirePermissions.java index 0fbe9a4..d2ba782 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/annotation/RequirePermissions.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/annotation/RequirePermissions.java @@ -7,6 +7,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * If this annotation is not present, inheriting permissions is default. + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface RequirePermissions { 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 new file mode 100644 index 0000000..3d96a7d --- /dev/null +++ b/dicore3/command/src/main/java/io/dico/dicore/command/predef/DefaultGroupCommand.java @@ -0,0 +1,24 @@ +package io.dico.dicore.command.predef; + +import io.dico.dicore.command.Command; +import io.dico.dicore.command.CommandException; +import io.dico.dicore.command.ExecutionContext; +import org.bukkit.command.CommandSender; + +public class DefaultGroupCommand extends Command { + private static final DefaultGroupCommand instance = new DefaultGroupCommand(); + + public static DefaultGroupCommand getInstance() { + return instance; + } + + private DefaultGroupCommand() { + + } + + @Override public String execute(CommandSender sender, ExecutionContext context) throws CommandException { + context.getAddress().getChatController().sendHelpMessage(sender, context, context.getAddress(), 1); + return null; + } + +} |