/
MCPotionEffectType.java
136 lines (119 loc) · 3.23 KB
/
MCPotionEffectType.java
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.laytonsmith.abstraction.enums;
import com.laytonsmith.PureUtilities.ClassLoading.DynamicEnum;
import com.laytonsmith.annotations.MDynamicEnum;
import com.laytonsmith.core.Static;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
@MDynamicEnum("com.commandhelper.PotionEffectType")
public abstract class MCPotionEffectType<Concrete> extends DynamicEnum<MCPotionEffectType.MCVanillaPotionEffectType, Concrete> {
protected static final Map<String, MCPotionEffectType> MAP = new HashMap<>();
protected static final Map<Integer, MCPotionEffectType> ID_MAP = new HashMap<>();
public MCPotionEffectType(MCVanillaPotionEffectType mcVanillaEffect, Concrete concrete) {
super(mcVanillaEffect, concrete);
}
public static MCPotionEffectType valueOf(String test) throws IllegalArgumentException {
MCPotionEffectType ret = MAP.get(test);
if(ret == null) {
throw new IllegalArgumentException("Unknown potion effect type: " + test);
}
return ret;
}
public static Set<String> types() {
if(MAP.isEmpty()) { // docs mode
Set<String> dummy = new HashSet<>();
for(final MCVanillaPotionEffectType s : MCVanillaPotionEffectType.values()) {
if(!s.equals(MCVanillaPotionEffectType.UNKNOWN)) {
dummy.add(s.name());
}
}
return dummy;
}
return new TreeSet<>(MAP.keySet());
}
public static Collection<MCPotionEffectType> values() {
if(MAP.isEmpty()) { // docs mode
ArrayList<MCPotionEffectType> dummy = new ArrayList<>();
for(final MCVanillaPotionEffectType s : MCVanillaPotionEffectType.values()) {
if(s.equals(MCVanillaPotionEffectType.UNKNOWN)) {
continue;
}
dummy.add(new MCPotionEffectType<Object>(s, null) {
@Override
public String name() {
return s.name();
}
@Override
public String concreteName() {
return s.name();
}
});
}
return dummy;
}
return MAP.values();
}
public static MCPotionEffectType getById(int id) {
MCPotionEffectType ret = ID_MAP.get(id);
if(ret == null) {
throw new IllegalArgumentException("Unknown potion effect id: " + id);
}
return ret;
}
public int getId() {
return getAbstracted().getId();
}
public enum MCVanillaPotionEffectType {
UNKNOWN(0, MCVersion.NEVER),
SPEED(1),
SLOWNESS(2),
HASTE(3),
MINING_FATIGUE(4),
STRENGTH(5),
INSTANT_HEALTH(6),
INSTANT_DAMAGE(7),
JUMP_BOOST(8),
NAUSEA(9),
REGENERATION(10),
RESISTANCE(11),
FIRE_RESISTANCE(12),
WATER_BREATHING(13),
INVISIBILITY(14),
BLINDNESS(15),
NIGHT_VISION(16),
HUNGER(17),
WEAKNESS(18),
POISON(19),
WITHER(20),
HEALTH_BOOST(21),
ABSORPTION(22),
SATURATION(23),
GLOWING(24),
LEVITATION(25),
LUCK(26),
BAD_LUCK(27),
SLOW_FALLING(28),
CONDUIT_POWER(29),
DOLPHINS_GRACE(30);
private final int id;
private final MCVersion since;
MCVanillaPotionEffectType(int id) {
this.id = id;
this.since = MCVersion.MC1_0;
}
MCVanillaPotionEffectType(int id, MCVersion version) {
this.id = id;
this.since = version;
}
public int getId() {
return this.id;
}
public boolean existsInCurrent() {
return Static.getServer().getMinecraftVersion().gte(since);
}
}
}