Added visited island UUID placeholder

Added test class for game mode placeholders.

Removed duplicated code for visited island placeholders.
This commit is contained in:
tastybento 2020-12-28 12:18:17 -08:00
parent 20ba8347a1
commit 72de0301e6
3 changed files with 710 additions and 117 deletions

View File

@ -6,8 +6,13 @@ import java.util.Date;
import java.util.Optional;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.placeholders.GameModePlaceholderReplacer;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util;
@ -15,6 +20,9 @@ import world.bentobox.bentobox.util.Util;
public enum GameModePlaceholder {
/* World-related */
/**
* World friendly name
*/
WORLD_FRIENDLY_NAME("world_friendly_name", (addon, user, island) -> addon.getWorldSettings().getFriendlyName()),
/**
* Returns the amount of islands in the world.
@ -120,57 +128,32 @@ public enum GameModePlaceholder {
* Returns the protection range of the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_PROTECTION_RANGE("visited_island_protection_range", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> String.valueOf(value.getProtectionRange())).orElse("");
}),
VISITED_ISLAND_PROTECTION_RANGE("visited_island_protection_range", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> String.valueOf(value.getProtectionRange())).orElse("")),
/**
* Returns the protection range of the island the player is standing on as a diameter.
* @since 1.5.2
*/
VISITED_ISLAND_PROTECTION_RANGE_DIAMETER("visited_island_protection_range_diameter", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> String.valueOf(2*value.getProtectionRange())).orElse("");
}),
VISITED_ISLAND_PROTECTION_RANGE_DIAMETER("visited_island_protection_range_diameter", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> String.valueOf(2*value.getProtectionRange())).orElse("")),
/**
* Returns the name of the owner of the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_OWNER("visited_island_owner", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> addon.getPlayers().getName(value.getOwner())).orElse("");
}),
VISITED_ISLAND_OWNER("visited_island_owner", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> addon.getPlayers().getName(value.getOwner())).orElse("")),
/**
* Returns the formatted creation date of the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_CREATION_DATE("visited_island_creation_date", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> DateFormat.getInstance().format(Date.from(Instant.ofEpochMilli(value.getCreatedDate())))).orElse("");
}),
VISITED_ISLAND_CREATION_DATE("visited_island_creation_date", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> DateFormat.getInstance().format(Date.from(Instant.ofEpochMilli(value.getCreatedDate())))).orElse("")),
/**
* Returns the name of the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_NAME("visited_island_name", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(is -> {
return getVisitedIsland(addon, user).map(is -> {
if (is.getName() != null) {
return is.getName();
} else {
@ -182,131 +165,83 @@ public enum GameModePlaceholder {
* Returns the coordinates of the center of the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_CENTER("visited_island_center", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> Util.xyz(value.getCenter().toVector())).orElse("");
}),
VISITED_ISLAND_CENTER("visited_island_center", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> Util.xyz(value.getCenter().toVector())).orElse("")),
/**
* Returns the X coordinate of the center of the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_CENTER_X("visited_island_center_x", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> String.valueOf(value.getCenter().getBlockX())).orElse("");
}),
VISITED_ISLAND_CENTER_X("visited_island_center_x", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> String.valueOf(value.getCenter().getBlockX())).orElse("")),
/**
* Returns the Y coordinate of the center of the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_CENTER_Y("visited_island_center_y", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> String.valueOf(value.getCenter().getBlockY())).orElse("");
}),
VISITED_ISLAND_CENTER_Y("visited_island_center_y", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> String.valueOf(value.getCenter().getBlockY())).orElse("")),
/**
* Returns the Z coordinate of the center of the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_CENTER_Z("visited_island_center_z", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> String.valueOf(value.getCenter().getBlockZ())).orElse("");
}),
VISITED_ISLAND_CENTER_Z("visited_island_center_z", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> String.valueOf(value.getCenter().getBlockZ())).orElse("")),
/**
* Returns the maximum number of members the island the player is standing on can have.
* @since 1.5.2
*/
VISITED_ISLAND_MEMBERS_MAX("visited_island_members_max", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> String.valueOf(user.getPermissionValue(addon.getPermissionPrefix() + "team.maxsize", addon.getPlugin().getIWM().getMaxTeamSize(addon.getOverWorld())))).orElse("");
}),
VISITED_ISLAND_MEMBERS_MAX("visited_island_members_max", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> String.valueOf(user.getPermissionValue(addon.getPermissionPrefix() + "team.maxsize", addon.getPlugin().getIWM().getMaxTeamSize(addon.getOverWorld())))).orElse("")),
/**
* Returns a comma separated list of player names that are at least MEMBER on the island the player is standing on.
* @since 1.13.0
*/
VISITED_ISLAND_MEMBERS_LIST("visited_island_members_list", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> value.getMemberSet(RanksManager.MEMBER_RANK).stream()
.map(addon.getPlayers()::getName).collect(Collectors.joining(","))).orElse("");
}),
VISITED_ISLAND_MEMBERS_LIST("visited_island_members_list", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> value.getMemberSet(RanksManager.MEMBER_RANK).stream()
.map(addon.getPlayers()::getName).collect(Collectors.joining(","))).orElse("")),
/**
* Returns the amount of players that are at least MEMBER on the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_MEMBERS_COUNT("visited_island_members_count", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> String.valueOf(value.getMemberSet().size())).orElse("");
}),
VISITED_ISLAND_MEMBERS_COUNT("visited_island_members_count", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> String.valueOf(value.getMemberSet().size())).orElse("")),
/**
* Returns the amount of players that are TRUSTED on the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_TRUSTEES_COUNT("visited_island_trustees_count", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> String.valueOf(value.getMemberSet(RanksManager.TRUSTED_RANK, false).size())).orElse("");
}),
VISITED_ISLAND_TRUSTEES_COUNT("visited_island_trustees_count", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> String.valueOf(value.getMemberSet(RanksManager.TRUSTED_RANK, false).size())).orElse("")),
/**
* Returns the amount of players that are TRUSTED on the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_COOPS_COUNT("visited_island_coops_count", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> String.valueOf(value.getMemberSet(RanksManager.COOP_RANK, false).size())).orElse("");
}),
VISITED_ISLAND_COOPS_COUNT("visited_island_coops_count", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> String.valueOf(value.getMemberSet(RanksManager.COOP_RANK, false).size())).orElse("")),
/**
* Returns the amount of players that are currently visiting the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_VISITORS_COUNT("visited_island_visitors_count", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> String.valueOf(value.getVisitors().size())).orElse("");
}),
VISITED_ISLAND_VISITORS_COUNT("visited_island_visitors_count", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> String.valueOf(value.getVisitors().size())).orElse("")),
/**
* Returns the amount of players banned from the island the player is standing on.
* @since 1.5.2
*/
VISITED_ISLAND_BANS_COUNT("visited_island_bans_count", (addon, user, island) -> {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return "";
}
Optional<Island> visitedIsland = addon.getIslands().getIslandAt(user.getLocation());
return visitedIsland.map(value -> String.valueOf(value.getBanned().size())).orElse("");
}),
VISITED_ISLAND_BANS_COUNT("visited_island_bans_count", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> String.valueOf(value.getBanned().size())).orElse("")),
/**
* Get the visited island unique ID
* @since 1.15.4
*/
VISITED_ISLAND_UUID("visited_island_uuid", (addon, user, island) ->
getVisitedIsland(addon, user).map(Island::getUniqueId).orElse("")),
/* Player-related */
/**
* Returns whether this player has an island or not.
* @since 1.5.0
*/
HAS_ISLAND("has_island", (addon, user, island) -> String.valueOf(island != null)),
HAS_ISLAND("has_island", (addon, user, island) -> String.valueOf(user != null && island != null)),
/**
* Returns the rank this player has on his island.
* @since 1.5.0
@ -316,18 +251,18 @@ public enum GameModePlaceholder {
* Returns how many times this player reset his island.
* @since 1.5.0
*/
RESETS("resets", (addon, user, island) -> String.valueOf(addon.getPlayers().getResets(addon.getOverWorld(), user.getUniqueId()))),
RESETS("resets", (addon, user, island) -> user == null ? "" : String.valueOf(addon.getPlayers().getResets(addon.getOverWorld(), user.getUniqueId()))),
/**
* Returns how many times this player can reset his island.
* {@code -1} is unlimited.
* @since 1.5.0
*/
RESETS_LEFT("resets_left", (addon, user, island) -> String.valueOf(addon.getPlayers().getResetsLeft(addon.getOverWorld(), user.getUniqueId()))),
RESETS_LEFT("resets_left", (addon, user, island) -> user == null ? "" : String.valueOf(addon.getPlayers().getResetsLeft(addon.getOverWorld(), user.getUniqueId()))),
/**
* Returns how many times this player died.
* @since 1.12.0
*/
DEATHS("deaths", (addon, user, island) -> String.valueOf(addon.getPlayers().getDeaths(addon.getOverWorld(), user.getUniqueId()))),
DEATHS("deaths", (addon, user, island) -> user == null ? "" : String.valueOf(addon.getPlayers().getDeaths(addon.getOverWorld(), user.getUniqueId()))),
/**
* Returns whether this player is on his island and has a rank greater than VISITOR_RANK
* @since 1.13.0
@ -337,7 +272,7 @@ public enum GameModePlaceholder {
* Returns whether this player is an owner of their island
* @since 1.14.0
*/
OWNS_ISLAND("owns_island", (addon, user, island) -> String.valueOf(island != null && user.getUniqueId().equals(island.getOwner())));
OWNS_ISLAND("owns_island", (addon, user, island) -> String.valueOf(island != null && user != null && user.getUniqueId().equals(island.getOwner())));
private String placeholder;
/**
@ -350,6 +285,19 @@ public enum GameModePlaceholder {
this.replacer = replacer;
}
/**
* Get the visited island
* @param addon - game mode addon
* @param user - user visiting
* @return optional island
*/
private static Optional<Island> getVisitedIsland(@NonNull GameModeAddon addon, @Nullable User user) {
if (user == null || !user.isPlayer() || user.getLocation() == null) {
return Optional.empty();
}
return addon.getIslands().getIslandAt(user.getLocation());
}
public String getPlaceholder() {
return placeholder;
}

