Skip to content

Commit 3194195

Browse files
authored
Merge pull request #2454 from BentoBoxWorld/2436_placeholder
Added placeholder to show if a player is on an island or not
2 parents 220fc72 + ac9aa91 commit 3194195

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java

+21
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ public void onPlayerJoin(final PlayerJoinEvent event) {
105105

106106
// Add a player to the bStats cache.
107107
plugin.getMetrics().ifPresent(bStats -> bStats.addPlayer(playerUUID));
108+
109+
// Create onIsland placeholders
110+
plugin.getAddonsManager().getGameModeAddons().forEach(addon -> {
111+
plugin.getPlaceholdersManager()
112+
.registerPlaceholder(addon, "onisland_" + user.getName(), asker -> {
113+
if (asker == null) {
114+
return "";
115+
}
116+
// Get the user who this applies to
117+
User named = User.getInstance(user.getUniqueId());
118+
if (named.isOnline()) {
119+
return plugin.getIslands().getIslands(addon.getOverWorld(), asker).stream()
120+
.filter(island -> island.onIsland(named.getLocation())).findFirst().map(i -> "true")
121+
.orElse("false");
122+
}
123+
return "false";
124+
});
125+
});
108126
}
109127

110128
private void firstTime(User user) {
@@ -237,6 +255,9 @@ public void onPlayerQuit(final PlayerQuitEvent event) {
237255
});
238256
// Remove any coop associations from the player logging out
239257
plugin.getIslands().clearRank(RanksManager.COOP_RANK, event.getPlayer().getUniqueId());
258+
// Remove any onisland placeholder
259+
plugin.getAddonsManager().getGameModeAddons().forEach(addon -> plugin.getPlaceholdersManager()
260+
.unregisterPlaceholder(addon, "onisland_" + event.getPlayer().getName()));
240261
User.removePlayer(event.getPlayer());
241262
}
242263
}

src/main/java/world/bentobox/bentobox/lists/GameModePlaceholder.java

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/**
2121
* Common Game Mode Placeholders
22+
* All of these are prefixed with the game mode's name, e.g., bskykblock_
2223
*/
2324
public enum GameModePlaceholder {
2425

src/test/java/world/bentobox/bentobox/listeners/JoinLeaveListenerTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import world.bentobox.bentobox.api.user.User;
5353
import world.bentobox.bentobox.database.objects.Island;
5454
import world.bentobox.bentobox.database.objects.Players;
55+
import world.bentobox.bentobox.managers.AddonsManager;
5556
import world.bentobox.bentobox.managers.IslandWorldManager;
5657
import world.bentobox.bentobox.managers.IslandsManager;
5758
import world.bentobox.bentobox.managers.LocalesManager;
@@ -107,6 +108,9 @@ public class JoinLeaveListenerTest {
107108
@Mock
108109
private @NonNull Location location;
109110

111+
@Mock
112+
private AddonsManager am;
113+
110114
/**
111115
*/
112116
@Before
@@ -218,6 +222,9 @@ public void setUp() throws Exception {
218222
when(phm.replacePlaceholders(any(), anyString()))
219223
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
220224

225+
// Addons manager
226+
when(plugin.getAddonsManager()).thenReturn(am);
227+
221228
jll = new JoinLeaveListener(plugin);
222229
}
223230

0 commit comments

Comments
 (0)