-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
EntityVisible.java
116 lines (100 loc) · 3.82 KB
/
EntityVisible.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
package com.denizenscript.denizen.objects.properties.entity;
import com.denizenscript.denizen.npc.traits.InvisibleTrait;
import com.denizenscript.denizen.objects.EntityTag;
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.entity.ArmorStand;
import org.bukkit.entity.ItemFrame;
public class EntityVisible implements Property {
public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag &&
(((EntityTag) entity).getBukkitEntity() instanceof ArmorStand
|| ((EntityTag) entity).getBukkitEntity() instanceof ItemFrame
|| ((EntityTag) entity).isLivingEntity());
}
public static EntityVisible getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityVisible((EntityTag) entity);
}
}
private EntityVisible(EntityTag ent) {
entity = ent;
}
EntityTag entity;
public boolean isVisible() {
if (isArmorStand()) {
return getArmorStand().isVisible();
}
else if (isItemFrame()) {
return getItemFrame().isVisible();
}
else {
return !entity.getLivingEntity().isInvisible();
}
}
@Override
public String getPropertyString() {
return isVisible() ? null : "false";
}
@Override
public String getPropertyId() {
return "visible";
}
public static void registerTags() {
// <--[tag]
// @attribute <EntityTag.visible>
// @returns ElementTag(Boolean)
// @mechanism EntityTag.visible
// @group attributes
// @description
// Returns whether the entity is visible.
// Supports armor stands, item frames, and living entities.
// -->
PropertyParser.registerTag(EntityVisible.class, ElementTag.class, "visible", (attribute, object) -> {
return new ElementTag(object.isVisible());
});
// <--[mechanism]
// @object EntityTag
// @name visible
// @input ElementTag(Boolean)
// @description
// Sets whether the entity is visible.
// Supports armor stands, item frames, and living entities.
// @tags
// <EntityTag.visible>
// -->
PropertyParser.registerMechanism(EntityVisible.class, ElementTag.class, "visible", (object, mechanism, input) -> {
if (mechanism.requireBoolean()) {
if (object.entity.isCitizensNPC()) {
InvisibleTrait.setInvisible(object.entity.getLivingEntity(), object.entity.getDenizenNPC().getCitizen(), !input.asBoolean());
}
else if (object.isArmorStand()) {
object.getArmorStand().setVisible(input.asBoolean());
}
else if (object.isItemFrame()) {
object.getItemFrame().setVisible(input.asBoolean());
}
else {
object.entity.getLivingEntity().setInvisible(!input.asBoolean());
}
}
});
}
public boolean isArmorStand() {
return entity.getBukkitEntity() instanceof ArmorStand;
}
public boolean isItemFrame() {
return entity.getBukkitEntity() instanceof ItemFrame;
}
public ArmorStand getArmorStand() {
return (ArmorStand) entity.getBukkitEntity();
}
public ItemFrame getItemFrame() {
return (ItemFrame) entity.getBukkitEntity();
}
}