-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
WorldGuardBridge.java
65 lines (59 loc) · 3.02 KB
/
WorldGuardBridge.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
package com.denizenscript.depenizen.bukkit.bridges;
import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizencore.DenizenCore;
import com.denizenscript.depenizen.bukkit.commands.worldguard.RegionCommand;
import com.denizenscript.depenizen.bukkit.properties.worldguard.WorldGuardCuboidProperties;
import com.denizenscript.depenizen.bukkit.properties.worldguard.WorldGuardWorldProperties;
import com.denizenscript.depenizen.bukkit.Bridge;
import com.denizenscript.denizen.objects.CuboidTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.objects.WorldTag;
import com.denizenscript.denizencore.objects.ObjectFetcher;
import com.denizenscript.denizencore.tags.TagRunnable;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.tags.ReplaceableTagEvent;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.depenizen.bukkit.properties.worldguard.WorldGuardLocationProperties;
import com.denizenscript.depenizen.bukkit.properties.worldguard.WorldGuardPlayerProperties;
import com.denizenscript.depenizen.bukkit.objects.worldguard.WorldGuardRegionTag;
import com.denizenscript.denizencore.tags.TagManager;
public class WorldGuardBridge extends Bridge {
public static WorldGuardBridge instance;
@Override
public void init() {
instance = this;
ObjectFetcher.registerWithObjectFetcher(WorldGuardRegionTag.class);
PropertyParser.registerProperty(WorldGuardLocationProperties.class, LocationTag.class);
PropertyParser.registerProperty(WorldGuardPlayerProperties.class, PlayerTag.class);
PropertyParser.registerProperty(WorldGuardCuboidProperties.class, CuboidTag.class);
PropertyParser.registerProperty(WorldGuardWorldProperties.class, WorldTag.class);
DenizenCore.commandRegistry.registerCommand(RegionCommand.class);
TagManager.registerTagHandler(new TagRunnable.RootForm() {
@Override
public void run(ReplaceableTagEvent event) {
tagEvent(event);
}
}, "region");
}
public void tagEvent(ReplaceableTagEvent event) {
Attribute attribute = event.getAttributes();
// <--[tag]
// @attribute <region[<region>]>
// @returns WorldGuardRegionTag
// @plugin Depenizen, WorldGuard
// @description
// Returns a WorldGuard region object constructed from the input value.
// Refer to <@link objecttype WorldGuardRegionTag>.
// -->
if (attribute.startsWith("region") && attribute.hasContext(1)) {
WorldGuardRegionTag region = attribute.contextAsType(1, WorldGuardRegionTag.class);
if (region != null) {
event.setReplacedObject(region.getObjectAttribute(attribute.fulfill(1)));
}
else {
attribute.echoError("Unknown WorldGuard region '" + attribute.getContext(1) + "' for region[] tag.");
}
}
}
}