From 79ca7512d1d9e2cd1ed97c540ffae9fedc7cf995 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sun, 7 Apr 2019 10:02:55 +0200 Subject: [PATCH] Made the gamemode placeholders no longer return an empty string if player doesn't have an island --- .../bentobox/lists/GameModePlaceholders.java | 16 ++++++++-------- .../managers/GameModePlaceholderManager.java | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholders.java b/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholders.java index 5f64ae9d2..29be222dd 100644 --- a/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholders.java +++ b/src/main/java/world/bentobox/bentobox/lists/GameModePlaceholders.java @@ -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; /** diff --git a/src/main/java/world/bentobox/bentobox/managers/GameModePlaceholderManager.java b/src/main/java/world/bentobox/bentobox/managers/GameModePlaceholderManager.java index a65d356b6..3b19cabfc 100644 --- a/src/main/java/world/bentobox/bentobox/managers/GameModePlaceholderManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/GameModePlaceholderManager.java @@ -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); }