/
EntityShouldBurn.java
64 lines (56 loc) · 2.17 KB
/
EntityShouldBurn.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
package com.denizenscript.denizen.paper.properties;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.properties.entity.EntityProperty;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ElementTag;
import org.bukkit.entity.Phantom;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Zombie;
public class EntityShouldBurn extends EntityProperty<ElementTag> {
// <--[property]
// @object EntityTag
// @name should_burn
// @input ElementTag(Boolean)
// @plugin Paper
// @description
// If the entity is a Zombie, Skeleton, or Phantom, controls whether it should burn in daylight.
// -->
public static boolean describes(EntityTag entity) {
return entity.getBukkitEntity() instanceof Zombie
|| entity.getBukkitEntity() instanceof Skeleton
|| entity.getBukkitEntity() instanceof Phantom;
}
@Override
public ElementTag getPropertyValue() {
if (getEntity() instanceof Zombie zombie) {
return new ElementTag(zombie.shouldBurnInDay());
}
else if (getEntity() instanceof Skeleton skeleton) {
return new ElementTag(skeleton.shouldBurnInDay());
}
else { // phantom
return new ElementTag(as(Phantom.class).shouldBurnInDay());
}
}
@Override
public String getPropertyId() {
return "should_burn";
}
@Override
public void setPropertyValue(ElementTag param, Mechanism mechanism) {
if (mechanism.requireBoolean()) {
if (getEntity() instanceof Zombie zombie) {
zombie.setShouldBurnInDay(param.asBoolean());
}
else if (getEntity() instanceof Skeleton skeleton) {
skeleton.setShouldBurnInDay(param.asBoolean());
}
else { // phantom
as(Phantom.class).setShouldBurnInDay(param.asBoolean());
}
}
}
public static void register() {
autoRegister("should_burn", EntityShouldBurn.class, ElementTag.class, false);
}
}