Archived
0

Work on a couple of the todos

This commit is contained in:
Dico
2018-08-12 18:07:43 +01:00
parent 957d6f2434
commit 5bd0970c54
32 changed files with 503 additions and 148 deletions

View File

@@ -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;
}

View File

@@ -210,15 +210,39 @@ 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));
return this;
}
/**
* 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
*

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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 {

View File

@@ -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;
}
}