-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
RequirementRegistry.java
463 lines (428 loc) · 14.9 KB
/
RequirementRegistry.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
package net.aufdemrand.denizen.scripts.requirements;
import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.scripts.requirements.core.*;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.interfaces.RegistrationableInstance;
import net.aufdemrand.denizencore.interfaces.dRegistry;
import java.util.HashMap;
import java.util.Map;
public class RequirementRegistry implements dRegistry {
public Denizen denizen;
private Map<String, AbstractRequirement> instances = new HashMap<String, AbstractRequirement>();
private Map<Class<? extends AbstractRequirement>, String> classes = new HashMap<Class<? extends AbstractRequirement>, String>();
public RequirementRegistry(Denizen denizen) {
this.denizen = denizen;
}
@Override
public void disableCoreMembers() {
for (RegistrationableInstance member : instances.values()) {
try {
member.onDisable();
}
catch (Exception e) {
dB.echoError("Unable to disable '" + member.getClass().getName() + "'!");
dB.echoError(e);
}
}
}
@Override
public <T extends RegistrationableInstance> T get(Class<T> clazz) {
if (classes.containsKey(clazz)) {
return clazz.cast(instances.get(classes.get(clazz)));
}
else {
return null;
}
}
@Override
public AbstractRequirement get(String requirementName) {
if (instances.containsKey(requirementName.toUpperCase())) {
return instances.get(requirementName.toUpperCase());
}
else {
return null;
}
}
@Override
public Map<String, AbstractRequirement> list() {
return instances;
}
@Override
public boolean register(String requirementName, RegistrationableInstance requirementClass) {
this.instances.put(requirementName.toUpperCase(), (AbstractRequirement) requirementClass);
this.classes.put(((AbstractRequirement) requirementClass).getClass(), requirementName.toUpperCase());
return true;
}
@Override
public void registerCoreMembers() {
// <--[requirement]
// @Name Enchanted
// @Syntax enchanted [iteminhand]
// @Required 1
// @Stable Stable
// @Short Checks if an item has an enchantment or not.
//
// @Description
// Checks if the specified item has an enchantment. Currently, the only
// item available for this is the "iteminhand".
//
// @Usage
// Use to check if the item in the player's hand has an enchantment.
// - enchanted iteminhand
//
// -->
registerCoreMember(EnchantedRequirement.class,
"ENCHANTED", "enchanted [iteminhand]", 1);
// <--[requirement]
// @Name Flagged
// @Syntax flagged ({player}/npc/global) [<name>([<#>])](:<value>)
// @Required 1
// @Stable Stable
// @Short Checks if the specified flag exists.
//
// @Description
// Checks if the specified flag exists on the specified owner, which is "player"
// by default.
//
// @Usage
// Check if a flag exists.
// - flagged FlagName
//
// @Usage
// Check if a flag has a specified value.
// - flagged FlagName:Value
//
// @Usage
// Check if a flag does not exist.
// - -flagged FlagName
//
// -->
registerCoreMember(FlaggedRequirement.class,
"FLAGGED", "flagged ({player}/npc/global) [<name>([<#>])](:<value>)", 1);
// <--[requirement]
// @Name Holding
// @Syntax holding [<item>] (qty:<#>) (exact)
// @Required 1
// @Stable Stable
// @Short Checks if the player is holding an item.
//
// @Description
// Checks if the player is holding a specified item. The item can be a dItem (i@itemName)
// or it can be a normal material name or ID (wood, 5, 5:1). If a quantity is given, it
// checks if the ItemStack in the player's hand hand has at least that many items. If
// "exact" is specified, it must be the exact quantity of items.
//
// @Usage
// Check if the player is holding at least 3 pieces of wood.
// - holding wood qty:3
//
// -->
registerCoreMember(HoldingRequirement.class,
"HOLDING", "holding [<item>] (qty:<#>) (exact)", 1);
// <--[requirement]
// @Name InGroup
// @Syntax ingroup (global) [<group>]
// @Required 1
// @Stable Stable
// @Short Checks if the player is in a group.
//
// @Description
// Checks if the player is in the specified group in the current world, or global group if specified.
//
// @Usage
// Check if the player is in a group.
// - ingroup Builder
//
// @Usage
// Check if the player is in a global group.
// - ingroup global Admin
//
// -->
registerCoreMember(InGroupRequirement.class,
"INGROUP", "ingroup (global) [<group>]", 1);
// <--[requirement]
// @Name Item
// @Syntax item [<item>] (qty:<#>)
// @Required 1
// @Stable Stable
// @Short Checks if the player has an item.
//
// @Description
// Checks if the player has the specified item and the quantity of that item in their inventory.
//
// @Usage
// Check if the player has an item.
// - item wood qty:3
//
// -->
registerCoreMember(ItemRequirement.class,
"ITEM", "item [<item>] (qty:<#>)", 1);
// <--[requirement]
// @Name IsLiquid
// @Syntax isliquid [location:<location>]
// @Required 1
// @Stable Stable
// @Short Checks if a block is a liquid.
//
// @Description
// Checks if the block at the specified location is a liquid. (Water or lava)
//
// @Usage
// Check if the block is a liquid.
// - isliquid location:103,70,413,world
//
// -->
registerCoreMember(LiquidRequirement.class,
"ISLIQUID", "isliquid [location:<location>]", 1);
// <--[requirement]
// @Name Money
// @Syntax money [qty:<#>]
// @Required 1
// @Stable Stable
// @Short Checks if the player has an amount of money.
//
// @Description
// Checks if the player has a specified amount of money in their account.
//
// @Usage
// Check if the player has an amount of money.
// - money qty:100
//
// -->
registerCoreMember(MoneyRequirement.class,
"MONEY", "money [qty:<#>]", 1);
// <--[requirement]
// @Name Op
// @Syntax op
// @Required 0
// @Stable Stable
// @Short Checks if the player is an op.
//
// @Description
// Checks if the player has Minecraft Op status.
//
// @Usage
// Check if the player is opped.
// - op
//
// -->
registerCoreMember(OpRequirement.class,
"OP", "op", 0);
// <--[requirement]
// @Name Owner
// @Syntax owner
// @Required 0
// @Stable Stable
// @Short Checks if the player is the owner of the current NPC.
//
// @Description
// Checks if the player is the owner of the NPC attached to the current script.
//
// @Usage
// Check if the player is the owner of the NPC.
// - owner
//
// -->
registerCoreMember(OwnerRequirement.class,
"OWNER", "owner", 0);
// <--[requirement]
// @Name Permission
// @Syntax permission (global) [<permission>]
// @Required 1
// @Stable Stable
// @Short Checks if the player has a permission node.
//
// @Description Check if the player has a specified permission node.
// (Requires Vault)
//
// @Usage
// Check if the player has a permission.
// - permission denizen.basic
//
// -->
registerCoreMember(PermissionRequirement.class,
"PERMISSION", "permission (global) [<permission>]", 1);
// <--[requirement]
// @Name IsPowered
// @Syntax ispowered [location:<location>]
// @Required 1
// @Stable Stable
// @Short Checks if a block is powered.
//
// @Description Checks if the block at a specified location is powered
// by a redstone current.
//
// @Usage
// Check if the block is powered.
// - ispowered location:919,78,298
//
// -->
registerCoreMember(PoweredRequirement.class,
"ISPOWERED", "ispowered [location:<location>]", 1);
// <--[requirement]
// @Name Oxygen
// @Syntax oxygen (range:below/equals/above) [qty:<#>]
// @Required 1
// @Stable Stable
// @Short Checks the player's oxygen level.
//
// @Description Checks if the specified oxygen level is above, below, or
// equal to the oxygen level of the player.
//
// @Usage Check if the player has above an amount of oxygen.
// - oxygen range:above qty:3
//
// -->
registerCoreMember(OxygenRequirement.class,
"OXYGEN", "oxygen (range:below/equals/above) [qty:<#>]", 1);
// <--[requirement]
// @Name Procedure
// @Syntax procedure [<script>]
// @Required 1
// @Stable Stable
// @Short Checks the value of the procedure script.
//
// @Description Checks the value of a specified procedure script.
//
// @Usage
// Check if the procedure script determines true
// - procedure procScriptName
//
// -->
registerCoreMember(ProcedureRequirement.class,
"PROCEDURE", "procedure [<script>]", 1);
// <--[requirement]
// @Name Script
// @Syntax script [finished/failed] [script:<name>]
// @Required 2
// @Stable Stable
// @Short Checks if a script is finished or failed.
//
// @Description
// Checks if the specified script was finished or failed by the player.
//
// @Usage
// Check if the script was finished
// - script finished script:ScriptName
//
// @Usage
// Check if the script was failed
// - script failed script:ScriptName
//
// -->
registerCoreMember(ScriptRequirement.class,
"SCRIPT", "script [finished/failed] [script:<name>]", 2);
// <--[requirement]
// @Name Sneaking
// @Syntax sneaking
// @Required 0
// @Stable Stable
// @Short Checks if the player is sneaking.
//
// @Description
// Checks if the player is currently sneaking.
//
// @Usage
// Check if the player is sneaking
// - sneaking
//
// -->
registerCoreMember(SneakingRequirement.class,
"SNEAKING", "sneaking", 0);
// <--[requirement]
// @Name Storming
// @Syntax storming
// @Required 0
// @Stable Stable
// @Short Checks if the player's world is storming.
//
// @Description
// Checks if the world the player is currently in has stormy weather.
//
// @Usage
// Check if the world is storming
// - storming
//
// -->
registerCoreMember(StormRequirement.class,
"STORMING", "storming", 0);
// <--[requirement]
// @Name Sunny
// @Syntax sunny
// @Required 0
// @Stable Stable
// @Short Checks if the player's world is sunny.
//
// @Description
// Checks if the world the player is currently in has sunny weather.
//
// @Usage
// Check if the world is sunny
// - sunny
//
// -->
registerCoreMember(SunnyRequirement.class,
"SUNNY", "sunny", 0);
// <--[requirement]
// @Name Rainy
// @Syntax rainy
// @Required 0
// @Stable Stable
// @Short Checks if the player's world is rainy.
//
// @Description
// Checks if the world the player is currently in has rainy weather.
//
// @Usage
// Check if the world is rainy
// - rainy
//
// -->
registerCoreMember(RainyRequirement.class,
"RAINY", "rainy", 0);
// <--[requirement]
// @Name Time
// @Syntax time [dawn/day/dusk/night]
// @Required 1
// @Stable Stable
// @Short Checks the time of the player's world.
//
// @Description
// Checks if the time of the player's world is currently dawn, day, dusk, or night.
//
// @Usage
// Check the time of day
// - time dusk
//
// -->
registerCoreMember(TimeRequirement.class,
"TIME", "time [dawn/day/dusk/night]", 1);
// <--[requirement]
// @Name InRegion
// @Syntax inregion [name:<region>]
// @Required 1
// @Stable Stable
// @Short Checks if the player is in a region.
//
// @Description
// Checks if the player is in a WorldGuard region. (Requires WorldGuard!)
//
// @Usage
// Check if the player is in a region
// - inregion name:MyRegion
//
// -->
registerCoreMember(WorldGuardRegionRequirement.class,
"INREGION", "inregion [name:<region>]", 1);
dB.echoApproval("Loaded core requirements: " + instances.keySet().toString());
}
private <T extends AbstractRequirement> void registerCoreMember(Class<T> requirement, String name, String hint, int args) {
try {
requirement.newInstance().activate().as(name).withOptions("(-)" + hint, args);
}
catch (Exception e) {
dB.echoError("Could not register requirement " + name + ": " + e.getMessage());
dB.echoError(e);
}
}
}