mirror of
https://github.com/aikar/commands.git
synced 2026-06-15 04:10:36 +00:00
Misc cleanup
This commit is contained in:
@@ -23,9 +23,7 @@
|
||||
|
||||
package co.aikar.commands.example;
|
||||
|
||||
import co.aikar.commands.CommandContexts;
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.contexts.ContextResolver;
|
||||
|
||||
public abstract class SomeObject {
|
||||
@@ -34,6 +32,7 @@ public abstract class SomeObject {
|
||||
SomeObject(Integer thisValue) {
|
||||
this.thisValue = thisValue;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return this.thisValue;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.lang.reflect.Parameter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
public class CommandExecutionContext {
|
||||
private final RegisteredCommand cmd;
|
||||
private final Parameter param;
|
||||
@@ -117,6 +118,7 @@ public class CommandExecutionContext {
|
||||
final Object o = passedArgs.get(key);
|
||||
for (Class<?> clazz : classes) {
|
||||
if (clazz.isInstance(o)) {
|
||||
//noinspection unchecked
|
||||
return (T) o;
|
||||
}
|
||||
}
|
||||
@@ -132,7 +134,7 @@ public class CommandExecutionContext {
|
||||
}
|
||||
|
||||
public String getFlagValue(String flag, String def) {
|
||||
return flags.containsKey(flag) ? flags.get(flag) : def;
|
||||
return flags.getOrDefault(flag, def);
|
||||
}
|
||||
|
||||
public Integer getFlagValue(String flag, Integer def) {
|
||||
@@ -174,80 +176,4 @@ public class CommandExecutionContext {
|
||||
public Map<String, String> getFlags() {
|
||||
return this.flags;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof CommandExecutionContext)) {
|
||||
return false;
|
||||
}
|
||||
final CommandExecutionContext other = (CommandExecutionContext) o;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
final Object this$cmd = this.getCmd();
|
||||
final Object other$cmd = other.getCmd();
|
||||
if (this$cmd == null ? other$cmd != null : !this$cmd.equals(other$cmd)) {
|
||||
return false;
|
||||
}
|
||||
final Object this$param = this.getParam();
|
||||
final Object other$param = other.getParam();
|
||||
if (this$param == null ? other$param != null : !this$param.equals(other$param)) {
|
||||
return false;
|
||||
}
|
||||
final Object this$sender = this.getSender();
|
||||
final Object other$sender = other.getSender();
|
||||
if (this$sender == null ? other$sender != null : !this$sender.equals(other$sender)) {
|
||||
return false;
|
||||
}
|
||||
final Object this$args = this.getArgs();
|
||||
final Object other$args = other.getArgs();
|
||||
if (this$args == null ? other$args != null : !this$args.equals(other$args)) {
|
||||
return false;
|
||||
}
|
||||
if (this.getIndex() != other.getIndex()) {
|
||||
return false;
|
||||
}
|
||||
final Object this$passedArgs = this.getPassedArgs();
|
||||
final Object other$passedArgs = other.getPassedArgs();
|
||||
if (this$passedArgs == null ? other$passedArgs != null : !this$passedArgs.equals(other$passedArgs)) {
|
||||
return false;
|
||||
}
|
||||
final Object this$flags = this.getFlags();
|
||||
final Object other$flags = other.getFlags();
|
||||
if (this$flags == null ? other$flags != null : !this$flags.equals(other$flags)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
final Object $cmd = this.getCmd();
|
||||
result = result * PRIME + ($cmd == null ? 43 : $cmd.hashCode());
|
||||
final Object $param = this.getParam();
|
||||
result = result * PRIME + ($param == null ? 43 : $param.hashCode());
|
||||
final Object $sender = this.getSender();
|
||||
result = result * PRIME + ($sender == null ? 43 : $sender.hashCode());
|
||||
final Object $args = this.getArgs();
|
||||
result = result * PRIME + ($args == null ? 43 : $args.hashCode());
|
||||
result = result * PRIME + this.getIndex();
|
||||
final Object $passedArgs = this.getPassedArgs();
|
||||
result = result * PRIME + ($passedArgs == null ? 43 : $passedArgs.hashCode());
|
||||
final Object $flags = this.getFlags();
|
||||
result = result * PRIME + ($flags == null ? 43 : $flags.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
protected boolean canEqual(Object other) {
|
||||
return other instanceof CommandExecutionContext;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "com.empireminecraft.commands.contexts.CommandExecutionContext(cmd=" + this.getCmd() + ", param=" + this.getParam() + ", sender=" +
|
||||
this.getSender() + ", args=" + this.getArgs() + ", index=" + this.getIndex() + ", passedArgs=" + this.getPassedArgs() + ", flags=" +
|
||||
this.getFlags() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
final class CommandLog {
|
||||
private static final Logger LOGGER = Bukkit.getLogger();
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public interface CommandManager {
|
||||
|
||||
/**
|
||||
* Gets the command completions manager
|
||||
* @return
|
||||
* @return Command Completions
|
||||
*/
|
||||
CommandCompletions getCommandCompletions();
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class RegisteredCommand {
|
||||
final CommandCompletion complete;
|
||||
final int nonSenderAwareResolvers;
|
||||
final int optionalResolvers;
|
||||
CommandTiming timing;
|
||||
private CommandTiming timing;
|
||||
|
||||
RegisteredCommand(BaseCommand scope, String command, Method method, String prefSubCommand) {
|
||||
this.scope = scope;
|
||||
@@ -132,45 +132,41 @@ public class RegisteredCommand {
|
||||
final String parameterName = parameter.getName();
|
||||
final Class<?> type = parameter.getType();
|
||||
final ContextResolver<?> resolver = resolvers[i];
|
||||
if (resolver != null) {
|
||||
CommandExecutionContext context = new CommandExecutionContext(this, parameter, sender, args, i, passedArgs);
|
||||
if (args.isEmpty() && !(isLast && type == String[].class)) {
|
||||
Default def = parameter.getAnnotation(Default.class);
|
||||
Optional opt = parameter.getAnnotation(Optional.class);
|
||||
if (isLast && def != null) {
|
||||
args.add(def.value());
|
||||
} else if (isLast && opt != null) {
|
||||
passedArgs.put(parameterName, resolver instanceof SenderAwareContextResolver ? resolver.getContext(context) : null);
|
||||
continue;
|
||||
} else if (!(resolver instanceof SenderAwareContextResolver)) {
|
||||
scope.showSyntax(sender, this);
|
||||
return;
|
||||
CommandExecutionContext context = new CommandExecutionContext(this, parameter, sender, args, i, passedArgs);
|
||||
if (args.isEmpty() && !(isLast && type == String[].class)) {
|
||||
Default def = parameter.getAnnotation(Default.class);
|
||||
Optional opt = parameter.getAnnotation(Optional.class);
|
||||
if (isLast && def != null) {
|
||||
args.add(def.value());
|
||||
} else if (isLast && opt != null) {
|
||||
passedArgs.put(parameterName, resolver instanceof SenderAwareContextResolver ? resolver.getContext(context) : null);
|
||||
//noinspection UnnecessaryContinue
|
||||
continue;
|
||||
} else if (!(resolver instanceof SenderAwareContextResolver)) {
|
||||
scope.showSyntax(sender, this);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
final Values values = parameter.getAnnotation(Values.class);
|
||||
if (values != null) {
|
||||
String arg = args.get(0);
|
||||
|
||||
final String[] split = CommandPatterns.PIPE.split(values.value());
|
||||
Set<String> possible = Sets.newHashSet();
|
||||
for (String s : split) {
|
||||
List<String> check = this.scope.manager.getCommandCompletions().of(sender, s, arg);
|
||||
if (!check.isEmpty()) {
|
||||
possible.addAll(check.stream().map(String::toLowerCase).collect(Collectors.toList()));
|
||||
} else {
|
||||
possible.add(s.toLowerCase());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final Values values = parameter.getAnnotation(Values.class);
|
||||
if (values != null) {
|
||||
String arg = args.get(0);
|
||||
|
||||
final String[] split = CommandPatterns.PIPE.split(values.value());
|
||||
Set<String> possible = Sets.newHashSet();
|
||||
for (String s : split) {
|
||||
List<String> check = this.scope.manager.getCommandCompletions().of(sender, s, arg);
|
||||
if (!check.isEmpty()) {
|
||||
possible.addAll(check.stream().map(String::toLowerCase).collect(Collectors.toList()));
|
||||
} else {
|
||||
possible.add(s.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
if (!possible.contains(arg.toLowerCase())) {
|
||||
throw new InvalidCommandArgument("Must be one of: " + CommandUtil.join(possible, ", "));
|
||||
}
|
||||
if (!possible.contains(arg.toLowerCase())) {
|
||||
throw new InvalidCommandArgument("Must be one of: " + CommandUtil.join(possible, ", "));
|
||||
}
|
||||
}
|
||||
passedArgs.put(parameterName, resolver.getContext(context));
|
||||
} else {
|
||||
CommandUtil.sendMsg(sender, "&cUnexpected Error. Staff have been notified of the bug.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user