diff options
| author | Krakenied <krakenied1@gmail.com> | 2025-03-02 06:35:19 +0100 |
|---|---|---|
| committer | Krakenied <46192742+Krakenied@users.noreply.github.com> | 2025-05-13 20:34:15 +0200 |
| commit | a82b6d369daad16c4df0862cb459f7d517083f02 (patch) | |
| tree | 53db39a45d0f52eaad37e9ebfcb96d8d898a6913 /bukkit/src/main/java | |
| parent | 0b6b06840c4779e27536e0efe7908a29ffe6d506 (diff) | |
Small optimization to placeholders replacement
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(); + } } - - } |
