/
MaterialBrewingStand.java
105 lines (88 loc) · 3.5 KB
/
MaterialBrewingStand.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
package com.denizenscript.denizen.objects.properties.material;
import com.denizenscript.denizen.objects.MaterialTag;
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.ListTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.block.data.type.BrewingStand;
public class MaterialBrewingStand implements Property {
public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& ((MaterialTag) material).getModernData() instanceof BrewingStand;
}
public static MaterialBrewingStand getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialBrewingStand((MaterialTag) _material);
}
}
public static final String[] handledMechs = new String[] {
"bottles"
};
private MaterialBrewingStand(MaterialTag _material) {
material = _material;
}
MaterialTag material;
public static void registerTags() {
// <--[tag]
// @attribute <MaterialTag.bottles>
// @returns ListTag
// @mechanism MaterialTag.bottles
// @group properties
// @description
// Returns a list of booleans that represent whether a slot in a brewing stand has a bottle.
// Under current implementation this always returns exactly 3 values, like "true|false|true".
// -->
PropertyParser.registerStaticTag(MaterialBrewingStand.class, ListTag.class, "bottles", (attribute, material) -> {
return material.getBottleBooleans();
});
}
public BrewingStand getBrewingStand() {
return (BrewingStand) material.getModernData();
}
public int getMaxBottles() {
return getBrewingStand().getMaximumBottles();
}
public ListTag getBottleBooleans() {
ListTag result = new ListTag();
for (int i = 0; i < getMaxBottles(); i++) {
result.addObject(new ElementTag(getBrewingStand().hasBottle(i)));
}
return result;
}
@Override
public String getPropertyString() {
return getBottleBooleans().identify();
}
@Override
public String getPropertyId() {
return "bottles";
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object MaterialTag
// @name bottles
// @input ListTag
// @description
// Sets the bottles in a brewing stand. Input is a list of booleans representing whether that slot has a bottle.
// @tags
// <MaterialTag.bottles>
// -->
if (mechanism.matches("bottles")) {
ListTag bottles = mechanism.valueAsType(ListTag.class);
if (bottles.size() > getMaxBottles()) {
mechanism.echoError("Too many values specified! Brewing stand has a maximum of " + getMaxBottles() + " bottles.");
return;
}
for (int i = 0; i < bottles.size(); i++) {
getBrewingStand().setBottle(i, new ElementTag(bottles.get(i)).asBoolean());
}
}
}
}