-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
WorldGuardCuboidExtension.java
93 lines (79 loc) · 3.3 KB
/
WorldGuardCuboidExtension.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
package com.morphanone.depenizenbukkit.extensions.worldguard;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
import com.morphanone.depenizenbukkit.extensions.dObjectExtension;
import com.morphanone.depenizenbukkit.objects.worldguard.WorldGuardRegion;
import com.morphanone.depenizenbukkit.support.Support;
import com.morphanone.depenizenbukkit.support.plugins.WorldGuardSupport;
import org.bukkit.World;
import java.util.ArrayList;
import java.util.List;
public class WorldGuardCuboidExtension extends dObjectExtension {
public static boolean describes(dObject cuboid) {
return cuboid instanceof dCuboid;
}
public static WorldGuardCuboidExtension getFrom(dObject cuboid) {
if (!describes(cuboid)) {
return null;
}
else {
return new WorldGuardCuboidExtension((dCuboid) cuboid);
}
}
private WorldGuardCuboidExtension(dCuboid cuboid) {
this.cuboid = cuboid;
}
dCuboid cuboid = null;
private ApplicableRegionSet getApplicableRegions() {
WorldGuardPlugin worldGuard = Support.getPlugin(WorldGuardSupport.class);
dLocation low = cuboid.getLow(0);
dLocation high = cuboid.getHigh(0);
BlockVector vecLow = new BlockVector(low.getX(), low.getY(), low.getZ());
BlockVector vecHigh = new BlockVector(high.getX(), high.getY(), high.getZ());
ProtectedCuboidRegion region = new ProtectedCuboidRegion("FAKE_REGION", vecLow, vecHigh);
return worldGuard.getRegionManager(cuboid.getWorld()).getApplicableRegions(region);
}
private boolean hasRegion() {
return getApplicableRegions().size() > 0;
}
private dList getRegions(World world) {
List<String> regionList = new ArrayList<String>();
for (ProtectedRegion protectedRegion : getApplicableRegions()) {
regionList.add(new WorldGuardRegion(protectedRegion, world).identify());
}
return new dList(regionList);
}
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <cu@cuboid.has_region>
// @returns Element(Boolean)
// @description
// Returns whether the cuboid contains any region.
// @Plugin Depenizen, WorldGuard
// -->
if (attribute.startsWith("has_region")) {
return new Element(hasRegion()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <cu@cuboid.regions>
// @returns dList(Region)
// @description
// Returns a list of regions that are in this cuboid.
// @Plugin Depenizen, WorldGuard
// -->
if (attribute.startsWith("regions")) {
return getRegions(cuboid.getWorld()).getAttribute(attribute.fulfill(1));
}
return null;
}
}