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) { public GameCommandModule(DiscordSRV discordSRV) {
super(discordSRV); super(discordSRV);
this.primaryCommand = DiscordSRVCommand.get(discordSRV); this.primaryCommand = DiscordSRVCommand.get(discordSRV, "discordsrv");
this.discordAlias = GameCommand.literal("discord").redirect(primaryCommand); this.discordAlias = DiscordSRVCommand.get(discordSRV, "discord");
this.linkCommand = LinkCommand.get(discordSRV); this.linkCommand = LinkCommand.get(discordSRV);
registerCommand(primaryCommand); 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.command.game.sender.ICommandSender;
import com.discordsrv.common.component.util.ComponentUtil; import com.discordsrv.common.component.util.ComponentUtil;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class DiscordSRVCommand implements GameCommandExecutor { public class DiscordSRVCommand implements GameCommandExecutor {
private static GameCommand INSTANCE; private static Map<String, GameCommand> INSTANCES = new ConcurrentHashMap<>();
public static GameCommand get(DiscordSRV discordSRV) { public static GameCommand get(DiscordSRV discordSRV, String alias) {
if (INSTANCE == null) { return INSTANCES.computeIfAbsent(alias, key ->
INSTANCE = GameCommand.literal("discordsrv") GameCommand.literal(alias)
.requiredPermission("discordsrv.player.command") .requiredPermission("discordsrv.player.command")
.executor(new DiscordSRVCommand(discordSRV)) .executor(new DiscordSRVCommand(discordSRV))
.then(BroadcastCommand.discord(discordSRV)) .then(BroadcastCommand.discord(discordSRV))
.then(BroadcastCommand.minecraft(discordSRV)) .then(BroadcastCommand.minecraft(discordSRV))
.then(BroadcastCommand.json(discordSRV)) .then(BroadcastCommand.json(discordSRV))
.then(DebugCommand.get(discordSRV)) .then(DebugCommand.get(discordSRV))
.then(LinkCommand.get(discordSRV)) .then(LinkCommand.get(discordSRV))
.then(ReloadCommand.get(discordSRV)) .then(ReloadCommand.get(discordSRV))
.then(ResyncCommand.get(discordSRV)) .then(ResyncCommand.get(discordSRV))
.then(VersionCommand.get(discordSRV)); .then(VersionCommand.get(discordSRV))
} );
return INSTANCE;
} }
private final DiscordSRV discordSRV; private final DiscordSRV discordSRV;