mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-17 05:03:55 -07:00
@@ -26,4 +26,8 @@ public interface CommandMap {
|
||||
*/
|
||||
public boolean dispatch(CommandSender sender, String cmdLine);
|
||||
|
||||
/**
|
||||
* Clears all registered commands.
|
||||
*/
|
||||
public void clearCommands();
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user