diff --git a/bans-core-addons/exemption-luckperms/src/main/java/space/arim/libertybans/core/addon/exempt/luckperms/ExemptionLuckPermsConfig.java b/bans-core-addons/exemption-luckperms/src/main/java/space/arim/libertybans/core/addon/exempt/luckperms/ExemptionLuckPermsConfig.java index d7c6a5ae0..999e83690 100644 --- a/bans-core-addons/exemption-luckperms/src/main/java/space/arim/libertybans/core/addon/exempt/luckperms/ExemptionLuckPermsConfig.java +++ b/bans-core-addons/exemption-luckperms/src/main/java/space/arim/libertybans/core/addon/exempt/luckperms/ExemptionLuckPermsConfig.java @@ -19,7 +19,14 @@ package space.arim.libertybans.core.addon.exempt.luckperms; +import space.arim.dazzleconf.annote.ConfComments; +import space.arim.dazzleconf.annote.ConfDefault; +import space.arim.dazzleconf.annote.ConfKey; import space.arim.libertybans.core.addon.AddonConfig; public interface ExemptionLuckPermsConfig extends AddonConfig { + @ConfKey("exempt-same") + @ConfComments("Whether to exempt victims with the same weight as the operator.") + @ConfDefault.DefaultBoolean(false) + boolean exemptSame(); } diff --git a/bans-core-addons/exemption-luckperms/src/main/java/space/arim/libertybans/core/addon/exempt/luckperms/LuckPermsExemptProvider.java b/bans-core-addons/exemption-luckperms/src/main/java/space/arim/libertybans/core/addon/exempt/luckperms/LuckPermsExemptProvider.java index 8a7a01ccb..fbcd5c494 100644 --- a/bans-core-addons/exemption-luckperms/src/main/java/space/arim/libertybans/core/addon/exempt/luckperms/LuckPermsExemptProvider.java +++ b/bans-core-addons/exemption-luckperms/src/main/java/space/arim/libertybans/core/addon/exempt/luckperms/LuckPermsExemptProvider.java @@ -73,14 +73,15 @@ public CompletionStage isExempted(CmdSender sender, String category, Vi return userManager.loadUser(senderUuid).thenCombine(userManager.loadUser(targetUuid), (senderUser, targetUser) -> { int senderWeight = calculateUserMaxWeight(senderUser); int targetWeight = calculateUserMaxWeight(targetUser); - return targetWeight > senderWeight; + if (senderWeight == -1 && targetWeight == -1) return false; + return addon.config().exemptSame() ? targetWeight >= senderWeight : targetWeight > senderWeight; }); } private int calculateUserMaxWeight(User user) { - int maxWeight = 0; + int maxWeight = -1; for (Group group : user.getInheritedGroups(user.getQueryOptions())) { - int weight = group.getWeight().orElse(0); + int weight = group.getWeight().orElse(-1); if (weight > maxWeight) { maxWeight = weight; } diff --git a/bans-core-addons/exemption-luckperms/src/test/java/space/arim/libertybans/core/addon/exempt/luckperms/LuckPermsExemptProviderTest.java b/bans-core-addons/exemption-luckperms/src/test/java/space/arim/libertybans/core/addon/exempt/luckperms/LuckPermsExemptProviderTest.java index 14e441801..e85b24b0c 100644 --- a/bans-core-addons/exemption-luckperms/src/test/java/space/arim/libertybans/core/addon/exempt/luckperms/LuckPermsExemptProviderTest.java +++ b/bans-core-addons/exemption-luckperms/src/test/java/space/arim/libertybans/core/addon/exempt/luckperms/LuckPermsExemptProviderTest.java @@ -24,8 +24,7 @@ import net.luckperms.api.model.user.User; import net.luckperms.api.model.user.UserManager; import net.luckperms.api.query.QueryOptions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -53,6 +52,7 @@ public class LuckPermsExemptProviderTest { private UUID targetUuid; private User senderUser; private User targetUser; + private ExemptionLuckPermsConfig config; private LuckPermsExemptProvider exemptProvider; public LuckPermsExemptProviderTest(@Mock ExemptionLuckPermsAddon addon) { @@ -68,6 +68,7 @@ public void setup(@Mock ExemptionLuckPermsConfig config, @Mock LuckPerms luckPer this.senderUser = senderUser; this.targetUser = targetUser; when(config.enable()).thenReturn(true); + this.config = config; when(addon.config()).thenReturn(config); when(addon.luckPerms()).thenReturn(luckPerms); when(luckPerms.getUserManager()).thenReturn(userManager); @@ -124,4 +125,19 @@ public void targetHasExemptWeightLowerThanOperatorWeight() { assertIsExempted(false); } + @Test + public void targetHasExemptWeightSameAsOperatorWeight() { + setGroups(senderUser, null, null, 4, null, null, 5, 20); + setGroups(targetUser, 3, null, 10, null, 20, 9); + assertIsExempted(false); + } + + @Test + public void targetHasExemptWeightSameAsOperatorWeightOptionEnabled() { + setGroups(senderUser, null, null, 4, null, null, 5, 20); + setGroups(targetUser, 3, null, 10, null, 20, 9); + when(config.exemptSame()).thenReturn(true); + assertIsExempted(true); + } + }