From cb1538d3766f86258992dc51595d4cdf18fd007a Mon Sep 17 00:00:00 2001 From: Vankka Date: Tue, 12 Apr 2022 12:39:58 +0300 Subject: [PATCH] Tweak main command initialization a bit --- .../command/game/GameCommandModule.java | 4 +-- .../game/command/DiscordSRVCommand.java | 34 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/common/src/main/java/com/discordsrv/common/command/game/GameCommandModule.java b/common/src/main/java/com/discordsrv/common/command/game/GameCommandModule.java index baed3f6f..daa4f0af 100644 --- a/common/src/main/java/com/discordsrv/common/command/game/GameCommandModule.java +++ b/common/src/main/java/com/discordsrv/common/command/game/GameCommandModule.java @@ -39,8 +39,8 @@ public class GameCommandModule extends AbstractModule { 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); diff --git a/common/src/main/java/com/discordsrv/common/command/game/command/DiscordSRVCommand.java b/common/src/main/java/com/discordsrv/common/command/game/command/DiscordSRVCommand.java index 4b9c9b44..11151c26 100644 --- a/common/src/main/java/com/discordsrv/common/command/game/command/DiscordSRVCommand.java +++ b/common/src/main/java/com/discordsrv/common/command/game/command/DiscordSRVCommand.java @@ -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 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;