Skip to content

Commit

Permalink
Merge pull request #2454 from BentoBoxWorld/2436_placeholder
Browse files Browse the repository at this point in the history
Added placeholder to show if a player is on an island or not
  • Loading branch information
tastybento authored Aug 6, 2024
2 parents 220fc72 + ac9aa91 commit 3194195
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ public void onPlayerJoin(final PlayerJoinEvent event) {

// 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) {
Expand Down Expand Up @@ -237,6 +255,9 @@ public void onPlayerQuit(final PlayerQuitEvent event) {
});
// 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* Common Game Mode Placeholders
* All of these are prefixed with the game mode's name, e.g., bskykblock_
*/
public enum GameModePlaceholder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
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;
Expand Down Expand Up @@ -107,6 +108,9 @@ public class JoinLeaveListenerTest {
@Mock
private @NonNull Location location;

@Mock
private AddonsManager am;

/**
*/
@Before
Expand Down Expand Up @@ -218,6 +222,9 @@ public void setUp() throws Exception {
when(phm.replacePlaceholders(any(), anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));

// Addons manager
when(plugin.getAddonsManager()).thenReturn(am);

jll = new JoinLeaveListener(plugin);
}

Expand Down

0 comments on commit 3194195

Please sign in to comment.