diff options
author | Erik Broes <erikbroes@ripe.net> | 2011-03-02 15:23:15 +0100 |
---|---|---|
committer | Erik Broes <erikbroes@ripe.net> | 2011-03-02 15:23:15 +0100 |
commit | c383d1f3859d099cc9ab11c02c5d73554d5e7822 (patch) | |
tree | b9df9a61baf13fc038b4ae2fedd8adb2d6f19829 /src/main | |
parent | 42d4dadddeb7f58d9e3784992ba1513015612dc6 (diff) | |
download | bukkit-c383d1f3859d099cc9ab11c02c5d73554d5e7822.tar bukkit-c383d1f3859d099cc9ab11c02c5d73554d5e7822.tar.gz bukkit-c383d1f3859d099cc9ab11c02c5d73554d5e7822.tar.lz bukkit-c383d1f3859d099cc9ab11c02c5d73554d5e7822.tar.xz bukkit-c383d1f3859d099cc9ab11c02c5d73554d5e7822.zip |
Java 1.5 compat.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/command/PluginCommand.java | 2 | ||||
-rw-r--r-- | src/main/java/org/bukkit/command/SimpleCommandMap.java | 5 | ||||
-rw-r--r-- | src/main/java/org/bukkit/util/Java15Compat.java | 20 |
3 files changed, 24 insertions, 3 deletions
diff --git a/src/main/java/org/bukkit/command/PluginCommand.java b/src/main/java/org/bukkit/command/PluginCommand.java index 2f306bb8..27eb0b18 100644 --- a/src/main/java/org/bukkit/command/PluginCommand.java +++ b/src/main/java/org/bukkit/command/PluginCommand.java @@ -33,7 +33,7 @@ public final class PluginCommand extends Command { 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)); } diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java index 94241ec3..9bd8529c 100644 --- a/src/main/java/org/bukkit/command/SimpleCommandMap.java +++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java @@ -10,6 +10,7 @@ import org.bukkit.Server; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; +import static org.bukkit.util.Java15Compat.Arrays_copyOfRange; public final class SimpleCommandMap implements CommandMap { private final Map<String, Command> knownCommands = new HashMap<String, Command>(); @@ -62,7 +63,7 @@ public final class SimpleCommandMap implements CommandMap { knownCommands.put(name.toLowerCase(), command); return !nameInUse; } - + /** * {@inheritDoc} */ @@ -70,7 +71,7 @@ public final class SimpleCommandMap implements CommandMap { String[] args = commandLine.split(" "); String sentCommandLabel = args[0].toLowerCase(); - args = Arrays.copyOfRange(args, 1, args.length); + args = Arrays_copyOfRange(args, 1, args.length); Command target = getCommand(sentCommandLabel); boolean isRegisteredCommand = (target != null); diff --git a/src/main/java/org/bukkit/util/Java15Compat.java b/src/main/java/org/bukkit/util/Java15Compat.java new file mode 100644 index 00000000..d56169a1 --- /dev/null +++ b/src/main/java/org/bukkit/util/Java15Compat.java @@ -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(); + } +} |