aboutsummaryrefslogtreecommitdiffstats
path: root/src/me/fatpigsarefat/quests/obj/misc/QItemStack.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/me/fatpigsarefat/quests/obj/misc/QItemStack.java')
-rw-r--r--src/me/fatpigsarefat/quests/obj/misc/QItemStack.java108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/me/fatpigsarefat/quests/obj/misc/QItemStack.java b/src/me/fatpigsarefat/quests/obj/misc/QItemStack.java
new file mode 100644
index 00000000..efde9f51
--- /dev/null
+++ b/src/me/fatpigsarefat/quests/obj/misc/QItemStack.java
@@ -0,0 +1,108 @@
+package me.fatpigsarefat.quests.obj.misc;
+
+import me.fatpigsarefat.quests.player.questprogressfile.QuestProgress;
+import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.ItemFlag;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class QItemStack {
+
+ private String name;
+ private List<String> loreNormal;
+ private List<String> loreStarted;
+ private Material type;
+ private int data;
+
+ public QItemStack(String name, List<String> loreNormal, List<String> loreStarted, Material type, int data) {
+ this.name = name;
+ this.loreNormal = loreNormal;
+ this.loreStarted = loreStarted;
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List<String> getLoreNormal() {
+ return loreNormal;
+ }
+
+ public void setLoreNormal(List<String> loreNormal) {
+ this.loreNormal = loreNormal;
+ }
+
+ public List<String> getLoreStarted() {
+ return loreStarted;
+ }
+
+ public void setLoreStarted(List<String> loreStarted) {
+ this.loreStarted = loreStarted;
+ }
+
+ public Material getType() {
+ return type;
+ }
+
+ public void setType(Material type) {
+ this.type = type;
+ }
+
+ public int getData() {
+ return data;
+ }
+
+ public void setData(int data) {
+ this.data = data;
+ }
+
+ public ItemStack toItemStack(QuestProgress questProgress) {
+ ItemStack is = new ItemStack(type, 1, (short) data);
+ ItemMeta ism = is.getItemMeta();
+ ism.setDisplayName(name);
+ List<String> formattedLore = new ArrayList<>();
+ List<String> tempLore = new ArrayList<>();
+ tempLore.addAll(loreNormal);
+ if (questProgress != null && questProgress.isStarted()) {
+ tempLore.addAll(loreStarted);
+ ism.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
+ try {
+ is.getItemMeta().addItemFlags(ItemFlag.HIDE_ENCHANTS);
+ } catch (Exception ignored) {
+
+ }
+ }
+ if (questProgress != null) {
+ for (String s : tempLore) {
+ Matcher m = Pattern.compile("\\{([^}]+)\\}").matcher(s);
+ while (m.find()) {
+ String[] parts = m.group(1).split(":");
+ if (parts.length > 1) {
+ if (questProgress.getTaskProgress(parts[0]) == null) {
+ continue;
+ }
+ if (parts[1].equals("progress")) {
+ String str = String.valueOf(questProgress.getTaskProgress(parts[0]).getProgress());
+ s = s.replace("{" + m.group(1) + "}", (str.equals("null") ? String.valueOf(0) : str));
+ }
+ }
+ }
+ formattedLore.add(s);
+ }
+ }
+ ism.setLore(formattedLore);
+ is.setItemMeta(ism);
+ return is;
+ }
+}