cn.nukkit.command.defaults.PluginsCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
package cn.nukkit.command.defaults;
import cn.nukkit.command.CommandSender;
import cn.nukkit.lang.TranslationContainer;
import cn.nukkit.plugin.Plugin;
import cn.nukkit.utils.TextFormat;
import java.util.Map;
/**
* @author xtypr
* @since 2015/11/12
*/
public class PluginsCommand extends VanillaCommand {
public PluginsCommand(String name) {
super(name,
"%nukkit.command.plugins.description",
"%nukkit.command.plugins.usage",
new String[]{"pl"}
);
this.setPermission("nukkit.command.plugins");
this.commandParameters.clear();
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
this.sendPluginList(sender);
return true;
}
private void sendPluginList(CommandSender sender) {
StringBuilder list = new StringBuilder();
Map plugins = sender.getServer().getPluginManager().getPlugins();
for (Plugin plugin : plugins.values()) {
if (list.length() > 0) {
list.append(TextFormat.WHITE + ", ");
}
list.append(plugin.isEnabled() ? TextFormat.GREEN : TextFormat.RED);
list.append(plugin.getDescription().getFullName());
}
sender.sendMessage(new TranslationContainer("nukkit.command.plugins.success", String.valueOf(plugins.size()), list.toString()));
}
}