From 6410e49ab952b1824815d2f4e50da786e1ce0930 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Wed, 2 Mar 2011 15:23:15 +0100 Subject: [PATCH] Java 1.5 compat. By: Erik Broes --- .../org/bukkit/command/PluginCommand.java | 2 +- .../org/bukkit/command/SimpleCommandMap.java | 5 +++-- .../java/org/bukkit/util/Java15Compat.java | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/util/Java15Compat.java diff --git a/paper-api/src/main/java/org/bukkit/command/PluginCommand.java b/paper-api/src/main/java/org/bukkit/command/PluginCommand.java index 2f306bb84d..27eb0b1881 100644 --- a/paper-api/src/main/java/org/bukkit/command/PluginCommand.java +++ b/paper-api/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("", commandLabel)); } diff --git a/paper-api/src/main/java/org/bukkit/command/SimpleCommandMap.java b/paper-api/src/main/java/org/bukkit/command/SimpleCommandMap.java index 94241ec308..9bd8529c4f 100644 --- a/paper-api/src/main/java/org/bukkit/command/SimpleCommandMap.java +++ b/paper-api/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 knownCommands = new HashMap(); @@ -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/paper-api/src/main/java/org/bukkit/util/Java15Compat.java b/paper-api/src/main/java/org/bukkit/util/Java15Compat.java new file mode 100644 index 0000000000..d56169a16d --- /dev/null +++ b/paper-api/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[] 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(); + } +}