Skip to content

Commit

Permalink
add plugins command
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokkonaut committed Sep 29, 2022
1 parent 4d338f4 commit dd40ffe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/de/cubeside/globalserver/GlobalServer.java
Expand Up @@ -9,6 +9,7 @@
import de.cubeside.globalserver.command.CreateAccountCommand;
import de.cubeside.globalserver.command.HelpCommand;
import de.cubeside.globalserver.command.ListCommand;
import de.cubeside.globalserver.command.PluginsCommand;
import de.cubeside.globalserver.command.ServersCommand;
import de.cubeside.globalserver.command.StopCommand;
import de.cubeside.globalserver.event.EventBus;
Expand Down Expand Up @@ -152,6 +153,8 @@ public GlobalServer() throws PluginLoadException {
addCommand(new AccountSetRestrictedCommand());
addCommand(new AccountAddAllowedChannelCommand());
addCommand(new AccountRemoveAllowedChannelCommand());
addCommand(new PluginsCommand());
addCommand("pl", new PluginsCommand());

this.pluginFolder = new File("./plugins");
pluginFolder.mkdirs();
Expand Down Expand Up @@ -181,7 +184,11 @@ public ServerCommand getCommand(String name) {
}

public void addCommand(ServerCommand command) {
commands.put(command.getCommand().toLowerCase().trim(), command);
addCommand(command.getCommand(), command);
}

public void addCommand(String commandString, ServerCommand command) {
commands.put(commandString.toLowerCase().trim(), command);
}

public void addAccount(String login, String password) {
Expand Down Expand Up @@ -514,4 +521,8 @@ Lock getReadLock() {
public EventBus getEventBus() {
return eventBus;
}

public PluginManager getPluginManager() {
return pluginManager;
}
}
30 changes: 30 additions & 0 deletions src/main/java/de/cubeside/globalserver/command/PluginsCommand.java
@@ -0,0 +1,30 @@
package de.cubeside.globalserver.command;

import de.cubeside.globalserver.ArgsParser;
import de.cubeside.globalserver.GlobalServer;
import de.cubeside.globalserver.ServerCommand;
import de.cubeside.globalserver.plugin.Plugin;
import java.util.ArrayList;

public class PluginsCommand extends ServerCommand {
public PluginsCommand() {
super("plugins");
}

@Override
public void execute(GlobalServer server, ArgsParser args) {
StringBuilder sb = new StringBuilder();
ArrayList<Plugin> plugins = new ArrayList<>(server.getPluginManager().getPlugins());
plugins.sort((a1, a2) -> a1.getDescription().getName().compareTo(a2.getDescription().getName()));
sb.append("Plugins (").append(plugins.size()).append("): ");
boolean first = true;
for (Plugin plugin : plugins) {
if (!first) {
sb.append(", ");
}
first = false;
sb.append(plugin.getDescription().getName());
}
GlobalServer.LOGGER.info(sb.toString());
}
}

0 comments on commit dd40ffe

Please sign in to comment.