From 39f527777d407f46592139b6339fd5b0094fa385 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 18 Mar 2020 08:36:40 -0700 Subject: [PATCH] Ignore negative permissions. Fixes https://github.com/BentoBoxWorld/Limits/issues/73 --- .../limits/listeners/JoinListener.java | 2 +- .../limits/listeners/JoinListenerTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/limits/listeners/JoinListener.java b/src/main/java/world/bentobox/limits/listeners/JoinListener.java index 5f8f0b7..612a5de 100644 --- a/src/main/java/world/bentobox/limits/listeners/JoinListener.java +++ b/src/main/java/world/bentobox/limits/listeners/JoinListener.java @@ -46,7 +46,7 @@ public class JoinListener implements Listener { ibc.getBlockLimits().clear(); } for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) { - if (!perms.getPermission().startsWith(permissionPrefix)) continue; + if (!perms.getValue() || !perms.getPermission().startsWith(permissionPrefix)) continue; // No wildcards if (perms.getPermission().contains(permissionPrefix + "*")) { logError(player.getName(), perms.getPermission(), "wildcards are not allowed."); diff --git a/src/test/java/bentobox/addon/limits/listeners/JoinListenerTest.java b/src/test/java/bentobox/addon/limits/listeners/JoinListenerTest.java index a7b33d4..366bf5f 100644 --- a/src/test/java/bentobox/addon/limits/listeners/JoinListenerTest.java +++ b/src/test/java/bentobox/addon/limits/listeners/JoinListenerTest.java @@ -239,6 +239,7 @@ public class JoinListenerTest { Set perms = new HashSet<>(); PermissionAttachmentInfo permAtt = mock(PermissionAttachmentInfo.class); when(permAtt.getPermission()).thenReturn("bskyblock.island.limit.my.perm.for.game"); + when(permAtt.getValue()).thenReturn(true); perms.add(permAtt); when(player.getEffectivePermissions()).thenReturn(perms); PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome"); @@ -254,6 +255,7 @@ public class JoinListenerTest { Set perms = new HashSet<>(); PermissionAttachmentInfo permAtt = mock(PermissionAttachmentInfo.class); when(permAtt.getPermission()).thenReturn("bskyblock.island.limit.mumbo.34"); + when(permAtt.getValue()).thenReturn(true); perms.add(permAtt); when(player.getEffectivePermissions()).thenReturn(perms); PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome"); @@ -269,6 +271,7 @@ public class JoinListenerTest { Set perms = new HashSet<>(); PermissionAttachmentInfo permAtt = mock(PermissionAttachmentInfo.class); when(permAtt.getPermission()).thenReturn("bskyblock.island.limit.*"); + when(permAtt.getValue()).thenReturn(true); perms.add(permAtt); when(player.getEffectivePermissions()).thenReturn(perms); PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome"); @@ -284,6 +287,7 @@ public class JoinListenerTest { Set perms = new HashSet<>(); PermissionAttachmentInfo permAtt = mock(PermissionAttachmentInfo.class); when(permAtt.getPermission()).thenReturn("bskyblock.island.limit.STONE.abc"); + when(permAtt.getValue()).thenReturn(true); perms.add(permAtt); when(player.getEffectivePermissions()).thenReturn(perms); PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome"); @@ -299,6 +303,7 @@ public class JoinListenerTest { Set perms = new HashSet<>(); PermissionAttachmentInfo permAtt = mock(PermissionAttachmentInfo.class); when(permAtt.getPermission()).thenReturn("bskyblock.island.limit.STONE.24"); + when(permAtt.getValue()).thenReturn(true); perms.add(permAtt); when(player.getEffectivePermissions()).thenReturn(perms); PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome"); @@ -315,6 +320,7 @@ public class JoinListenerTest { Set perms = new HashSet<>(); PermissionAttachmentInfo permAtt = mock(PermissionAttachmentInfo.class); when(permAtt.getPermission()).thenReturn("bskyblock.island.limit.BAT.24"); + when(permAtt.getValue()).thenReturn(true); perms.add(permAtt); when(player.getEffectivePermissions()).thenReturn(perms); PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome"); @@ -331,19 +337,29 @@ public class JoinListenerTest { Set perms = new HashSet<>(); PermissionAttachmentInfo permAtt = mock(PermissionAttachmentInfo.class); when(permAtt.getPermission()).thenReturn("bskyblock.island.limit.STONE.24"); + when(permAtt.getValue()).thenReturn(true); perms.add(permAtt); PermissionAttachmentInfo permAtt2 = mock(PermissionAttachmentInfo.class); when(permAtt2.getPermission()).thenReturn("bskyblock.island.limit.grass.14"); + when(permAtt2.getValue()).thenReturn(true); perms.add(permAtt2); PermissionAttachmentInfo permAtt3 = mock(PermissionAttachmentInfo.class); when(permAtt3.getPermission()).thenReturn("bskyblock.island.limit.dirt.34"); + when(permAtt3.getValue()).thenReturn(true); perms.add(permAtt3); PermissionAttachmentInfo permAtt4 = mock(PermissionAttachmentInfo.class); when(permAtt4.getPermission()).thenReturn("bskyblock.island.limit.chicken.34"); + when(permAtt4.getValue()).thenReturn(true); perms.add(permAtt4); PermissionAttachmentInfo permAtt5 = mock(PermissionAttachmentInfo.class); when(permAtt5.getPermission()).thenReturn("bskyblock.island.limit.cave_spider.4"); + when(permAtt5.getValue()).thenReturn(true); perms.add(permAtt5); + PermissionAttachmentInfo permAtt6 = mock(PermissionAttachmentInfo.class); + when(permAtt6.getPermission()).thenReturn("bskyblock.island.limit.cave_spider.4"); + when(permAtt6.getValue()).thenReturn(false); // negative perm + perms.add(permAtt6); + when(player.getEffectivePermissions()).thenReturn(perms); PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome"); jl.onPlayerJoin(e); @@ -365,12 +381,15 @@ public class JoinListenerTest { Set perms = new HashSet<>(); PermissionAttachmentInfo permAtt = mock(PermissionAttachmentInfo.class); when(permAtt.getPermission()).thenReturn("bskyblock.island.limit.STONE.24"); + when(permAtt.getValue()).thenReturn(true); perms.add(permAtt); PermissionAttachmentInfo permAtt2 = mock(PermissionAttachmentInfo.class); when(permAtt2.getPermission()).thenReturn("bskyblock.island.limit.STONE.14"); + when(permAtt2.getValue()).thenReturn(true); perms.add(permAtt2); PermissionAttachmentInfo permAtt3 = mock(PermissionAttachmentInfo.class); when(permAtt3.getPermission()).thenReturn("bskyblock.island.limit.STONE.34"); + when(permAtt3.getValue()).thenReturn(true); perms.add(permAtt3); when(player.getEffectivePermissions()).thenReturn(perms); PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome"); @@ -392,12 +411,15 @@ public class JoinListenerTest { Set perms = new HashSet<>(); PermissionAttachmentInfo permAtt = mock(PermissionAttachmentInfo.class); when(permAtt.getPermission()).thenReturn("bskyblock.island.limit.BAT.24"); + when(permAtt.getValue()).thenReturn(true); perms.add(permAtt); PermissionAttachmentInfo permAtt2 = mock(PermissionAttachmentInfo.class); when(permAtt2.getPermission()).thenReturn("bskyblock.island.limit.BAT.14"); + when(permAtt2.getValue()).thenReturn(true); perms.add(permAtt2); PermissionAttachmentInfo permAtt3 = mock(PermissionAttachmentInfo.class); when(permAtt3.getPermission()).thenReturn("bskyblock.island.limit.BAT.34"); + when(permAtt3.getValue()).thenReturn(true); perms.add(permAtt3); when(player.getEffectivePermissions()).thenReturn(perms); PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome");