mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-19 06:42:02 +01:00
Java 1.5 compat.
By: Erik Broes <erikbroes@ripe.net>
This commit is contained in:
parent
2d93fec7d2
commit
6410e49ab9
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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>();
|
||||
@ -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);
|
||||
|
20
paper-api/src/main/java/org/bukkit/util/Java15Compat.java
Normal file
20
paper-api/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…
Reference in New Issue
Block a user