-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
SentinelTarget.java
196 lines (169 loc) · 7.94 KB
/
SentinelTarget.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package org.mcmonkey.sentinel.targeting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.trait.trait.Owner;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.mcmonkey.sentinel.SentinelPlugin;
import org.mcmonkey.sentinel.SentinelTrait;
import org.mcmonkey.sentinel.SentinelUtilities;
import java.util.*;
/**
* Helper for target types.
*/
public class SentinelTarget {
/**
* All NPCs are targets.
*/
public static SentinelTarget NPCS = new SentinelTarget(new EntityType[]{}, "NPC");
/**
* The NPC's owner is a target.
*/
public static SentinelTarget OWNER = new SentinelTarget(new EntityType[]{}, "OWNER");
/**
* Player entity is a target.
*/
public static SentinelTarget PLAYERS = new SentinelTarget(new EntityType[]{EntityType.PLAYER}, "PLAYER");
/**
* Entity types known to support native melee combat.
*/
public static HashSet<EntityType> NATIVE_COMBAT_CAPABLE_TYPES = new HashSet<>(Arrays.asList(EntityType.ZOMBIE, EntityType.SKELETON));
/**
* Basic single-entity target types (that were added in Minecraft 1.8 or earlier).
*/
public static SentinelTarget PIGS = new SentinelTarget(new EntityType[]{EntityType.PIG}, "PIG"),
OCELOTS = new SentinelTarget(new EntityType[]{EntityType.OCELOT}, "OCELOT", "CAT"),
COWS = new SentinelTarget(new EntityType[]{EntityType.COW}, "COW"),
RABBITS = new SentinelTarget(new EntityType[]{EntityType.RABBIT}, "RABBIT", "BUNNY", "BUNNIE"),
SHEEP = new SentinelTarget(new EntityType[]{EntityType.SHEEP}, "SHEEP"),
CHICKENS = new SentinelTarget(new EntityType[]{EntityType.CHICKEN}, "CHICKEN", "DUCK"),
HORSES = new SentinelTarget(new EntityType[]{EntityType.HORSE}, "HORSE"),
MUSHROOM_COW = new SentinelTarget(new EntityType[]{EntityType.MUSHROOM_COW}, "MUSHROOM_COW", "MUSHROOMCOW", "MOOSHROOM"),
IRON_GOLEMS = new SentinelTarget(new EntityType[]{EntityType.IRON_GOLEM}, "IRON_GOLEM", "IRONGOLEM"),
SQUIDS = new SentinelTarget(new EntityType[]{EntityType.SQUID}, "SQUID"),
VILLAGER = new SentinelTarget(new EntityType[]{EntityType.VILLAGER}, "VILLAGER"),
WOLVES = new SentinelTarget(new EntityType[]{EntityType.WOLF}, "WOLF", "WOLVE"),
SNOWMEN = new SentinelTarget(new EntityType[]{EntityType.SNOWMAN}, "SNOWMAN", "SNOWMEN"),
WITCHES = new SentinelTarget(new EntityType[]{EntityType.WITCH}, "WITCH"),
GUARDIANS = new SentinelTarget(new EntityType[]{EntityType.GUARDIAN}, "GUARDIAN"),
CREERERS = new SentinelTarget(new EntityType[]{EntityType.CREEPER}, "CREEPER"),
SKELETONS = new SentinelTarget(new EntityType[]{EntityType.SKELETON}, "SKELETON"),
ZOMBIES = new SentinelTarget(new EntityType[]{EntityType.ZOMBIE}, "ZOMBIE"),
MAGMA_CUBES = new SentinelTarget(new EntityType[]{EntityType.MAGMA_CUBE}, "MAGMA_CUBE", "MAGMACUBE"),
SILVERFISH = new SentinelTarget(new EntityType[]{EntityType.SILVERFISH}, "SILVERFISH", "SILVER_FISH", "SILVERFISHE", "SILVER_FISHE"),
BATS = new SentinelTarget(new EntityType[]{EntityType.BAT}, "BAT"),
BLAZES = new SentinelTarget(new EntityType[]{EntityType.BLAZE}, "BLAZE"),
GHASTS = new SentinelTarget(new EntityType[]{EntityType.GHAST}, "GHAST"),
GIANTS = new SentinelTarget(new EntityType[]{EntityType.GIANT}, "GIANT"),
SLIMES = new SentinelTarget(new EntityType[]{EntityType.SLIME}, "SLIME"),
SPIDERS = new SentinelTarget(new EntityType[]{EntityType.SPIDER}, "SPIDER"),
CAVE_SPIDERS = new SentinelTarget(new EntityType[]{EntityType.CAVE_SPIDER}, "CAVE_SPIDER", "CAVESPIDER"),
ENDERMEN = new SentinelTarget(new EntityType[]{EntityType.ENDERMAN}, "ENDERMAN", "ENDER_MAN", "ENDERMEN", "ENDER_MEN"),
ENDERMITES = new SentinelTarget(new EntityType[]{EntityType.ENDERMITE}, "ENDERMITE", "ENDER_MITE"),
WITHERS = new SentinelTarget(new EntityType[]{EntityType.WITHER}, "WITHER"),
ENDERDRAGONS = new SentinelTarget(new EntityType[]{EntityType.ENDER_DRAGON}, "ENDERDRAGON", "ENDER_DRAGON"),
ARMOR_STAND = new SentinelTarget(new EntityType[]{EntityType.ARMOR_STAND}, "ARMORSTAND", "ARMOR_STAND");
/**
* Valid target types for 1.9 or higher.
*/
public static SentinelTarget SHULKERS;
/**
* Valid target types for 1.10 or higher.
*/
public static SentinelTarget POLAR_BEARS;
/**
* Valid target types for 1.11 or higher.
*/
public static SentinelTarget VEXES, DONKEYS, LLAMAS, MULES, HUSKS, ELDER_GUARDIANS,
EVOKERS, SKELETON_HORSES, STRAYS, ZOMBIE_VILLAGERS, ZOMBIE_HORSES, WITHER_SKELETONS, VINDICATORS;
/**
* Valid target types for 1.12 or higher.
*/
public static SentinelTarget PARROTS, ILLUSIONERS;
/**
* Valid target types for 1.13 or higher.
*/
public static SentinelTarget DOLPHINS, DROWNED, COD, SALMON, PUFFERFISH, TROPICAL_FISH, PHANTOMS, TURTLES, FISH;
/**
* Valid target types for 1.14 or higher.
*/
public static SentinelTarget RAVAGERS, PILLAGERS, CATS, PANDAS, TRADER_LLAMAS, WANDERING_TRADERS, FOXES;
/**
* Valid target types for 1.15 or higher.
*/
public static SentinelTarget BEES;
/**
* Valid target types for 1.15 or LOWER.
*/
public static SentinelTarget ZOMBIE_PIGMEN;
/**
* Valid target types for 1.16 or higher.
*/
public static SentinelTarget HOGLINS, PIGLINS, STRIDERS, ZOGLINS, ZOMBIFIED_PIGLINS, PIGLIN_BRUTE;
/**
* Valid target types for 1.19 or higher.
*/
public static SentinelTarget TADPOLES, FROGS, ALLAYS, WARDENS, CAMELS, SNIFFERS;
/**
* Multiple-entity-type targets.
*/
public static SentinelTarget PASSIVE_MOBS, MONSTERS, MOBS;
/**
* Gets the set of targets that include an entity type.
*/
public static HashSet<SentinelTarget> forEntityType(EntityType type) {
return SentinelPlugin.entityToTargets.get(type);
}
/**
* Gets the Sentinel target that matches a name.
*/
public static SentinelTarget forName(String name) {
return SentinelPlugin.targetOptions.get(name.toUpperCase());
}
/**
* The array of valid names for this target type.
*/
public String[] names;
/**
* The name of this target type.
*/
public String name() {
return names[0];
}
/**
* Constructs the target type instance.
*/
public SentinelTarget(EntityType[] types, String... names) {
this.names = names;
this.types = new HashSet<>(Arrays.asList(types));
for (String name : names) {
SentinelPlugin.targetOptions.put(name, this);
SentinelPlugin.targetOptions.put(name + "S", this);
}
for (EntityType type : types) {
SentinelPlugin.entityToTargets.get(type).add(this);
}
}
public HashSet<EntityType> types;
/**
* Returns whether this SentinelTarget targets the given entity.
*/
public boolean isTarget(LivingEntity entity) {
return isTarget(entity, null);
}
/**
* Returns whether this SentinelTarget targets the given entity for the given Sentinel.
*/
public boolean isTarget(LivingEntity entity, SentinelTrait sentinel) {
if (types.contains(entity.getType())) {
return true;
}
if (this == NPCS && CitizensAPI.getNPCRegistry().isNPC(entity)) {
return true;
}
if (this == OWNER && sentinel != null
&& SentinelUtilities.uuidEquals(entity.getUniqueId(), sentinel.getNPC().getOrAddTrait(Owner.class).getOwnerId())) {
return true;
}
return false;
}
}