-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from webhead1104/master
Server command
- Loading branch information
Showing
9 changed files
with
98 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/net/cytonic/cytosis/commands/ServerCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package net.cytonic.cytosis.commands; | ||
|
||
import net.cytonic.cytosis.Cytosis; | ||
import net.cytonic.cytosis.data.objects.CytonicServer; | ||
import net.cytonic.cytosis.logging.Logger; | ||
import net.cytonic.cytosis.utils.MiniMessageTemplate; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.format.NamedTextColor; | ||
import net.minestom.server.command.builder.Command; | ||
import net.minestom.server.command.builder.arguments.ArgumentType; | ||
import net.minestom.server.command.builder.suggestion.SuggestionEntry; | ||
import net.minestom.server.entity.Player; | ||
|
||
public class ServerCommand extends Command { | ||
|
||
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!")); | ||
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); | ||
} | ||
} | ||
} | ||
}), serverArgument); | ||
} catch (Exception e) { | ||
Logger.error("error", e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tonic/cytosis/data/obj/CytonicServer.java → ...c/cytosis/data/objects/CytonicServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters