mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-23 00:05:52 +01:00
Fixed issue with quest list custom model data
This commit is contained in:
parent
5c185476dd
commit
d6ec76573c
@ -1,7 +1,9 @@
|
||||
package net.Indyuce.mmocore.gui;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.SoundEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.quest.Quest;
|
||||
import net.Indyuce.mmocore.api.util.math.format.DelayFormat;
|
||||
import net.Indyuce.mmocore.experience.Profession;
|
||||
import net.Indyuce.mmocore.gui.api.EditableInventory;
|
||||
@ -10,14 +12,11 @@ import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.api.quest.Quest;
|
||||
import net.Indyuce.mmocore.api.SoundEvent;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
@ -108,9 +107,7 @@ public class QuestViewer extends EditableInventory {
|
||||
|
||||
List<String> lore = new ArrayList<>(getLore());
|
||||
|
||||
/*
|
||||
* replace quest lore
|
||||
*/
|
||||
// Replace quest lore
|
||||
index = lore.indexOf("{lore}");
|
||||
if (index >= 0) {
|
||||
lore.remove(index);
|
||||
@ -118,22 +115,20 @@ public class QuestViewer extends EditableInventory {
|
||||
lore.add(index + j, quest.getLore().get(j));
|
||||
}
|
||||
|
||||
/*
|
||||
* calculate quest info for later.
|
||||
*/
|
||||
// Calculate lore for later
|
||||
int reqCount = quest.countLevelRestrictions();
|
||||
boolean started = inv.getPlayerData().getQuestData().hasCurrent(quest), completed = inv.getPlayerData().getQuestData().hasFinished(quest),
|
||||
cooldown = completed && inv.getPlayerData().getQuestData().checkCooldownAvailability(quest);
|
||||
|
||||
lore.removeIf(next -> (next.startsWith("{level_req}") && reqCount < 1) ||
|
||||
(next.startsWith("{started}") && !started) || (next.startsWith("{!started}") && started)
|
||||
|| (next.startsWith("{completed}") && !completed) || (next.startsWith("{completed_cannot_redo}") &&
|
||||
!(completed && !quest.isRedoable())) || (next.startsWith("{completed_can_redo}") && !(cooldown && quest.isRedoable()))
|
||||
lore.removeIf(next -> (next.startsWith("{level_req}") && reqCount < 1)
|
||||
|| (next.startsWith("{started}") && !started)
|
||||
|| (next.startsWith("{!started}") && started)
|
||||
|| (next.startsWith("{completed}") && !completed)
|
||||
|| (next.startsWith("{completed_cannot_redo}") && !(completed && !quest.isRedoable()))
|
||||
|| (next.startsWith("{completed_can_redo}") && !(cooldown && quest.isRedoable()))
|
||||
|| (next.startsWith("{completed_delay}") && !(completed && !cooldown)));
|
||||
|
||||
/*
|
||||
* replace level requirements
|
||||
*/
|
||||
// Replace level requirements
|
||||
index = lore.indexOf("{level_req}{level_requirements}");
|
||||
if (index >= 0) {
|
||||
lore.remove(index);
|
||||
@ -149,28 +144,25 @@ public class QuestViewer extends EditableInventory {
|
||||
}
|
||||
}
|
||||
|
||||
Placeholders holders = getPlaceholders(inv.getPlayerData(), quest);
|
||||
|
||||
Placeholders holders = getPlaceholders(inv, n);
|
||||
for (int j = 0; j < lore.size(); j++)
|
||||
lore.set(j, ChatColor.GRAY + holders.apply(inv.getPlayer(), lore.get(j)));
|
||||
|
||||
/*
|
||||
* generate item
|
||||
*/
|
||||
ItemStack item = new ItemStack(getMaterial());
|
||||
// Generate item
|
||||
ItemStack item = super.display(inv, n);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(holders.apply(inv.getPlayer(), getName()));
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
meta.setLore(lore);
|
||||
|
||||
|
||||
meta.getPersistentDataContainer().set(new NamespacedKey(MMOCore.plugin, "quest_id"), PersistentDataType.STRING,quest.getId());
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
private Placeholders getPlaceholders(PlayerData data, Quest quest) {
|
||||
@Override
|
||||
public Placeholders getPlaceholders(GeneratedInventory inv, int n) {
|
||||
Quest quest = ((QuestInventory) inv).quests.get(n);
|
||||
PlayerData data = inv.getPlayerData();
|
||||
|
||||
Placeholders holders = new Placeholders();
|
||||
holders.register("name", quest.getName());
|
||||
holders.register("total_level_req", quest.getLevelRestrictions().size() + (quest.getLevelRestriction(null) > 0 ? 1 : 0));
|
||||
|
Loading…
Reference in New Issue
Block a user