-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
EntityPotion.java
125 lines (101 loc) · 3.24 KB
/
EntityPotion.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
123
124
125
package net.aufdemrand.denizen.objects.properties.entity;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.inventory.ItemStack;
public class EntityPotion implements Property {
public static boolean describes(dObject entity) {
if (!(entity instanceof dEntity)) {
return false;
}
// Check if the entity is a SPLASH_POTION, the EntityType alias for ThrownPotion
return ((dEntity) entity).getBukkitEntityType() == EntityType.SPLASH_POTION;
}
public static EntityPotion getFrom(dObject entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityPotion((dEntity) entity);
}
}
public static final String[] handledTags = new String[] {
"potion"
};
public static final String[] handledMechs = new String[] {
"potion"
};
///////////////////
// Instance Fields and Methods
/////////////
dEntity potion;
private EntityPotion(dEntity entity) {
potion = entity;
}
private ThrownPotion getPotion() {
if (potion == null) {
return null;
}
return (ThrownPotion) potion.getBukkitEntity();
}
public void setPotion(ItemStack item) {
if (potion != null) {
((ThrownPotion) potion.getBukkitEntity()).setItem(item);
}
}
/////////
// Property Methods
///////
@Override
public String getPropertyString() {
if (potion == null) {
return null;
}
return new dItem(getPotion().getItem()).identify();
}
@Override
public String getPropertyId() {
return "potion";
}
///////////
// dObject Attributes
////////
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// <--[tag]
// @attribute <e@entity.potion>
// @returns dItem
// @mechanism dEntity.potion
// @group properties
// @description
// Returns the dItem of the splash potion.
// -->
if (attribute.startsWith("potion")) {
return new dItem(getPotion().getItem()).getAttribute(attribute.fulfill(1));
}
return null;
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object dEntity
// @name potion
// @input dItem
// @description
// Sets the splash potion's ItemStack (must be a potion), thereby changing the effects.
// @tags
// <e@entity.potion>
// -->
if (mechanism.matches("potion") && mechanism.requireObject(dItem.class)) {
setPotion(mechanism.valueAsType(dItem.class).getItemStack());
}
}
}