geforkt von Mirrors/Paper
The server config can now specify aliases to multiple (or none) commands, for example "debug: [version, plugin]" to run both version and plugin, or "plugins: []" to disable the plugins command
By: Dinnerbone <dinnerbone@dinnerbone.com>
Dieser Commit ist enthalten in:
Ursprung
22bfa512a9
Commit
244635242e
@ -270,7 +270,7 @@ public interface Server {
|
||||
*
|
||||
* @return Map of aliases to command names
|
||||
*/
|
||||
public Map<String, String> getCommandAliases();
|
||||
public Map<String, String[]> getCommandAliases();
|
||||
|
||||
/**
|
||||
* Gets the radius, in blocks, around each worlds spawn point to protect
|
||||
|
25
paper-api/src/main/java/org/bukkit/command/MultipleCommandAlias.java
Normale Datei
25
paper-api/src/main/java/org/bukkit/command/MultipleCommandAlias.java
Normale Datei
@ -0,0 +1,25 @@
|
||||
|
||||
package org.bukkit.command;
|
||||
|
||||
/**
|
||||
* Represents a command that delegates to one or more other commands
|
||||
*/
|
||||
public class MultipleCommandAlias extends Command {
|
||||
private Command[] commands;
|
||||
|
||||
public MultipleCommandAlias(String name, Command[] commands) {
|
||||
super(name);
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
boolean result = false;
|
||||
|
||||
for (Command command : commands) {
|
||||
result |= command.execute(sender, commandLabel, args);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -151,17 +151,35 @@ public final class SimpleCommandMap implements CommandMap {
|
||||
}
|
||||
|
||||
public void registerServerAliases() {
|
||||
Map<String, String> values = server.getCommandAliases();
|
||||
Map<String, String[]> values = server.getCommandAliases();
|
||||
|
||||
for (String alias : values.keySet()) {
|
||||
String target = values.get(alias);
|
||||
Command command = getCommand(target);
|
||||
String[] targetNames = values.get(alias);
|
||||
List<Command> targets = new ArrayList<Command>();
|
||||
String bad = "";
|
||||
|
||||
if (command != null) {
|
||||
// We register these as commands so they have absolute priority.
|
||||
knownCommands.put(alias.toLowerCase(), command);
|
||||
for (String name : targetNames) {
|
||||
Command command = getCommand(name);
|
||||
|
||||
if (command == null) {
|
||||
if (bad.length() > 0) {
|
||||
bad += ", ";
|
||||
}
|
||||
} else {
|
||||
targets.add(command);
|
||||
}
|
||||
}
|
||||
|
||||
// We register these as commands so they have absolute priority.
|
||||
|
||||
if (targets.size() > 0) {
|
||||
knownCommands.put(alias.toLowerCase(), new MultipleCommandAlias(alias.toLowerCase(), targets.toArray(new Command[0])));
|
||||
} else {
|
||||
server.getLogger().warning("Could not register custom alias '" + alias + "' to command '" + target + "' because the command does not exist.");
|
||||
knownCommands.remove(alias.toLowerCase());
|
||||
}
|
||||
|
||||
if (bad.length() > 0) {
|
||||
server.getLogger().warning("The following command(s) could not be aliased under '" + alias + "' because they do not exist: " + bad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren