diff --git a/src/main/java/net/cytonic/cytosis/commands/ServerCommand.java b/src/main/java/net/cytonic/cytosis/commands/ServerCommand.java index bdf25251..c605f9af 100644 --- a/src/main/java/net/cytonic/cytosis/commands/ServerCommand.java +++ b/src/main/java/net/cytonic/cytosis/commands/ServerCommand.java @@ -17,31 +17,25 @@ public ServerCommand() { super("cytosis:server"); try { setCondition((sender, _) -> sender.hasPermission("cytosis.commands.server")); - setDefaultExecutor((sender, context) -> sender.sendMessage(MiniMessageTemplate.MM."You must specify a server!")); + setDefaultExecutor((sender, _) -> sender.sendMessage(MiniMessageTemplate.MM."You must specify a server!")); var serverArgument = ArgumentType.Word("server"); serverArgument.setCallback((sender, exception) -> sender.sendMessage(Component.text(STR."The server \{exception.getInput()} is invalid!", NamedTextColor.RED))); serverArgument.setSuggestionCallback((_, _, suggestion) -> { - Logger.debug("this has been called"); for (CytonicServer server : Cytosis.getCytonicNetwork().getServers()) { suggestion.addEntry(new SuggestionEntry(server.id())); - Logger.debug(STR."command server id = \{server.id()}"); } }); addSyntax(((sender, context) -> { if (sender instanceof Player player) if (player.hasPermission("cytosis.commands.server")) { - if (context.get(serverArgument).isEmpty()) { - StringBuilder builder = new StringBuilder(); - Cytosis.getCytonicNetwork().getServers().forEach(server -> builder.append(STR."\{server.id()} ")); - player.sendMessage(Component.text(builder.toString())); - return; - } - for (CytonicServer server : Cytosis.getCytonicNetwork().getServers()) { - if (server.id().equals(context.get(serverArgument))) { - player.sendMessage(Component.text(STR."Connecting to \{server.id()}", NamedTextColor.GREEN)); - Cytosis.getDatabaseManager().getRedisDatabase().sendPlayerToServer(player, server); + if (!context.get(serverArgument).equalsIgnoreCase(Cytosis.SERVER_ID)) { + for (CytonicServer server : Cytosis.getCytonicNetwork().getServers()) { + if (server.id().equals(context.get(serverArgument))) { + player.sendMessage(Component.text(STR."Connecting to \{server.id()}", NamedTextColor.GREEN)); + Cytosis.getDatabaseManager().getRedisDatabase().sendPlayerToServer(player, server); + } } - } + }else player.sendMessage(MiniMessageTemplate.MM."You are already connected to the server!"); } }), serverArgument); } catch (Exception e) {