aboutsummaryrefslogtreecommitdiffstats
path: root/bukkit/src/main/java/com/leonardobishop
diff options
context:
space:
mode:
authorKrakenied <krakenied1@gmail.com>2025-06-05 02:51:12 +0200
committerKrakenied <46192742+Krakenied@users.noreply.github.com>2025-07-29 00:06:46 +0200
commit50c639f9abe01f751271d9c58c0bd185d32cd781 (patch)
treeca905730f6dc9b6d8cec607d2ee0dcd5cb041ce8 /bukkit/src/main/java/com/leonardobishop
parent3efb11c01162744150b788f790a629305108f709 (diff)
PlaceholderAPI hook cleanup
Diffstat (limited to 'bukkit/src/main/java/com/leonardobishop')
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/AbstractPlaceholderAPIHook.java10
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/PlaceholderAPIHook.java14
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/DisplayNameUtil.java39
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/EnumUtil.java35
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/TriFunction.java13
5 files changed, 103 insertions, 8 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/AbstractPlaceholderAPIHook.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/AbstractPlaceholderAPIHook.java
index 144c2ecd..8404d5fe 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/AbstractPlaceholderAPIHook.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/AbstractPlaceholderAPIHook.java
@@ -1,14 +1,20 @@
package com.leonardobishop.quests.bukkit.hook.papi;
import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
+import com.leonardobishop.quests.common.util.Modern;
import org.bukkit.entity.Player;
+import org.jetbrains.annotations.Contract;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+@Modern(type = Modern.Type.FULL)
+@NullMarked
public interface AbstractPlaceholderAPIHook {
- String replacePlaceholders(Player player, String text);
+ @Contract(pure = true, value = "_, null -> null; _, !null -> !null")
+ @Nullable String replacePlaceholders(@Nullable Player player, @Nullable String text);
void registerExpansion(BukkitQuestsPlugin plugin);
void unregisterExpansion();
-
}
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 1b70f295..a0b8211f 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
@@ -1,20 +1,22 @@
package com.leonardobishop.quests.bukkit.hook.papi;
import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
+import com.leonardobishop.quests.common.util.Modern;
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;
+@Modern(type = Modern.Type.FULL)
@NullMarked
public final class PlaceholderAPIHook implements AbstractPlaceholderAPIHook {
@Nullable
- private QuestsPlaceholders placeholder;
+ private QuestsPlaceholders expansion;
public PlaceholderAPIHook() {
- this.placeholder = null;
+ this.expansion = null;
}
@Contract(pure = true, value = "_, null -> null; _, !null -> !null")
@@ -38,14 +40,14 @@ public final class PlaceholderAPIHook implements AbstractPlaceholderAPIHook {
@Override
public void registerExpansion(final BukkitQuestsPlugin plugin) {
- this.placeholder = new QuestsPlaceholders(plugin);
- this.placeholder.register();
+ this.expansion = new QuestsPlaceholders(plugin);
+ this.expansion.register();
}
@Override
public void unregisterExpansion() {
- if (this.placeholder != null) {
- this.placeholder.unregister();
+ if (this.expansion != null) {
+ this.expansion.unregister();
}
}
}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/DisplayNameUtil.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/DisplayNameUtil.java
new file mode 100644
index 00000000..811b19cd
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/DisplayNameUtil.java
@@ -0,0 +1,39 @@
+package com.leonardobishop.quests.bukkit.hook.papi.util;
+
+import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
+import com.leonardobishop.quests.bukkit.menu.itemstack.QItemStack;
+import com.leonardobishop.quests.bukkit.util.chat.Chat;
+import com.leonardobishop.quests.common.quest.Category;
+import com.leonardobishop.quests.common.quest.Quest;
+import com.leonardobishop.quests.common.util.Modern;
+import org.bukkit.inventory.ItemStack;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+@Modern(type = Modern.Type.FULL)
+@NullMarked
+public final class DisplayNameUtil {
+
+ public static @Nullable String getStrippedDisplayName(final BukkitQuestsPlugin plugin, final Quest quest) {
+ final QItemStack item = plugin.getQItemStackRegistry().getQuestItemStack(quest);
+
+ if (item == null) {
+ return null;
+ }
+
+ final String displayName = item.getName();
+ return Chat.legacyStrip(displayName);
+ }
+
+ public static @Nullable String getStrippedDisplayName(final BukkitQuestsPlugin plugin, final Category category) {
+ final ItemStack item = plugin.getQItemStackRegistry().getCategoryItemStack(category);
+
+ if (item == null) {
+ return null;
+ }
+
+ //noinspection deprecation
+ final String displayName = item.getItemMeta().getDisplayName();
+ return Chat.legacyStrip(displayName);
+ }
+}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/EnumUtil.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/EnumUtil.java
new file mode 100644
index 00000000..60f6bdaf
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/EnumUtil.java
@@ -0,0 +1,35 @@
+package com.leonardobishop.quests.bukkit.hook.papi.util;
+
+import com.leonardobishop.quests.common.util.Modern;
+import org.jspecify.annotations.NullMarked;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Modern(type = Modern.Type.FULL)
+@NullMarked
+public final class EnumUtil {
+
+ public static <E extends Enum<E> & Named> Map<String, E> namedMap(final Class<E> clazz) {
+ final E[] constants = clazz.getEnumConstants();
+
+ final Map<String, E> map = new HashMap<>(constants.length);
+
+ for (final E constant : constants) {
+ for (final String name : constant.getNames()) {
+ if (map.put(name, constant) != null) {
+ throw new IllegalStateException("'" + name + "' already bound");
+ }
+ }
+ }
+
+ return Collections.unmodifiableMap(map);
+ }
+
+ public interface Named {
+
+ List<String> getNames();
+ }
+}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/TriFunction.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/TriFunction.java
new file mode 100644
index 00000000..8a1da4ed
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/util/TriFunction.java
@@ -0,0 +1,13 @@
+package com.leonardobishop.quests.bukkit.hook.papi.util;
+
+import com.leonardobishop.quests.common.util.Modern;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+@Modern(type = Modern.Type.FULL)
+@NullMarked
+@FunctionalInterface
+public interface TriFunction<T extends @Nullable Object, U extends @Nullable Object, V extends @Nullable Object, R extends @Nullable Object> {
+
+ R apply(T t, U u, V v);
+}