-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
EntityDrinkingPotion.java
121 lines (104 loc) · 4.05 KB
/
EntityDrinkingPotion.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
package com.denizenscript.denizen.paper.properties;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.DurationTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.Material;
import org.bukkit.entity.Witch;
public class EntityDrinkingPotion implements Property {
public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag
&& ((EntityTag) entity).getBukkitEntity() instanceof Witch;
}
public static EntityDrinkingPotion getFrom(ObjectTag _entity) {
if (!describes(_entity)) {
return null;
}
else {
return new EntityDrinkingPotion((EntityTag) _entity);
}
}
public static final String[] handledMechs = new String[] {
"drinking_potion", "potion_drink_duration"
};
public EntityDrinkingPotion(EntityTag _entity) {
entity = _entity;
}
EntityTag entity;
public static void register() {
// <--[tag]
// @attribute <EntityTag.drinking_potion>
// @returns ItemTag
// @mechanism EntityTag.drinking_potion
// @group properties
// @Plugin Paper
// @description
// Returns the potion item a witch is drinking, or air if none.
// -->
PropertyParser.registerTag(EntityDrinkingPotion.class, ItemTag.class, "drinking_potion", (attribute, object) -> {
return new ItemTag(object.getWitch().getDrinkingPotion());
});
// <--[tag]
// @attribute <EntityTag.potion_drink_duration>
// @returns DurationTag
// @mechanism EntityTag.potion_drink_duration
// @group properties
// @Plugin Paper
// @description
// Returns the duration remaining until a witch is done drinking a potion.
// -->
PropertyParser.registerTag(EntityDrinkingPotion.class, DurationTag.class, "potion_drink_duration", (attribute, object) -> {
return new DurationTag((long) object.getWitch().getPotionUseTimeLeft());
});
}
public Witch getWitch() {
return (Witch) entity.getBukkitEntity();
}
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "drinking_potion";
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object EntityTag
// @name drinking_potion
// @input ItemTag
// @Plugin Paper
// @group properties
// @description
// Sets the potion item a witch is drinking.
// @tags
// <EntityTag.drinking_potion>
// -->
if (mechanism.matches("drinking_potion") && mechanism.requireObject(ItemTag.class)) {
ItemTag potion = mechanism.valueAsType(ItemTag.class);
if (potion.getBukkitMaterial() != Material.POTION) {
mechanism.echoError("Invalid item input '" + potion + "': item must be a potion");
return;
}
getWitch().setDrinkingPotion(potion.getItemStack());
}
// <--[mechanism]
// @object EntityTag
// @name potion_drink_duration
// @input DurationTag
// @Plugin Paper
// @group properties
// @description
// Sets the duration remaining until a witch is done drinking a potion.
// @tags
// <EntityTag.potion_drink_duration>
// -->
if (mechanism.matches("potion_drink_duration") && mechanism.requireObject(DurationTag.class)) {
getWitch().setPotionUseTimeLeft(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
}
}