/
EntityInWaterTime.java
82 lines (69 loc) · 3.07 KB
/
EntityInWaterTime.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.Zombie;
public class EntityInWaterTime implements Property {
public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Zombie;
}
public static EntityInWaterTime getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityInWaterTime((EntityTag) entity);
}
}
public static final String[] handledMechs = new String[] {
"in_water_duration"
};
private EntityInWaterTime(EntityTag entity) {
this.entity = entity;
}
EntityTag entity;
@Override
public String getPropertyString() {
return new DurationTag((long) NMSHandler.entityHelper.getInWaterTime((Zombie) entity.getBukkitEntity())).identify();
}
@Override
public String getPropertyId() {
return "in_water_duration";
}
public static void register() {
// <--[tag]
// @attribute <EntityTag.in_water_duration>
// @returns ElementTag(Boolean)
// @mechanism EntityTag.in_water_duration
// @group properties
// @description
// If the entity is a zombie mob, returns the duration of time the zombie has been in water for.
// If this value exceeds 600 ticks, the zombie will begin converted to a Drowned mob.
// See also <@link tag EntityTag.conversion_duration>
// -->
PropertyParser.registerTag(EntityInWaterTime.class, DurationTag.class, "in_water_duration", (attribute, object) -> {
return new DurationTag((long) NMSHandler.entityHelper.getInWaterTime((Zombie) object.entity.getBukkitEntity()));
});
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object EntityTag
// @name in_water_duration
// @input ElementTag(Boolean)
// @description
// If the entity is a zombie mob, sets the duration of time the zombie has been in water for.
// If this value exceeds 600 ticks, the zombie will begin converted to a Drowned mob.
// See also <@link mechanism EntityTag.conversion_duration>
// @tags
// <EntityTag.in_water_duration>
// -->
if (mechanism.matches("in_water_duration") && mechanism.requireObject(DurationTag.class)) {
NMSHandler.entityHelper.setInWaterTime((Zombie) entity.getBukkitEntity(), mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
}
}