diff options
Diffstat (limited to 'bukkit/src/main/java')
| -rw-r--r-- | bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/PlaceholderAPIHook.java | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/PlaceholderAPIHook.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/PlaceholderAPIHook.java index afd298ac..1b70f295 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/PlaceholderAPIHook.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/PlaceholderAPIHook.java @@ -3,17 +3,33 @@ package com.leonardobishop.quests.bukkit.hook.papi; import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin; import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Contract; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; -public class PlaceholderAPIHook implements AbstractPlaceholderAPIHook { +@NullMarked +public final class PlaceholderAPIHook implements AbstractPlaceholderAPIHook { + @Nullable private QuestsPlaceholders placeholder; - public String replacePlaceholders(Player player, String text) { + public PlaceholderAPIHook() { + this.placeholder = null; + } + + @Contract(pure = true, value = "_, null -> null; _, !null -> !null") + public @Nullable String replacePlaceholders(final @Nullable Player player, final @Nullable String text) { if (text == null) { return null; } - if (text.indexOf('%') == -1) { + final int firstIndex = text.indexOf('%'); + if (firstIndex == -1) { + return text; + } + + final int lastIndex = text.lastIndexOf('%'); + if (lastIndex == firstIndex) { return text; } @@ -21,15 +37,15 @@ public class PlaceholderAPIHook implements AbstractPlaceholderAPIHook { } @Override - public void registerExpansion(BukkitQuestsPlugin plugin) { - placeholder = new QuestsPlaceholders(plugin); - placeholder.register(); + public void registerExpansion(final BukkitQuestsPlugin plugin) { + this.placeholder = new QuestsPlaceholders(plugin); + this.placeholder.register(); } @Override public void unregisterExpansion() { - placeholder.unregister(); + if (this.placeholder != null) { + this.placeholder.unregister(); + } } - - } |
