From 9ed606e84b12d218ffe3849797e9cf5ca9462517 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 21 Feb 2024 20:57:29 -0800 Subject: [PATCH] Fix perm issue #120 (#121) --- .../border/listeners/PlayerListener.java | 16 +++++++++------- .../border/listeners/PlayerListenerTest.java | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/java/world/bentobox/border/listeners/PlayerListener.java b/src/main/java/world/bentobox/border/listeners/PlayerListener.java index 66a9604..4481b70 100644 --- a/src/main/java/world/bentobox/border/listeners/PlayerListener.java +++ b/src/main/java/world/bentobox/border/listeners/PlayerListener.java @@ -65,17 +65,19 @@ protected void processEvent(PlayerJoinEvent e) { // Just for sure, disable world Border user.getPlayer().setWorldBorder(null); - // Check player perms and return to defaults if players don't have them - if (!e.getPlayer().hasPermission(addon.getPermissionPrefix() + IslandBorderCommand.BORDER_COMMAND_PERM)) { - // Restore barrier on/off to default - user.putMetaData(BorderShower.BORDER_STATE_META_DATA, new MetaDataValue(addon.getSettings().isShowByDefault())); - - if (!e.getPlayer().hasPermission(addon.getPermissionPrefix() + BorderTypeCommand.BORDER_TYPE_COMMAND_PERM)) { + // Get the game mode that this player is in + addon.getPlugin().getIWM().getAddon(e.getPlayer().getWorld()).map(gma -> gma.getPermissionPrefix()).filter( + permPrefix -> !e.getPlayer().hasPermission(permPrefix + IslandBorderCommand.BORDER_COMMAND_PERM)) + .ifPresent(permPrefix -> { + // Restore barrier on/off to default + user.putMetaData(BorderShower.BORDER_STATE_META_DATA, + new MetaDataValue(addon.getSettings().isShowByDefault())); + if (!e.getPlayer().hasPermission(permPrefix + BorderTypeCommand.BORDER_TYPE_COMMAND_PERM)) { // Restore default barrier type to player MetaDataValue metaDataValue = new MetaDataValue(addon.getSettings().getType().getId()); user.putMetaData(PerPlayerBorderProxy.BORDER_BORDERTYPE_META_DATA, metaDataValue); } - } + }); // Show the border if required one tick after Bukkit.getScheduler().runTask(addon.getPlugin(), () -> addon.getIslands().getIslandAt(e.getPlayer().getLocation()).ifPresent(i -> diff --git a/src/test/java/world/bentobox/border/listeners/PlayerListenerTest.java b/src/test/java/world/bentobox/border/listeners/PlayerListenerTest.java index 3a62045..632369f 100644 --- a/src/test/java/world/bentobox/border/listeners/PlayerListenerTest.java +++ b/src/test/java/world/bentobox/border/listeners/PlayerListenerTest.java @@ -40,9 +40,11 @@ import org.powermock.modules.junit4.PowerMockRunner; import world.bentobox.bentobox.BentoBox; +import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.api.events.island.IslandProtectionRangeChangeEvent; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.objects.Island; +import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.util.Util; import world.bentobox.border.Border; @@ -82,6 +84,10 @@ public class PlayerListenerTest { private Island island; @Mock private Vehicle vehicle; + @Mock + private IslandWorldManager iwm; + @Mock + private GameModeAddon gma; /** @@ -135,6 +141,15 @@ public void setUp() throws Exception { // Util PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS); + // Plugin + when(addon.getPlugin()).thenReturn(plugin); + + // IWM + when(gma.getPermissionPrefix()).thenReturn("bskyblock."); + when(iwm.getAddon(world)).thenReturn(Optional.of(gma)); + when(plugin.getIWM()).thenReturn(iwm); + + pl = new PlayerListener(addon); } @@ -178,7 +193,7 @@ public void testOnPlayerQuit() { */ @Test public void testOnPlayerRespawn() { - PlayerRespawnEvent event = new PlayerRespawnEvent(player, null, false, false); + PlayerRespawnEvent event = new PlayerRespawnEvent(player, from, false, false, null); pl.onPlayerRespawn(event); PowerMockito.verifyStatic(Bukkit.class); Bukkit.getScheduler();