13
0
geforkt von Mirrors/Paper

Fixed command aliases priorities.

Command aliases are now given lower weight than the "official" name of the command; this allows you to define aliases without worrying about them overriding someone else's command.

By: Celtic Minstrel <celtic.minstrel.ca@>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2011-03-30 17:36:39 -04:00
Ursprung 12a93a05ff
Commit a679c0c906

Datei anzeigen

@ -3,8 +3,11 @@ package org.bukkit.command;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.Server;
@ -14,6 +17,7 @@ import static org.bukkit.util.Java15Compat.Arrays_copyOfRange;
public final class SimpleCommandMap implements CommandMap {
private final Map<String, Command> knownCommands = new HashMap<String, Command>();
private final Set<String> aliases = new HashSet<String>();
private final Server server;
public SimpleCommandMap(final Server server) {
@ -41,12 +45,11 @@ public final class SimpleCommandMap implements CommandMap {
}
private void register(String fallbackPrefix, Command command) {
List<String> names = new ArrayList<String>();
register(command.getName(), fallbackPrefix, command);
aliases.addAll(command.getAliases());
aliases.remove(command.getName());
names.add(command.getName());
names.addAll(command.getAliases());
for (String name : names) {
for (String name : command.getAliases()) {
register(name, fallbackPrefix, command);
}
}
@ -55,7 +58,7 @@ public final class SimpleCommandMap implements CommandMap {
* {@inheritDoc}
*/
public boolean register(String name, String fallbackPrefix, Command command) {
boolean nameInUse = (getCommand(name) != null);
boolean nameInUse = nameInUse(name);
if (nameInUse) {
name = fallbackPrefix + ":" + name;
@ -65,6 +68,13 @@ public final class SimpleCommandMap implements CommandMap {
return !nameInUse;
}
private boolean nameInUse(String name) {
if (getCommand(name) != null) {
return !aliases.contains(name);
}
return false;
}
/**
* {@inheritDoc}
*/