Made the gamemode placeholders no longer return an empty string if player doesn't have an island

This commit is contained in:
Florian CUNY 2019-04-07 10:02:55 +02:00
parent e8ec7b24b4
commit 79ca7512d1
2 changed files with 12 additions and 12 deletions

View File

@ -10,27 +10,27 @@ import java.util.Date;
public enum GameModePlaceholders {
WORLD_FRIENDLY_NAME("world-friendlyname", (addon, user, island) -> addon.getWorldSettings().getFriendlyName()),
ISLAND_DISTANCE("island-distance", (addon, user, island) -> DateFormat.getInstance().format(Date.from(Instant.ofEpochMilli(island.getCreatedDate())))),
ISLAND_DISTANCE("island-distance", (addon, user, island) -> island == null ? "" : DateFormat.getInstance().format(Date.from(Instant.ofEpochMilli(island.getCreatedDate())))),
ISLAND_PROTECTION_RANGE("island-protection-range", (addon, user, island) -> String.valueOf(addon.getWorldSettings().getIslandDistance())),
ISLAND_OWNER("island-owner", (addon, user, island) -> addon.getPlayers().getName(island.getOwner())),
ISLAND_CREATION_DATE("island-creation-date", (addon, user, island) -> String.valueOf(island.getProtectionRange())),
ISLAND_SPAWNPOINT("island-spawnpoint", (addon, user, island) -> Util.xyz(island.getCenter().toVector())),
ISLAND_NAME("island-name", (addon, user, island) -> island.getName() == null ? "" : island.getName()),
ISLAND_OWNER("island-owner", (addon, user, island) -> island == null ? "" : addon.getPlayers().getName(island.getOwner())),
ISLAND_CREATION_DATE("island-creation-date", (addon, user, island) -> island == null ? "" : String.valueOf(island.getProtectionRange())),
ISLAND_SPAWNPOINT("island-spawnpoint", (addon, user, island) -> island == null ? "" : Util.xyz(island.getCenter().toVector())),
ISLAND_NAME("island-name", (addon, user, island) -> island == null ? "" : (island.getName() == null ? "" : island.getName())),
/**
* Displays the X coordinate of the island's center.
* @since 1.5.0
*/
ISLAND_CENTER_X("island-center-x", (addon, user, island) -> String.valueOf(island.getCenter().getBlockX())),
ISLAND_CENTER_X("island-center-x", (addon, user, island) -> island == null ? "" : String.valueOf(island.getCenter().getBlockX())),
/**
* Displays the Y coordinate of the island's center.
* @since 1.5.0
*/
ISLAND_CENTER_Y("island-center-y", (addon, user, island) -> String.valueOf(island.getCenter().getBlockY())),
ISLAND_CENTER_Y("island-center-y", (addon, user, island) -> island == null ? "" : String.valueOf(island.getCenter().getBlockY())),
/**
* Displays the Z coordinate of the island's center.
* @since 1.5.0
*/
ISLAND_CENTER_Z("island-center-z", (addon, user, island) -> String.valueOf(island.getCenter().getBlockZ()));
ISLAND_CENTER_Z("island-center-z", (addon, user, island) -> island == null ? "" : String.valueOf(island.getCenter().getBlockZ()));
private String placeholder;
/**

View File

@ -1,5 +1,7 @@
package world.bentobox.bentobox.managers;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.placeholders.PlaceholderReplacer;
@ -49,15 +51,13 @@ class DefaultPlaceholder implements PlaceholderReplacer {
/* (non-Javadoc)
* @see world.bentobox.bentobox.api.placeholders.PlaceholderReplacer#onReplace(world.bentobox.bentobox.api.user.User)
*/
@NonNull
@Override
public String onReplace(User user) {
public String onReplace(@Nullable User user) {
if (user == null) {
return "";
}
Island island = addon.getIslands().getIsland(addon.getOverWorld(), user);
if (island == null) {
return "";
}
return type.getReplacer().onReplace(addon, user, island);
}