/
ItemArmorStand.java
122 lines (108 loc) · 4.25 KB
/
ItemArmorStand.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
package com.denizenscript.denizen.paper.properties;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.destroystokyo.paper.inventory.meta.ArmorStandMeta;
import org.bukkit.Material;
public class ItemArmorStand implements Property {
public static boolean describes(ObjectTag item) {
return item instanceof ItemTag
&& ((ItemTag) item).getBukkitMaterial() == Material.ARMOR_STAND;
}
public static ItemArmorStand getFrom(ObjectTag item) {
if (!describes(item)) {
return null;
}
return new ItemArmorStand((ItemTag) item);
}
public static final String[] handledMechs = new String[] {
"armor_stand_data"
};
private ItemArmorStand(ItemTag item) {
this.item = item;
}
ItemTag item;
public MapTag getDataMap() {
ArmorStandMeta meta = (ArmorStandMeta) item.getItemMeta();
if (meta == null) {
return null;
}
MapTag result = new MapTag();
result.putObject("base_plate", new ElementTag(!meta.hasNoBasePlate()));
result.putObject("visible", new ElementTag(!meta.isInvisible()));
result.putObject("marker", new ElementTag(meta.isMarker()));
result.putObject("is_small", new ElementTag(meta.isSmall()));
result.putObject("arms", new ElementTag(meta.shouldShowArms()));
return result;
}
@Override
public String getPropertyString() {
MapTag result = getDataMap();
if (result == null) {
return null;
}
return result.toString();
}
@Override
public String getPropertyId() {
return "armor_stand_data";
}
public static void registerTags() {
// <--[tag]
// @attribute <ItemTag.armor_stand_data>
// @returns MapTag
// @mechanism ItemTag.armor_stand_data
// @group properties
// @Plugin Paper
// @description
// Returns a map of basic armor stand data, with keys matching EntityTag property names.
// Keys: base_plate, visible, marker, is_small, arms
// -->
PropertyParser.registerTag(ItemArmorStand.class, MapTag.class, "armor_stand_data", (attribute, item) -> {
return item.getDataMap();
});
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object ItemTag
// @name armor_stand_data
// @input MapTag
// @Plugin Paper
// @description
// Sets a map of basic armor stand data, with keys matching EntityTag property names.
// Allowed keys: base_plate, visible, marker, is_small, arms
// @tags
// <ItemTag.armor_stand_data>
// -->
if (mechanism.matches("armor_stand_data") && mechanism.requireObject(MapTag.class)) {
MapTag map = mechanism.valueAsType(MapTag.class);
ArmorStandMeta meta = (ArmorStandMeta) item.getItemMeta();
ElementTag base_plate = map.getElement("base_plate");
ElementTag visible = map.getElement("visible");
ElementTag marker = map.getElement("marker");
ElementTag is_small = map.getElement("is_small");
ElementTag arms = map.getElement("arms");
if (base_plate != null) {
meta.setNoBasePlate(!base_plate.asBoolean());
}
if (visible != null) {
meta.setInvisible(!visible.asBoolean());
}
if (marker != null) {
meta.setMarker(marker.asBoolean());
}
if (is_small != null) {
meta.setSmall(is_small.asBoolean());
}
if (arms != null) {
meta.setShowArms(arms.asBoolean());
}
item.setItemMeta(meta);
}
}
}