View File

@ -0,0 +1,409 @@
package world.bentobox.bentobox;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.entity.EntityType;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.flags.Flag;
/**
* Class for tests that require world settings
* @author tastybento
*
*/
public class TestWorldSettings implements WorldSettings {
private long epoch;
@Override
public GameMode getDefaultGameMode() {
return GameMode.SURVIVAL;
}
@Override
public Map<Flag, Integer> getDefaultIslandFlags() {
return Collections.emptyMap();
}
@Override
public Map<Flag, Integer> getDefaultIslandSettings() {
return Collections.emptyMap();
}
@Override
public Difficulty getDifficulty() {
return Difficulty.EASY;
}
@Override
public void setDifficulty(Difficulty difficulty) {
}
@Override
public String getFriendlyName() {
return "friendly_name";
}
@Override
public int getIslandDistance() {
return 0;
}
@Override
public int getIslandHeight() {
return 0;
}
@Override
public int getIslandProtectionRange() {
return 0;
}
@Override
public int getIslandStartX() {
return 0;
}
@Override
public int getIslandStartZ() {
return 0;
}
@Override
public int getIslandXOffset() {
return 0;
}
@Override
public int getIslandZOffset() {
return 0;
}
@Override
public List<String> getIvSettings() {
return Collections.emptyList();
}
@Override
public int getMaxHomes() {
return 3;
}
@Override
public int getMaxIslands() {
return 0;
}
@Override
public int getMaxTeamSize() {
return 4;
}
@Override
public int getNetherSpawnRadius() {
return 10;
}
@Override
public String getPermissionPrefix() {
return "perm.";
}
@Override
public Set<EntityType> getRemoveMobsWhitelist() {
return Collections.emptySet();
}
@Override
public int getSeaHeight() {
return 0;
}
@Override
public List<String> getHiddenFlags() {
return Collections.emptyList();
}
@Override
public List<String> getVisitorBannedCommands() {
return Collections.emptyList();
}
@Override
public Map<String, Boolean> getWorldFlags() {
return Collections.emptyMap();
}
@Override
public String getWorldName() {
return "world_name";
}
@Override
public boolean isDragonSpawn() {
return false;
}
@Override
public boolean isEndGenerate() {
return true;
}
@Override
public boolean isEndIslands() {
return true;
}
@Override
public boolean isNetherGenerate() {
return true;
}
@Override
public boolean isNetherIslands() {
return true;
}
@Override
public boolean isOnJoinResetEnderChest() {
return false;
}
@Override
public boolean isOnJoinResetInventory() {
return false;
}
@Override
public boolean isOnJoinResetMoney() {
return false;
}
@Override
public boolean isOnJoinResetHealth() {
return false;
}
@Override
public boolean isOnJoinResetHunger() {
return false;
}
@Override
public boolean isOnJoinResetXP() {
return false;
}
@Override
public @NonNull List<String> getOnJoinCommands() {
return Collections.emptyList();
}
@Override
public boolean isOnLeaveResetEnderChest() {
return false;
}
@Override
public boolean isOnLeaveResetInventory() {
return false;
}
@Override
public boolean isOnLeaveResetMoney() {
return false;
}
@Override
public boolean isOnLeaveResetHealth() {
return false;
}
@Override
public boolean isOnLeaveResetHunger() {
return false;
}
@Override
public boolean isOnLeaveResetXP() {
return false;
}
@Override
public @NonNull List<String> getOnLeaveCommands() {
return Collections.emptyList();
}
@Override
public boolean isUseOwnGenerator() {
return false;
}
@Override
public boolean isWaterUnsafe() {
return false;
}
@Override
public List<String> getGeoLimitSettings() {
return Collections.emptyList();
}
@Override
public int getResetLimit() {
return 0;
}
@Override
public long getResetEpoch() {
return epoch;
}
@Override
public void setResetEpoch(long timestamp) {
this.epoch = timestamp;
}
@Override
public boolean isTeamJoinDeathReset() {
return false;
}
@Override
public int getDeathsMax() {
return 0;
}
@Override
public boolean isDeathsCounted() {
return true;
}
@Override
public boolean isDeathsResetOnNewIsland() {
return true;
}
@Override
public boolean isAllowSetHomeInNether() {
return false;
}
@Override
public boolean isAllowSetHomeInTheEnd() {
return false;
}
@Override
public boolean isRequireConfirmationToSetHomeInNether() {
return false;
}
@Override
public boolean isRequireConfirmationToSetHomeInTheEnd() {
return false;
}
@Override
public int getBanLimit() {
return 10;
}
@Override
public boolean isLeaversLoseReset() {
return true;
}
@Override
public boolean isKickedKeepInventory() {
return true;
}
@Override
public boolean isCreateIslandOnFirstLoginEnabled() {
return false;
}
@Override
public int getCreateIslandOnFirstLoginDelay() {
return 0;
}
@Override
public boolean isCreateIslandOnFirstLoginAbortOnLogout() {
return false;
}
}

