Skip to content

Commit

Permalink
Merge pull request #110 from webhead1104/server-command
Browse files Browse the repository at this point in the history
Fix server command
  • Loading branch information
Foxikle authored Jun 19, 2024
2 parents 4786d51 + f5c8e38 commit 8f5ce23
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/main/java/net/cytonic/cytosis/commands/ServerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,25 @@ public ServerCommand() {
super("cytosis:server");
try {
setCondition((sender, _) -> sender.hasPermission("cytosis.commands.server"));
setDefaultExecutor((sender, context) -> sender.sendMessage(MiniMessageTemplate.MM."<RED>You must specify a server!"));
setDefaultExecutor((sender, _) -> sender.sendMessage(MiniMessageTemplate.MM."<RED>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."<RED>You are already connected to the server!");
}
}), serverArgument);
} catch (Exception e) {
Expand Down

0 comments on commit 8f5ce23

Please sign in to comment.