diff --git a/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java index 814e4828d..cec64eec5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java @@ -46,12 +46,13 @@ public class PlanCommand extends TreeCommand { commands.add(new ReloadCommand(plugin)); commands.add(new ManageCommand(plugin)); commands.add(new StatusCommand<>(plugin, Permissions.MANAGE.getPermission())); - - if (plugin.getWebServer().isEnabled()) { - commands.add(new ListCommand()); - RegisterCommand registerCommand = new RegisterCommand(plugin); - commands.add(registerCommand); - commands.add(new WebUserCommand(plugin, registerCommand)); + commands.add(new ListCommand()); + RegisterCommand registerCommand = new RegisterCommand(plugin); + commands.add(registerCommand); + commands.add(new WebUserCommand(plugin, registerCommand)); + if (plugin.getInfoManager().isUsingAnotherWebServer()) { + commands.add(new NetworkCommand()); + commands.add(new ListServersCommand(plugin)); } if (Settings.DEV_MODE.isTrue()) { diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java new file mode 100644 index 000000000..d59eaf8e3 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java @@ -0,0 +1,61 @@ +package main.java.com.djrapitops.plan.command.commands; + +import com.djrapitops.plugin.command.CommandType; +import com.djrapitops.plugin.command.ISender; +import com.djrapitops.plugin.command.SubCommand; +import com.djrapitops.plugin.settings.ColorScheme; +import main.java.com.djrapitops.plan.Log; +import main.java.com.djrapitops.plan.Permissions; +import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.api.IPlan; +import main.java.com.djrapitops.plan.locale.Locale; +import main.java.com.djrapitops.plan.locale.Msg; + +import java.sql.SQLException; +import java.util.Map; + +/** + * This subcommand is used to reload the plugin. + * + * @author Rsl1122 + * @since 2.0.0 + */ +public class ListServersCommand extends SubCommand { + + private final IPlan plugin; + + /** + * Subcommand constructor. + * + * @param plugin Current instance of Plan + */ + public ListServersCommand(Plan plugin) { + super("servers, serverlist, listservers, sl", + CommandType.CONSOLE, + Permissions.MANAGE.getPermission(), + Locale.get(Msg.CMD_USG_RELOAD).toString()); + + this.plugin = plugin; + } + + @Override + public boolean onCommand(ISender sender, String commandLabel, String[] args) { + ColorScheme colorScheme = plugin.getColorScheme(); + String mCol = colorScheme.getMainColor(); + String sCol = colorScheme.getSecondaryColor(); + String tCol = colorScheme.getTertiaryColor(); + try { + sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString() + mCol + " Servers"); + Map serverNames = plugin.getDB().getServerTable().getServerNames(); + for (Map.Entry entry : serverNames.entrySet()) { + sender.sendMessage(" " + tCol + entry.getKey() + sCol + " : " + entry.getValue()); + } + sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString()); + } catch (SQLException e) { + sender.sendMessage("§cSQLException occurred."); + Log.toLog(this.getClass().getName(), e); + } + return true; + } + +} diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/NetworkCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/NetworkCommand.java new file mode 100644 index 000000000..741fbaf39 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/NetworkCommand.java @@ -0,0 +1,52 @@ +package main.java.com.djrapitops.plan.command.commands; + +import com.djrapitops.plugin.command.CommandType; +import com.djrapitops.plugin.command.CommandUtils; +import com.djrapitops.plugin.command.ISender; +import com.djrapitops.plugin.command.SubCommand; +import main.java.com.djrapitops.plan.Permissions; +import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.locale.Locale; +import main.java.com.djrapitops.plan.locale.Msg; + +/** + * Command used to display link to the player list webpage. + *

+ * Subcommand is not registered if Webserver is not enabled. + * + * @author Rsl1122 + * @since 3.5.2 + */ +public class NetworkCommand extends SubCommand { + + /** + * Class Constructor. + */ + public NetworkCommand() { + super("network, n, netw", CommandType.CONSOLE, Permissions.ANALYZE.getPermission(), Locale.get(Msg.CMD_USG_LIST).toString(), ""); + + } + + @Override + public boolean onCommand(ISender sender, String commandLabel, String[] args) { + + sendNetworkMsg(sender); + return true; + } + + private void sendNetworkMsg(ISender sender) { + sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).parse()); + + // Link + String url = Plan.getInstance().getInfoManager().getLinkTo("/network"); + String message = Locale.get(Msg.CMD_INFO_LINK).toString(); + boolean console = !CommandUtils.isPlayer(sender); + if (console) { + sender.sendMessage(message + url); + } else { + sender.sendMessage(message); + sender.sendLink(" ", Locale.get(Msg.CMD_INFO_CLICK_ME).toString(), url); + } + sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString()); + } +} \ No newline at end of file