merge with head

By: stevenh <steven.hartland@multiplay.co.uk>
This commit is contained in:
Bukkit/Spigot
2011-01-29 17:18:32 +00:00
12 changed files with 289 additions and 15 deletions

View File

@@ -26,4 +26,8 @@ public interface CommandMap {
*/
public boolean dispatch(CommandSender sender, String cmdLine);
/**
* Clears all registered commands.
*/
public void clearCommands();
}

View File

@@ -14,24 +14,16 @@ import org.bukkit.plugin.PluginDescriptionFile;
public final class SimpleCommandMap implements CommandMap {
private final Map<String, Command> knownCommands = new HashMap<String, Command>();
private final Server server;
public SimpleCommandMap(final Server server) {
this.server = server;
setDefaultCommands(server);
}
private void setDefaultCommands(final Server server) {
register("bukkit", new VersionCommand("version", server));
register("reload", "bukkit", new Command("reload") {
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (sender.isOp()) {
server.reload();
sender.sendMessage(ChatColor.GREEN + "Reload complete.");
} else {
sender.sendMessage(ChatColor.RED + "You do not have sufficient access"
+ " to reload this server.");
}
return true;
}
});
register("bukkit", new ReloadCommand("reload", server));
}
/**
@@ -86,6 +78,13 @@ public final class SimpleCommandMap implements CommandMap {
return isRegisteredCommand;
}
public void clearCommands() {
synchronized (this) {
knownCommands.clear();
setDefaultCommands(server);
}
}
private static class VersionCommand extends Command {
private final Server server;
@@ -183,4 +182,28 @@ public final class SimpleCommandMap implements CommandMap {
return result.toString();
}
}
private static class ReloadCommand extends Command {
private final Server server;
public ReloadCommand(String name, Server server) {
super(name);
this.server = server;
this.tooltip = "Reloads the server configuration and plugins";
this.usageMessage = "/reload";
this.setAliases(Arrays.asList("rl"));
}
@Override
public boolean execute(Player player, String currentAlias, String[] args) {
if (player.isOp()) {
server.reload();
player.sendMessage(ChatColor.GREEN + "Reload complete.");
} else {
player.sendMessage(ChatColor.RED + "You do not have sufficient access" + " to reload this server.");
}
return true;
}
}
}