blob: a416f6ec807710aaeda17de4814041510c6d8335 (
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
|
package de.hype.bbsentials.constants.enviromentShared;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class ChChestItems {
private static final List<ChChestItem> items = new ArrayList<>();
public static final ChChestItem PrehistoricEgg = new ChChestItem("Prehistoric Egg");
public static final ChChestItem Pickonimbus2000 = new ChChestItem("Pickonimbus 2000");
public static final ChChestItem ControlSwitch = new ChChestItem("Control Switch");
public static final ChChestItem ElectronTransmitter = new ChChestItem("Electron Transmitter");
public static final ChChestItem FTX3070 = new ChChestItem("FTX 3070");
public static final ChChestItem RobotronReflector = new ChChestItem("Robotron Reflector");
public static final ChChestItem SuperliteMotor = new ChChestItem("Superlite Motor");
public static final ChChestItem SyntheticHeart = new ChChestItem("Synthetic Heart");
public static final ChChestItem FlawlessGemstone = new ChChestItem("Flawless Gemstone");
public static final ChChestItem JungleHeart = new ChChestItem("Jungle Heart");
// Automatically populate predefined items using reflection
static {
Field[] fields = ChChestItems.class.getDeclaredFields();
for (Field field : fields) {
if (field.getType().equals(ChChestItem.class) && isPublicStaticFinal(field)) {
try {
items.add((ChChestItem) field.get(null));
} catch (IllegalAccessException e) {
// Handle exception
}
}
}
}
public static ChChestItem getItem(String displayName) {
ChChestItem existingItem = getPredefinedItem(displayName);
if (existingItem != null) {
return existingItem;
}
ChChestItem customItem = new ChChestItem(displayName, true);
return customItem;
}
private static ChChestItem getPredefinedItem(String displayName) {
for (ChChestItem item : items) {
if (item.getDisplayName().equals(displayName)) {
return item;
}
}
return null;
}
public static ChChestItem[] getItem(String[] displayNames) {
ChChestItem[] result = new ChChestItem[displayNames.length];
for (int i = 0; i < displayNames.length; i++) {
result[i] = getItem(displayNames[i]);
}
return result;
}
// Utility method to check if a field is public, static, and final
private static boolean isPublicStaticFinal(Field field) {
return java.lang.reflect.Modifier.isPublic(field.getModifiers()) &&
java.lang.reflect.Modifier.isStatic(field.getModifiers()) &&
java.lang.reflect.Modifier.isFinal(field.getModifiers());
}
public static ChChestItem createCustomItem(String displayName) {
ChChestItem customItem = new ChChestItem(displayName, true);
items.add(customItem);
return customItem;
}
public static List<ChChestItem> getAllItems() {
return items;
}
public static List<String> getAllItemNames() {
return items.stream()
.map(ChChestItem::getDisplayName)
.collect(Collectors.toList());
//very fancy way to convert a list to a list of values from the previous list
}
}
|