/
PaperEntityProperties.java
159 lines (141 loc) · 6.15 KB
/
PaperEntityProperties.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
package com.denizenscript.denizen.paper.properties;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb;
import java.util.UUID;
public class PaperEntityProperties implements Property {
public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag;
}
public static final String[] handledMechs = new String[] {
}; // None
public static PaperEntityProperties getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
return new PaperEntityProperties((EntityTag) entity);
}
private PaperEntityProperties(EntityTag entity) {
this.entity = entity;
}
EntityTag entity;
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "EntityPaperProperties";
}
public static void registerTags() {
// <--[tag]
// @attribute <EntityTag.spawn_reason>
// @returns ElementTag
// @group properties
// @Plugin Paper
// @description
// Returns the entity's spawn reason.
// Valid spawn reasons can be found at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/CreatureSpawnEvent.SpawnReason.html>
// -->
PropertyParser.<PaperEntityProperties, ElementTag>registerTag(ElementTag.class, "spawn_reason", (attribute, entity) -> {
return new ElementTag(entity.entity.getBukkitEntity().getEntitySpawnReason().name());
});
// <--[tag]
// @attribute <EntityTag.xp_spawn_reason>
// @returns ElementTag
// @group properties
// @Plugin Paper
// @description
// If the entity is an experience orb, returns its spawn reason.
// Valid spawn reasons can be found at <@link url https://papermc.io/javadocs/paper/1.17/org/bukkit/entity/ExperienceOrb.SpawnReason.html>
// -->
PropertyParser.<PaperEntityProperties, ElementTag>registerTag(ElementTag.class, "xp_spawn_reason", (attribute, entity) -> {
if (!(entity.entity.getBukkitEntity() instanceof ExperienceOrb)) {
attribute.echoError("Entity " + entity.entity + " is not an experience orb.");
return null;
}
return new ElementTag(((ExperienceOrb) entity.entity.getBukkitEntity()).getSpawnReason().name());
});
// <--[tag]
// @attribute <EntityTag.xp_trigger>
// @returns EntityTag
// @group properties
// @Plugin Paper
// @description
// If the entity is an experience orb, returns the entity that triggered it spawning (if any).
// For example, if a player killed an entity this would return the player.
// -->
PropertyParser.<PaperEntityProperties, EntityTag>registerTag(EntityTag.class, "xp_trigger", (attribute, entity) -> {
if (!(entity.entity.getBukkitEntity() instanceof ExperienceOrb)) {
attribute.echoError("Entity " + entity.entity + " is not an experience orb.");
return null;
}
UUID uuid = ((ExperienceOrb) entity.entity.getBukkitEntity()).getTriggerEntityId();
if (uuid == null) {
return null;
}
Entity e = EntityTag.getEntityForID(uuid);
if (e == null) {
return null;
}
return new EntityTag(e);
});
// <--[tag]
// @attribute <EntityTag.xp_source>
// @returns EntityTag
// @group properties
// @Plugin Paper
// @description
// If the entity is an experience orb, returns the entity that it was created from (if any).
// For example, if the xp orb was spawned from breeding this would return the baby.
// -->
PropertyParser.<PaperEntityProperties, EntityTag>registerTag(EntityTag.class, "xp_source", (attribute, entity) -> {
if (!(entity.entity.getBukkitEntity() instanceof ExperienceOrb)) {
attribute.echoError("Entity " + entity.entity + " is not an experience orb.");
return null;
}
UUID uuid = ((ExperienceOrb) entity.entity.getBukkitEntity()).getSourceEntityId();
if (uuid == null) {
return null;
}
Entity e = EntityTag.getEntityForID(uuid);
if (e == null) {
return null;
}
return new EntityTag(e);
});
// <--[tag]
// @attribute <EntityTag.spawn_location>
// @returns LocationTag
// @group properties
// @Plugin Paper
// @description
// Returns the initial spawn location of this entity.
// -->
PropertyParser.<PaperEntityProperties, LocationTag>registerTag(LocationTag.class, "spawn_location", (attribute, entity) -> {
Location loc = entity.entity.getBukkitEntity().getOrigin();
return loc != null ? new LocationTag(loc) : null;
});
// <--[tag]
// @attribute <EntityTag.from_spawner>
// @returns ElementTag(Boolean)
// @group properties
// @Plugin Paper
// @description
// Returns whether the entity was spawned from a spawner.
// -->
PropertyParser.<PaperEntityProperties, ElementTag>registerTag(ElementTag.class, "from_spawner", (attribute, entity) -> {
return new ElementTag(entity.entity.getBukkitEntity().fromMobSpawner());
});
}
@Override
public void adjust(Mechanism mechanism) {
}
}