mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-01 00:10:40 +01:00
Merge pull request #2454 from BentoBoxWorld/2436_placeholder
Added placeholder to show if a player is on an island or not
This commit is contained in:
commit
3194195009
@ -105,6 +105,24 @@ public class JoinLeaveListener implements Listener {
|
|||||||
|
|
||||||
// Add a player to the bStats cache.
|
// Add a player to the bStats cache.
|
||||||
plugin.getMetrics().ifPresent(bStats -> bStats.addPlayer(playerUUID));
|
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) {
|
private void firstTime(User user) {
|
||||||
@ -237,6 +255,9 @@ public class JoinLeaveListener implements Listener {
|
|||||||
});
|
});
|
||||||
// Remove any coop associations from the player logging out
|
// Remove any coop associations from the player logging out
|
||||||
plugin.getIslands().clearRank(RanksManager.COOP_RANK, event.getPlayer().getUniqueId());
|
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());
|
User.removePlayer(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Common Game Mode Placeholders
|
* Common Game Mode Placeholders
|
||||||
|
* All of these are prefixed with the game mode's name, e.g., bskykblock_
|
||||||
*/
|
*/
|
||||||
public enum GameModePlaceholder {
|
public enum GameModePlaceholder {
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ import world.bentobox.bentobox.api.addons.GameModeAddon;
|
|||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.database.objects.Players;
|
import world.bentobox.bentobox.database.objects.Players;
|
||||||
|
import world.bentobox.bentobox.managers.AddonsManager;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
import world.bentobox.bentobox.managers.LocalesManager;
|
import world.bentobox.bentobox.managers.LocalesManager;
|
||||||
@ -107,6 +108,9 @@ public class JoinLeaveListenerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private @NonNull Location location;
|
private @NonNull Location location;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AddonsManager am;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
@ -218,6 +222,9 @@ public class JoinLeaveListenerTest {
|
|||||||
when(phm.replacePlaceholders(any(), anyString()))
|
when(phm.replacePlaceholders(any(), anyString()))
|
||||||
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||||
|
|
||||||
|
// Addons manager
|
||||||
|
when(plugin.getAddonsManager()).thenReturn(am);
|
||||||
|
|
||||||
jll = new JoinLeaveListener(plugin);
|
jll = new JoinLeaveListener(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user