Fix permissions further
This commit is contained in:
@@ -111,12 +111,12 @@ public abstract class Command {
|
||||
return Collections.unmodifiableList(contextFilters);
|
||||
}
|
||||
|
||||
public boolean removeContextFilter(IContextFilter contextFilter) {
|
||||
public Command removeContextFilter(IContextFilter contextFilter) {
|
||||
boolean ret = contextFilters.remove(contextFilter);
|
||||
if (ret) {
|
||||
computeContextFilterPostParameterIndex();
|
||||
}
|
||||
return ret;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void computeContextFilterPostParameterIndex() {
|
||||
|
||||
@@ -2,10 +2,11 @@ package io.dico.dicore.command;
|
||||
|
||||
import io.dico.dicore.command.parameter.IArgumentPreProcessor;
|
||||
import io.dico.dicore.command.parameter.Parameter;
|
||||
import io.dico.dicore.command.parameter.type.ParameterType;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class ExtendedCommand<T extends ExtendedCommand<T>> extends Command {
|
||||
protected final boolean modifiable;
|
||||
protected boolean modifiable;
|
||||
|
||||
public ExtendedCommand() {
|
||||
this(true);
|
||||
@@ -24,6 +25,16 @@ public abstract class ExtendedCommand<T extends ExtendedCommand<T>> extends Comm
|
||||
return modifiable ? (T) super.addParameter(parameter) : newModifiableInstance().addParameter(parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T addContextFilter(IContextFilter contextFilter) {
|
||||
return modifiable ? (T) super.addContextFilter(contextFilter) : newModifiableInstance().addContextFilter(contextFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T removeContextFilter(IContextFilter contextFilter) {
|
||||
return modifiable ? (T) super.removeContextFilter(contextFilter) : newModifiableInstance().removeContextFilter(contextFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T requiredParameters(int requiredParameters) {
|
||||
return modifiable ? (T) super.requiredParameters(requiredParameters) : newModifiableInstance().requiredParameters(requiredParameters);
|
||||
|
||||
@@ -7,7 +7,7 @@ public abstract class InheritingContextFilter implements IContextFilter {
|
||||
|
||||
private static String[] addParent(String[] path, String parent) {
|
||||
String[] out = new String[path.length + 1];
|
||||
System.arraycopy(path, 0, out, 0, path.length);
|
||||
System.arraycopy(path, 0, out, 1, path.length);
|
||||
out[0] = parent;
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PermissionContextFilter implements IContextFilter {
|
||||
doFilter(context, permission);
|
||||
}
|
||||
|
||||
private String getInheritedPermission(String[] components) {
|
||||
public String getInheritedPermission(String[] components) {
|
||||
int insertedAmount = components.length;
|
||||
String[] currentComponents = permissionComponents;
|
||||
int currentAmount = currentComponents.length;
|
||||
@@ -80,7 +80,7 @@ public class PermissionContextFilter implements IContextFilter {
|
||||
|
||||
@Override
|
||||
public void filterSubContext(ExecutionContext subContext, String... path) throws CommandException {
|
||||
if (permissionComponents != null) {
|
||||
if (isInheritable()) {
|
||||
doFilter(subContext, getInheritedPermission(path));
|
||||
}
|
||||
}
|
||||
@@ -90,4 +90,20 @@ public class PermissionContextFilter implements IContextFilter {
|
||||
return Priority.PERMISSION;
|
||||
}
|
||||
|
||||
public boolean isInheritable() {
|
||||
return permissionComponents != null;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public int getComponentInsertionIndex() {
|
||||
return componentInsertionIndex;
|
||||
}
|
||||
|
||||
public String getFailMessage() {
|
||||
return failMessage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
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 io.dico.dicore.command.IContextFilter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class DefaultGroupCommand extends Command {
|
||||
private static final DefaultGroupCommand instance = new DefaultGroupCommand();
|
||||
public class DefaultGroupCommand extends PredefinedCommand<DefaultGroupCommand> {
|
||||
private static final DefaultGroupCommand instance = new DefaultGroupCommand(false);
|
||||
|
||||
public static DefaultGroupCommand getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private DefaultGroupCommand() {
|
||||
|
||||
private DefaultGroupCommand(boolean modifiable) {
|
||||
addContextFilter(IContextFilter.INHERIT_PERMISSIONS);
|
||||
this.modifiable = modifiable;
|
||||
}
|
||||
|
||||
@Override public String execute(CommandSender sender, ExecutionContext context) throws CommandException {
|
||||
@Override
|
||||
protected DefaultGroupCommand newModifiableInstance() {
|
||||
return new DefaultGroupCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(CommandSender sender, ExecutionContext context) throws CommandException {
|
||||
context.getAddress().getChatController().sendHelpMessage(sender, context, context.getAddress(), 1);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ public abstract class PredefinedCommand<T extends PredefinedCommand<T>> extends
|
||||
|
||||
static {
|
||||
registerPredefinedCommandGenerator("help", HelpCommand::registerAsChild);
|
||||
//noinspection StaticInitializerReferencesSubClass
|
||||
registerPredefinedCommandGenerator("syntax", SyntaxCommand::registerAsChild);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user