Commands now have the ability to set a permission required before execution
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package org.bukkit.command.defaults;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class PluginsCommand extends Command {
|
||||
public PluginsCommand(String name) {
|
||||
super(name);
|
||||
this.description = "Gets a list of plugins running on the server";
|
||||
this.usageMessage = "/plugins";
|
||||
this.setPermission("bukkit.command.plugins");
|
||||
this.setAliases(Arrays.asList("pl"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
||||
if (!testPermission(sender)) return true;
|
||||
|
||||
sender.sendMessage("Plugins: " + getPluginList());
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getPluginList() {
|
||||
StringBuilder pluginList = new StringBuilder();
|
||||
Plugin[] plugins = Bukkit.getPluginManager().getPlugins();
|
||||
|
||||
for (Plugin plugin : plugins) {
|
||||
if (pluginList.length() > 0) {
|
||||
pluginList.append(ChatColor.WHITE);
|
||||
pluginList.append(", ");
|
||||
}
|
||||
|
||||
pluginList.append(plugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED);
|
||||
pluginList.append(plugin.getDescription().getName());
|
||||
}
|
||||
|
||||
return pluginList.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user