Skip to content

Commit

Permalink
Ignore administrator account in link count check (#79)
Browse files Browse the repository at this point in the history
Simply ignores max-link count check if user defined as user in configuration
  • Loading branch information
bivashy authored Oct 14, 2023
1 parent c440d19 commit 31debf5
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

@CommandKey(LinkCodeCommand.CONFIGURATION_KEY)
public class LinkCodeCommand implements OrphanCommand {

public static final String CONFIGURATION_KEY = "code";
@Dependency
private PluginConfig config;
Expand All @@ -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;
}
Expand All @@ -68,11 +69,19 @@ 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;
if (actor instanceof LinkCommandActorWrapper)
return LinkConfirmationType.FROM_LINK;
throw new IllegalArgumentException("Cannot resolve confirmation type for actor: " + actor);
}

}

0 comments on commit 31debf5

Please sign in to comment.