Tweak main command initialization a bit

This commit is contained in:
Vankka 2022-04-12 12:39:58 +03:00
parent 8c81873f92
commit cb1538d376
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
2 changed files with 20 additions and 18 deletions

View File

@ -39,8 +39,8 @@ public class GameCommandModule extends AbstractModule<DiscordSRV> {
public GameCommandModule(DiscordSRV discordSRV) {
super(discordSRV);
this.primaryCommand = DiscordSRVCommand.get(discordSRV);
this.discordAlias = GameCommand.literal("discord").redirect(primaryCommand);
this.primaryCommand = DiscordSRVCommand.get(discordSRV, "discordsrv");
this.discordAlias = DiscordSRVCommand.get(discordSRV, "discord");
this.linkCommand = LinkCommand.get(discordSRV);
registerCommand(primaryCommand);

View File

@ -27,25 +27,27 @@ import com.discordsrv.common.command.game.command.subcommand.*;
import com.discordsrv.common.command.game.sender.ICommandSender;
import com.discordsrv.common.component.util.ComponentUtil;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class DiscordSRVCommand implements GameCommandExecutor {
private static GameCommand INSTANCE;
private static Map<String, GameCommand> INSTANCES = new ConcurrentHashMap<>();
public static GameCommand get(DiscordSRV discordSRV) {
if (INSTANCE == null) {
INSTANCE = GameCommand.literal("discordsrv")
.requiredPermission("discordsrv.player.command")
.executor(new DiscordSRVCommand(discordSRV))
.then(BroadcastCommand.discord(discordSRV))
.then(BroadcastCommand.minecraft(discordSRV))
.then(BroadcastCommand.json(discordSRV))
.then(DebugCommand.get(discordSRV))
.then(LinkCommand.get(discordSRV))
.then(ReloadCommand.get(discordSRV))
.then(ResyncCommand.get(discordSRV))
.then(VersionCommand.get(discordSRV));
}
return INSTANCE;
public static GameCommand get(DiscordSRV discordSRV, String alias) {
return INSTANCES.computeIfAbsent(alias, key ->
GameCommand.literal(alias)
.requiredPermission("discordsrv.player.command")
.executor(new DiscordSRVCommand(discordSRV))
.then(BroadcastCommand.discord(discordSRV))
.then(BroadcastCommand.minecraft(discordSRV))
.then(BroadcastCommand.json(discordSRV))
.then(DebugCommand.get(discordSRV))
.then(LinkCommand.get(discordSRV))
.then(ReloadCommand.get(discordSRV))
.then(ResyncCommand.get(discordSRV))
.then(VersionCommand.get(discordSRV))
);
}
private final DiscordSRV discordSRV;