blob: efde9f5188a157fd347ec15ffb2e19752f6fa342 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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;
}
}
|