diff --git a/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java b/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java index 605e020c3..11c750889 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java @@ -105,6 +105,24 @@ public class JoinLeaveListener implements Listener { // Add a player to the bStats cache. plugin.getMetrics().ifPresent(bStats -> bStats.addPlayer(playerUUID)); + + // Create onIsland placeholders + plugin.getAddonsManager().getGameModeAddons().forEach(addon -> { + plugin.getPlaceholdersManager() + .registerPlaceholder(addon, "onisland_" + user.getName(), asker -> { + if (asker == null) { + return ""; + } + // Get the user who this applies to + User named = User.getInstance(user.getUniqueId()); + if (named.isOnline()) { + return plugin.getIslands().getIslands(addon.getOverWorld(), asker).stream() + .filter(island -> island.onIsland(named.getLocation())).findFirst().map(i -> "true") + .orElse("false"); + } + return "false"; + }); + }); } private void firstTime(User user) { @@ -237,6 +255,9 @@ public class JoinLeaveListener implements Listener { }); // Remove any coop associations from the player logging out plugin.getIslands().clearRank(RanksManager.COOP_RANK, event.getPlayer().getUniqueId()); + // Remove any onisland placeholder + plugin.getAddonsManager().getGameModeAddons().forEach(addon -> plugin.getPlaceholdersManager() + .unregisterPlaceholder(addon, "onisland_" + event.getPlayer().getName())); User.removePlayer(event.getPlayer()); } } diff --git a/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java b/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java index 5677b3c89..032617d26 100644 --- a/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java +++ b/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java @@ -19,6 +19,7 @@ import world.bentobox.bentobox.util.Util; /** * Common Game Mode Placeholders + * All of these are prefixed with the game mode's name, e.g., bskykblock_ */ public enum GameModePlaceholder { diff --git a/src/test/java/world/bentobox/bentobox/listeners/JoinLeaveListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/JoinLeaveListenerTest.java index 21127e72e..43a8b1e1e 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/JoinLeaveListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/JoinLeaveListenerTest.java @@ -52,6 +52,7 @@ import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Players; +import world.bentobox.bentobox.managers.AddonsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; @@ -107,6 +108,9 @@ public class JoinLeaveListenerTest { @Mock private @NonNull Location location; + @Mock + private AddonsManager am; + /** */ @Before @@ -218,6 +222,9 @@ public class JoinLeaveListenerTest { when(phm.replacePlaceholders(any(), anyString())) .thenAnswer((Answer) invocation -> invocation.getArgument(1, String.class)); + // Addons manager + when(plugin.getAddonsManager()).thenReturn(am); + jll = new JoinLeaveListener(plugin); }