/
EntityFireworkLifetime.java
82 lines (68 loc) · 2.73 KB
/
EntityFireworkLifetime.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
package com.denizenscript.denizen.objects.properties.entity;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.DurationTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.entity.Firework;
public class EntityFireworkLifetime implements Property {
public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Firework;
}
public static EntityFireworkLifetime getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityFireworkLifetime((EntityTag) entity);
}
}
public static final String[] handledMechs = new String[] {
"firework_lifetime"
};
public EntityFireworkLifetime(EntityTag entity) {
this.entity = entity;
}
EntityTag entity;
public DurationTag getDuration() {
return new DurationTag((long) NMSHandler.entityHelper.getFireworkLifetime((Firework) entity.getBukkitEntity()));
}
@Override
public String getPropertyString() {
return getDuration().identify();
}
@Override
public String getPropertyId() {
return "firework_lifetime";
}
public static void register() {
// <--[tag]
// @attribute <EntityTag.firework_lifetime>
// @returns DurationTag
// @mechanism EntityTag.firework_lifetime
// @group properties
// @description
// Returns the duration that a firework will live for (before detonating).
// -->
PropertyParser.registerTag(EntityFireworkLifetime.class, DurationTag.class, "firework_lifetime", (attribute, object) -> {
return object.getDuration();
});
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object EntityTag
// @name firework_lifetime
// @input DurationTag
// @description
// Sets the duration that a firework will live for (before detonating).
// @tags
// <EntityTag.firework_lifetime>
// -->
if (mechanism.matches("firework_lifetime") && mechanism.requireObject(DurationTag.class)) {
NMSHandler.entityHelper.setFireworkLifetime((Firework) entity.getBukkitEntity(), mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
}
}