From e30ec59183daf5975bcfefc08d947f797dbb74a0 Mon Sep 17 00:00:00 2001 From: Krakenied Date: Thu, 5 Sep 2024 20:27:32 +0200 Subject: [PATCH] Allow quest items usage in menus --- .../quests/bukkit/BukkitQuestsPlugin.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java index 759f1104..12916b66 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java @@ -644,16 +644,36 @@ public void reloadQuests() { } } - public QuestItem getConfiguredQuestItem(String path, ConfigurationSection config, ItemGetter.Filter... excludes) { - if (config.contains(path + ".quest-item")) { - return questItemRegistry.getItem(config.getString(path + ".quest-item")); + public @NotNull QuestItem getConfiguredQuestItem(final @NotNull String path, final @NotNull ConfigurationSection config, final @NotNull ItemGetter.Filter @NotNull ... excludes) { + final String questItemId = config.getString(path + ".quest-item"); + + if (questItemId != null) { + final QuestItem questItem = this.questItemRegistry.getItem(questItemId); + + if (questItem != null) { + return questItem; + } + } + + return new ParsedQuestItem("defined", null, this.getItemStack(path, config, excludes)); + } + + public @NotNull ItemStack getConfiguredItemStack(final @NotNull String path, final @NotNull ConfigurationSection config, final @NotNull ItemGetter.Filter @NotNull ... excludes) { + final String questItemId = config.getString(path + ".quest-item"); + + if (questItemId != null) { + final QuestItem questItem = this.questItemRegistry.getItem(questItemId); + + if (questItem != null) { + return questItem.getItemStack(); + } } - return new ParsedQuestItem("defined", null, getConfiguredItemStack(path, config, excludes)); + return this.itemGetter.getItem(path, config, excludes); } - public ItemStack getConfiguredItemStack(String path, ConfigurationSection config, ItemGetter.Filter... excludes) { - return itemGetter.getItem(path, config, excludes); + public @NotNull ItemStack getItemStack(final @NotNull String path, final @NotNull ConfigurationSection config, final @NotNull ItemGetter.Filter @NotNull ... excludes) { + return this.itemGetter.getItem(path, config, excludes); } private boolean reloadBaseConfiguration(final boolean initialLoad) {