-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
EssentialsItemExtension.java
88 lines (76 loc) · 2.91 KB
/
EssentialsItemExtension.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
package net.gnomeffinway.depenizen.extensions.essentials;
import com.earth2me.essentials.Essentials;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
import net.gnomeffinway.depenizen.extensions.dObjectExtension;
import net.gnomeffinway.depenizen.support.Support;
import net.gnomeffinway.depenizen.support.plugins.EssentialsSupport;
public class EssentialsItemExtension extends dObjectExtension {
public static boolean describes(dObject object) {
return object instanceof dItem;
}
public static EssentialsItemExtension getFrom(dObject object) {
if (!describes(object)) {
return null;
}
else {
return new EssentialsItemExtension((dItem) object);
}
}
private EssentialsItemExtension(dItem item) {
this.item = item;
}
dItem item;
Essentials ess = Support.getPlugin(EssentialsSupport.class);
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// <--[tag]
// @attribute <i@item.worth>
// @returns Element(Decimal)
// @description
// Returns the amount of money one of this item is worth in Essentials.
// @plugin Depenizen, Essentials
// -->
if (attribute.startsWith("worth")) {
double price = ess.getWorth().getPrice(item.getItemStack()).doubleValue();
// <--[tag]
// @attribute <i@item.worth.quantity[<#>]>
// @returns Element(Decimal)
// @description
// Returns the amount of money the quantity specified of this item is worth in Essentials.
// @plugin Depenizen, Essentials
// -->
if (attribute.getAttribute(2).startsWith("quantity") &&
attribute.hasContext(2) && aH.matchesInteger(attribute.getContext(2))) {
return new Element(price * attribute.getIntContext(2)).getAttribute(attribute.fulfill(2));
}
return new Element(price).getAttribute(attribute.fulfill(1));
}
return null;
}
@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();
// <--[mechanism]
// @object dItem
// @name worth
// @input Element(Decimal)
// @description
// Sets the worth of this item in Essentials.
// @tags
// <i@item.worth>
// <i@item.worth.quantity[<Element>]>
// @plugin Depenizen, Essentials
// -->
if (mechanism.matches("worth") && value.isDouble()) {
ess.getWorth().setPrice(item.getItemStack(), value.asDouble());
}
}
}