diff --git a/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java b/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java index 89085140..1ed9258b 100644 --- a/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java +++ b/core/src/main/java/me/mastercapexd/auth/shared/commands/LinkCodeCommand.java @@ -26,6 +26,7 @@ @CommandKey(LinkCodeCommand.CONFIGURATION_KEY) public class LinkCodeCommand implements OrphanCommand { + public static final String CONFIGURATION_KEY = "code"; @Dependency private PluginConfig config; @@ -50,7 +51,7 @@ public void onLink(MessageableCommandActor actor, MessengerLinkContext linkConte accountDatabase.getAccount(linkContext.getConfirmationUser().getLinkTarget().getPlayerId()) .thenAccept(account -> accountDatabase.getAccountsFromLinkIdentificator(identificator).thenAccept(accounts -> { - if (linkType.getSettings().getMaxLinkCount() > 0 && accounts.size() >= linkType.getSettings().getMaxLinkCount()) { + if (!validateLinkCount(linkType, identificator, accounts.size())) { actor.replyWithMessage(messages.getMessage("link-limit-reached")); return; } @@ -68,6 +69,13 @@ public void onLink(MessageableCommandActor actor, MessengerLinkContext linkConte })); } + private boolean validateLinkCount(LinkType linkType, LinkUserIdentificator identificator, int linkedAccountAmount) { + int maxLinkCount = linkType.getSettings().getMaxLinkCount(); + if (maxLinkCount > 0) + return true; + return !linkType.getSettings().isAdministrator(identificator) && maxLinkCount >= linkedAccountAmount; + } + private LinkConfirmationType getLinkConfirmationType(MessageableCommandActor actor) { if (actor instanceof ServerCommandActor) return LinkConfirmationType.FROM_GAME; @@ -75,4 +83,5 @@ private LinkConfirmationType getLinkConfirmationType(MessageableCommandActor act return LinkConfirmationType.FROM_LINK; throw new IllegalArgumentException("Cannot resolve confirmation type for actor: " + actor); } + }