View File

@ -0,0 +1,236 @@
package world.bentobox.bentobox.lists;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import java.util.Optional;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.World;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.stubbing.Answer;
import org.powermock.modules.junit4.PowerMockRunner;
import com.google.common.collect.ImmutableSet;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.TestWorldSettings;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.configuration.WorldSettings;
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.managers.PlayersManager;
import world.bentobox.bentobox.managers.RanksManager;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
public class GameModePlaceholderTest {
@Mock
private GameModeAddon addon;
@Mock
private User user;
@Mock
private Island island;
@Mock
private PlayersManager pm;
private UUID uuid;
@Mock
private World world;
@Mock
private BentoBox plugin;
@Mock
private IslandWorldManager iwm;
@Mock
private IslandsManager im;
private RanksManager rm = new RanksManager();
@Mock
private @Nullable Location location;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
uuid = UUID.randomUUID();
when(addon.getPlayers()).thenReturn(pm);
when(addon.getIslands()).thenReturn(im);
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPermissionValue(anyString(), anyInt())).thenReturn(10);
when(addon.getOverWorld()).thenReturn(world);
when(addon.getPlugin()).thenReturn(plugin);
when(addon.getPermissionPrefix()).thenReturn("MyGameMode.");
when(island.getCenter()).thenReturn(new Location(world, 123, 456, 789));
when(island.getOwner()).thenReturn(uuid);
when(island.getUniqueId()).thenReturn(uuid.toString());
when(island.getMemberSet()).thenReturn(ImmutableSet.of(uuid));
when(island.getMemberSet(anyInt(), anyBoolean())).thenReturn(ImmutableSet.of(uuid));
when(island.getMemberSet(anyInt())).thenReturn(ImmutableSet.of(uuid));
when(island.getName()).thenReturn("island");
when(island.getRank(any(User.class))).thenReturn(RanksManager.OWNER_RANK);
WorldSettings ws = new TestWorldSettings();
when(addon.getWorldSettings()).thenReturn(ws);
when(pm.getName(any())).thenReturn("tastybento");
when(plugin.getIWM()).thenReturn(iwm);
when(plugin.getRanksManager()).thenReturn(rm);
when(user.getTranslation(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getLocation()).thenReturn(location);
when(im.getIslandAt(any())).thenReturn(Optional.of(island));
when(user.isPlayer()).thenReturn(true);
}
/**
* Test method for {@link world.bentobox.bentobox.lists.GameModePlaceholder#getReplacer()}.
*/
@Test
public void testGetReplacerIsland() {
assertEquals("0", GameModePlaceholder.ISLAND_BANS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("123,456,789", GameModePlaceholder.ISLAND_CENTER.getReplacer().onReplace(addon, user, island));
assertEquals("123", GameModePlaceholder.ISLAND_CENTER_X.getReplacer().onReplace(addon, user, island));
assertEquals("456", GameModePlaceholder.ISLAND_CENTER_Y.getReplacer().onReplace(addon, user, island));
assertEquals("789", GameModePlaceholder.ISLAND_CENTER_Z.getReplacer().onReplace(addon, user, island));
assertEquals("1", GameModePlaceholder.ISLAND_COOPS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("12/31/69 4:00 PM", GameModePlaceholder.ISLAND_CREATION_DATE.getReplacer().onReplace(addon, user, island));
assertEquals("1", GameModePlaceholder.ISLAND_MEMBERS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("tastybento", GameModePlaceholder.ISLAND_MEMBERS_LIST.getReplacer().onReplace(addon, user, island));
assertEquals("10", GameModePlaceholder.ISLAND_MEMBERS_MAX.getReplacer().onReplace(addon, user, island));
assertEquals("island", GameModePlaceholder.ISLAND_NAME.getReplacer().onReplace(addon, user, island));
assertEquals("tastybento", GameModePlaceholder.ISLAND_OWNER.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.ISLAND_PROTECTION_RANGE.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.ISLAND_PROTECTION_RANGE_DIAMETER.getReplacer().onReplace(addon, user, island));
assertEquals("1", GameModePlaceholder.ISLAND_TRUSTEES_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals(uuid.toString(), GameModePlaceholder.ISLAND_UUID.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.ISLAND_VISITORS_COUNT.getReplacer().onReplace(addon, user, island));
}
/**
* Test method for {@link world.bentobox.bentobox.lists.GameModePlaceholder#getReplacer()}.
*/
@Test
public void testGetReplacerNullIsland() {
island = null;
assertEquals("", GameModePlaceholder.ISLAND_BANS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_CENTER.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_CENTER_X.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_CENTER_Y.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_CENTER_Z.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_COOPS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_CREATION_DATE.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_MEMBERS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_MEMBERS_LIST.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_MEMBERS_MAX.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_NAME.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_OWNER.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_PROTECTION_RANGE.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_PROTECTION_RANGE_DIAMETER.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_TRUSTEES_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_UUID.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.ISLAND_VISITORS_COUNT.getReplacer().onReplace(addon, user, island));
}
/**
* Test method for {@link world.bentobox.bentobox.lists.GameModePlaceholder#getReplacer()}.
*/
@Test
public void testGetReplacerPlayer() {
assertEquals("deaths", GameModePlaceholder.DEATHS.getPlaceholder());
assertEquals("0", GameModePlaceholder.DEATHS.getReplacer().onReplace(addon, user, island));
assertEquals("true", GameModePlaceholder.HAS_ISLAND.getReplacer().onReplace(addon, user, island));
assertEquals("false", GameModePlaceholder.ON_ISLAND.getReplacer().onReplace(addon, user, island));
assertEquals("true", GameModePlaceholder.OWNS_ISLAND.getReplacer().onReplace(addon, user, island));
assertEquals("ranks.owner", GameModePlaceholder.RANK.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.RESETS.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.RESETS_LEFT.getReplacer().onReplace(addon, user, island));
}
/**
* Test method for {@link world.bentobox.bentobox.lists.GameModePlaceholder#getReplacer()}.
*/
@Test
public void testGetReplacerNullPlayer() {
user = null;
assertEquals("", GameModePlaceholder.DEATHS.getReplacer().onReplace(addon, user, island));
assertEquals("false", GameModePlaceholder.HAS_ISLAND.getReplacer().onReplace(addon, user, island));
assertEquals("false", GameModePlaceholder.ON_ISLAND.getReplacer().onReplace(addon, user, island));
assertEquals("false", GameModePlaceholder.OWNS_ISLAND.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.RANK.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.RESETS.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.RESETS_LEFT.getReplacer().onReplace(addon, user, island));
}
/**
* Test method for {@link world.bentobox.bentobox.lists.GameModePlaceholder#getReplacer()}.
*/
@Test
public void testGetReplacerVisitedIslands() {
assertEquals("0", GameModePlaceholder.VISITED_ISLAND_BANS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("123,456,789", GameModePlaceholder.VISITED_ISLAND_CENTER.getReplacer().onReplace(addon, user, island));
assertEquals("123", GameModePlaceholder.VISITED_ISLAND_CENTER_X.getReplacer().onReplace(addon, user, island));
assertEquals("456", GameModePlaceholder.VISITED_ISLAND_CENTER_Y.getReplacer().onReplace(addon, user, island));
assertEquals("789", GameModePlaceholder.VISITED_ISLAND_CENTER_Z.getReplacer().onReplace(addon, user, island));
assertEquals("1", GameModePlaceholder.VISITED_ISLAND_COOPS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("12/31/69 4:00 PM", GameModePlaceholder.VISITED_ISLAND_CREATION_DATE.getReplacer().onReplace(addon, user, island));
assertEquals("1", GameModePlaceholder.VISITED_ISLAND_MEMBERS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("tastybento", GameModePlaceholder.VISITED_ISLAND_MEMBERS_LIST.getReplacer().onReplace(addon, user, island));
assertEquals("10", GameModePlaceholder.VISITED_ISLAND_MEMBERS_MAX.getReplacer().onReplace(addon, user, island));
assertEquals("island", GameModePlaceholder.VISITED_ISLAND_NAME.getReplacer().onReplace(addon, user, island));
assertEquals("tastybento", GameModePlaceholder.VISITED_ISLAND_OWNER.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.VISITED_ISLAND_PROTECTION_RANGE.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.VISITED_ISLAND_PROTECTION_RANGE_DIAMETER.getReplacer().onReplace(addon, user, island));
assertEquals("1", GameModePlaceholder.VISITED_ISLAND_TRUSTEES_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals(uuid.toString(), GameModePlaceholder.VISITED_ISLAND_UUID.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.VISITED_ISLAND_VISITORS_COUNT.getReplacer().onReplace(addon, user, island));
}
/**
* Test method for {@link world.bentobox.bentobox.lists.GameModePlaceholder#getReplacer()}.
*/
@Test
public void testGetReplacerVisitedIslandsNoIsland() {
when(im.getIslandAt(any())).thenReturn(Optional.empty());
assertEquals("", GameModePlaceholder.VISITED_ISLAND_BANS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_CENTER.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_CENTER_X.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_CENTER_Y.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_CENTER_Z.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_COOPS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_CREATION_DATE.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_MEMBERS_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_MEMBERS_LIST.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_MEMBERS_MAX.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_NAME.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_OWNER.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_PROTECTION_RANGE.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_PROTECTION_RANGE_DIAMETER.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_TRUSTEES_COUNT.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_UUID.getReplacer().onReplace(addon, user, island));
assertEquals("", GameModePlaceholder.VISITED_ISLAND_VISITORS_COUNT.getReplacer().onReplace(addon, user, island));
}
/**
* Test method for {@link world.bentobox.bentobox.lists.GameModePlaceholder#getReplacer()}.
*/
@Test
public void testGetReplacerWorld() {
assertEquals("0", GameModePlaceholder.ISLAND_DISTANCE.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.ISLAND_DISTANCE_DIAMETER.getReplacer().onReplace(addon, user, island));
assertEquals("friendly_name", GameModePlaceholder.WORLD_FRIENDLY_NAME.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.WORLD_ISLANDS.getReplacer().onReplace(addon, user, island));
}
}