Java 1.5 compat.
This commit is contained in:
parent
42d4daddde
commit
c383d1f385
@ -33,7 +33,7 @@ public final class PluginCommand extends Command {
|
|||||||
throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin " + owningPlugin.getDescription().getFullName(), ex);
|
throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin " + owningPlugin.getDescription().getFullName(), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success && !usageMessage.isEmpty()) {
|
if (!success && usageMessage.length() > 0) {
|
||||||
sender.sendMessage(usageMessage.replace("<command>", commandLabel));
|
sender.sendMessage(usageMessage.replace("<command>", commandLabel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.Server;
|
|||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import static org.bukkit.util.Java15Compat.Arrays_copyOfRange;
|
||||||
|
|
||||||
public final class SimpleCommandMap implements CommandMap {
|
public final class SimpleCommandMap implements CommandMap {
|
||||||
private final Map<String, Command> knownCommands = new HashMap<String, Command>();
|
private final Map<String, Command> knownCommands = new HashMap<String, Command>();
|
||||||
@ -70,7 +71,7 @@ public final class SimpleCommandMap implements CommandMap {
|
|||||||
String[] args = commandLine.split(" ");
|
String[] args = commandLine.split(" ");
|
||||||
String sentCommandLabel = args[0].toLowerCase();
|
String sentCommandLabel = args[0].toLowerCase();
|
||||||
|
|
||||||
args = Arrays.copyOfRange(args, 1, args.length);
|
args = Arrays_copyOfRange(args, 1, args.length);
|
||||||
|
|
||||||
Command target = getCommand(sentCommandLabel);
|
Command target = getCommand(sentCommandLabel);
|
||||||
boolean isRegisteredCommand = (target != null);
|
boolean isRegisteredCommand = (target != null);
|
||||||
|
20
src/main/java/org/bukkit/util/Java15Compat.java
Normal file
20
src/main/java/org/bukkit/util/Java15Compat.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package org.bukkit.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
|
public class Java15Compat {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> T[] Arrays_copyOfRange(T[] original, int start, int end) {
|
||||||
|
if (original.length >= start && 0 <= start) {
|
||||||
|
if (start <= end) {
|
||||||
|
int length = end - start;
|
||||||
|
int copyLength = Math.min( length, original.length - start);
|
||||||
|
T[] copy = (T[]) Array.newInstance(original.getClass().getComponentType(), length);
|
||||||
|
System.arraycopy(original, start, copy, 0, copyLength);
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
throw new ArrayIndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user