More deprecation removal

This commit is contained in:
Matthew Miller
2018-06-16 16:36:55 +10:00
parent 20bf6e079b
commit aaaf2d5678
152 changed files with 701 additions and 1150 deletions

View File

@ -34,8 +34,8 @@ public class CommandContext {
protected final List<Integer> originalArgIndices;
protected final String[] originalArgs;
protected final Set<Character> booleanFlags = new HashSet<Character>();
protected final Map<Character, String> valueFlags = new HashMap<Character, String>();
protected final Set<Character> booleanFlags = new HashSet<>();
protected final Map<Character, String> valueFlags = new HashMap<>();
protected final SuggestionContext suggestionContext;
protected final CommandLocals locals;
@ -103,8 +103,8 @@ public class CommandContext {
SuggestionContext suggestionContext = SuggestionContext.hangingValue();
// Eliminate empty args and combine multiword args first
List<Integer> argIndexList = new ArrayList<Integer>(args.length);
List<String> argList = new ArrayList<String>(args.length);
List<Integer> argIndexList = new ArrayList<>(args.length);
List<String> argList = new ArrayList<>(args.length);
for (int i = 1; i < args.length; ++i) {
isHanging = false;
@ -152,8 +152,8 @@ public class CommandContext {
// Then flags
this.originalArgIndices = new ArrayList<Integer>(argIndexList.size());
this.parsedArgs = new ArrayList<String>(argList.size());
this.originalArgIndices = new ArrayList<>(argIndexList.size());
this.parsedArgs = new ArrayList<>(argList.size());
if (parseFlags) {
for (int nextArg = 0; nextArg < argList.size(); ) {

View File

@ -28,7 +28,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class CommandException extends Exception {
private List<String> commandStack = new ArrayList<String>();
private List<String> commandStack = new ArrayList<>();
public CommandException() {
super();

View File

@ -24,7 +24,7 @@ import java.util.Map;
public class CommandLocals {
private final Map<Object, Object> locals = new HashMap<Object, Object>();
private final Map<Object, Object> locals = new HashMap<>();
public boolean containsKey(Object key) {
return locals.containsKey(key);

View File

@ -72,18 +72,18 @@ public abstract class CommandsManager<T> {
* the key of the command name (one for each alias) with the
* method.
*/
protected Map<Method, Map<String, Method>> commands = new HashMap<Method, Map<String, Method>>();
protected Map<Method, Map<String, Method>> commands = new HashMap<>();
/**
* Used to store the instances associated with a method.
*/
protected Map<Method, Object> instances = new HashMap<Method, Object>();
protected Map<Method, Object> instances = new HashMap<>();
/**
* Mapping of commands (not including aliases) with a description. This
* is only for top level commands.
*/
protected Map<String, String> descs = new HashMap<String, String>();
protected Map<String, String> descs = new HashMap<>();
/**
* Stores the injector used to getInstance.
@ -94,7 +94,7 @@ public abstract class CommandsManager<T> {
* Mapping of commands (not including aliases) with a description. This
* is only for top level commands.
*/
protected Map<String, String> helpMessages = new HashMap<String, String>();
protected Map<String, String> helpMessages = new HashMap<>();
/**
* Register an class that contains commands (denoted by {@link Command}.
@ -141,11 +141,7 @@ public abstract class CommandsManager<T> {
Object obj = getInjector().getInstance(cls);
return registerMethods(cls, parent, obj);
}
} catch (InvocationTargetException e) {
logger.log(Level.SEVERE, "Failed to register commands", e);
} catch (IllegalAccessException e) {
logger.log(Level.SEVERE, "Failed to register commands", e);
} catch (InstantiationException e) {
} catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
logger.log(Level.SEVERE, "Failed to register commands", e);
}
return null;
@ -161,14 +157,14 @@ public abstract class CommandsManager<T> {
*/
private List<Command> registerMethods(Class<?> cls, Method parent, Object obj) {
Map<String, Method> map;
List<Command> registered = new ArrayList<Command>();
List<Command> registered = new ArrayList<>();
// Make a new hash map to cache the commands for this class
// as looking up methods via reflection is fairly slow
if (commands.containsKey(parent)) {
map = commands.get(parent);
} else {
map = new HashMap<String, Method>();
map = new HashMap<>();
commands.put(parent, map);
}
@ -359,7 +355,7 @@ public abstract class CommandsManager<T> {
command.append("<");
Set<String> allowedCommands = new HashSet<String>();
Set<String> allowedCommands = new HashSet<>();
for (Map.Entry<String, Method> entry : map.entrySet()) {
Method childMethod = entry.getValue();
@ -479,10 +475,10 @@ public abstract class CommandsManager<T> {
String[] newArgs = new String[args.length - level];
System.arraycopy(args, level, newArgs, 0, args.length - level);
final Set<Character> valueFlags = new HashSet<Character>();
final Set<Character> valueFlags = new HashSet<>();
char[] flags = cmd.flags().toCharArray();
Set<Character> newFlags = new HashSet<Character>();
Set<Character> newFlags = new HashSet<>();
for (int i = 0; i < flags.length; ++i) {
if (flags.length > i + 1 && flags[i + 1] == ':') {
valueFlags.add(flags[i]);
@ -526,9 +522,7 @@ public abstract class CommandsManager<T> {
public void invokeMethod(Method parent, String[] args, T player, Method method, Object instance, Object[] methodArgs, int level) throws CommandException {
try {
method.invoke(instance, methodArgs);
} catch (IllegalArgumentException e) {
logger.log(Level.SEVERE, "Failed to execute command", e);
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException | IllegalAccessException e) {
logger.log(Level.SEVERE, "Failed to execute command", e);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof CommandException) {

View File

@ -44,16 +44,7 @@ public class SimpleInjector implements Injector {
Constructor<?> ctr = clazz.getConstructor(argClasses);
ctr.setAccessible(true);
return ctr.newInstance(args);
} catch (NoSuchMethodException e) {
log.log(Level.SEVERE, "Error initializing commands class " + clazz, e);
return null;
} catch (InvocationTargetException e) {
log.log(Level.SEVERE, "Error initializing commands class " + clazz, e);
return null;
} catch (InstantiationException e) {
log.log(Level.SEVERE, "Error initializing commands class " + clazz, e);
return null;
} catch (IllegalAccessException e) {
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
log.log(Level.SEVERE, "Error initializing commands class " + clazz, e);
return null;
}