Updated commands to have optional aliases, and to fallback to /pluginName:cmdName on name conflict.

By: VictorD <victor.danell@gmail.com>
This commit is contained in:
Bukkit/Spigot
2011-01-18 01:12:50 +01:00
parent b46210453c
commit ab6f5d4bc2
11 changed files with 233 additions and 161 deletions

View File

@@ -0,0 +1,33 @@
package org.bukkit.command;
import java.awt.Color;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public final class PluginCommand extends Command {
private final Plugin owningPlugin;
public PluginCommand(String name, Plugin owner) {
super(name);
this.owningPlugin = owner;
this.usageMessage = "";
}
public boolean execute(Player player, String commandLabel, String[] args) {
boolean cmdSuccess = owningPlugin.onCommand(player, this, commandLabel, args);
if (!cmdSuccess && usageMessage != "") {
String tmpMsg = usageMessage.replace("<command>", commandLabel);
String[] usageLines = tmpMsg.split("\\n");
for(String line: usageLines) {
while (line.length() > 0) {
int stripChars = (line.length() > 53 ? 53:line.length());
player.sendMessage(ChatColor.RED + line.substring(0, stripChars));
line = line.substring(stripChars);
}
}
}
return cmdSuccess;
}
}