-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
PrismLocationExtension.java
144 lines (123 loc) · 5.38 KB
/
PrismLocationExtension.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.denizenscript.depenizen.bukkit.extensions.prism;
import com.denizenscript.depenizen.bukkit.extensions.dObjectExtension;
import com.denizenscript.depenizen.bukkit.objects.prism.PrismAction;
import com.denizenscript.depenizen.bukkit.support.Support;
import com.denizenscript.depenizen.bukkit.support.plugins.PrismSupport;
import me.botsko.prism.Prism;
import me.botsko.prism.actionlibs.ActionsQuery;
import me.botsko.prism.actionlibs.QueryParameters;
import me.botsko.prism.actions.Handler;
import me.botsko.prism.appliers.PrismProcessType;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
import java.util.List;
public class PrismLocationExtension extends dObjectExtension {
public static boolean describes(dObject object) {
return object instanceof dLocation;
}
public static PrismLocationExtension getFrom(dObject object) {
if (!describes(object)) {
return null;
}
else {
return new PrismLocationExtension((dLocation) object);
}
}
public static final String[] handledTags = new String[] {
"prism_logs"
};
public static final String[] handledMechs = new String[] {
}; // None
private PrismLocationExtension(dLocation location) {
this.location = location;
}
dLocation location = null;
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <l@location.prism_logs>
// @returns dList(PrismAction)
// @description
// Returns a list of prism logs for this location.
// @Plugin DepenizenBukkit, Prism
// -->
if (attribute.startsWith("prism_logs")) {
attribute = attribute.fulfill(1);
QueryParameters params = new QueryParameters();
params.setProcessType(PrismProcessType.LOOKUP);
boolean isRadius = false;
// <--[tag]
// @attribute <l@location.prism_logs.radius[<#>]>
// @returns dList(PrismAction)
// @description
// Returns a list of prism logs for a specified radius of blocks around this location.
// @Plugin DepenizenBukkit, Prism
// -->
if (attribute.startsWith("radius")) {
params.setRadius(attribute.getIntContext(1));
isRadius = true;
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <l@location.prism_logs.radius[<#>].types[<action>|...]>
// @returns dList(PrismAction)
// @description
// Returns a list of prism logs for a specified radius of blocks around this location
// with a search for action types.
// For example, <player.location.prism_logs.radius[10].types[block-break|block-place]>
// @Plugin DepenizenBukkit, Prism
// -->
if (attribute.startsWith("types")) {
for (String type : dList.valueOf(attribute.getContext(1))) {
params.addActionType(type);
}
attribute = attribute.fulfill(1);
}
}
// <--[tag]
// @attribute <l@location.prism_logs.types[<action>|...]>
// @returns dList(PrismAction)
// @description
// Returns a list of prism logs for this location, with a search for action types.
// For example, <player.location.prism_logs.types[block-break|block-place]>
// @Plugin DepenizenBukkit, Prism
// -->
else if (attribute.startsWith("types")) {
for (String type : dList.valueOf(attribute.getContext(1))) {
params.addActionType(type);
}
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <l@location.prism_logs.types[<action>|...].radius[<#>]>
// @returns dList(PrismAction)
// @description
// Returns a list of prism logs, with a search for action types, for a specified radius
// of blocks around this location.
// For example, <player.location.prism_logs.types[block-break|block-place].radius[10]>
// @Plugin DepenizenBukkit, Prism
// -->
if (attribute.startsWith("radius")) {
params.setRadius(attribute.getIntContext(1));
isRadius = true;
attribute = attribute.fulfill(1);
}
}
params.setWorld(location.getWorld().getName());
if (isRadius) {
params.setMinMaxVectorsFromPlayerLocation(location);
}
else {
params.setSpecificBlockLocation(location);
}
ActionsQuery query = new ActionsQuery((Prism) Support.getPlugin(PrismSupport.class));
List<Handler> results = query.lookup(params).getActionResults();
dList list = new dList();
for (Handler action : results) {
list.add(new PrismAction(action).identify());
}
return list.getAttribute(attribute);
}
return null;
}
}