-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
WorldGuardPlayerProperties.java
139 lines (119 loc) · 5.12 KB
/
WorldGuardPlayerProperties.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
package com.denizenscript.depenizen.bukkit.properties.worldguard;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.depenizen.bukkit.bridges.WorldGuardBridge;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import com.denizenscript.denizen.objects.dLocation;
import com.denizenscript.denizen.objects.dPlayer;
import com.denizenscript.denizencore.objects.Element;
import com.denizenscript.denizencore.objects.dObject;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class WorldGuardPlayerProperties implements Property {
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "WorldGuardPlayer";
}
@Override
public void adjust(Mechanism mechanism) {
// None
}
public static boolean describes(dObject object) {
return object instanceof dPlayer
&& ((dPlayer) object).isOnline();
}
public static WorldGuardPlayerProperties getFrom(dObject object) {
if (!describes(object)) {
return null;
}
return new WorldGuardPlayerProperties((dPlayer) object);
}
public static final String[] handledTags = new String[] {
"worldguard"
};
public static final String[] handledMechs = new String[] {
}; // None
private WorldGuardPlayerProperties(dPlayer player) {
this.player = player.getPlayerEntity();
}
Player player = null;
private StateFlag getStateFlag(String s) {
Flag flag = Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), s);
return flag instanceof StateFlag ? (StateFlag) flag : null;
}
@Override
public String getAttribute(Attribute attribute) {
if (!attribute.startsWith("worldguard") && !attribute.startsWith("wg")) {
return null;
}
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <p@player.worldguard.can_build[<location>]>
// @returns Element(Boolean)
// @description
// Whether WorldGuard allows to build at a location.
// @Plugin Depenizen, WorldGuard
// -->
if (attribute.startsWith("can_build") && attribute.hasContext(1)) {
dLocation location = dLocation.valueOf(attribute.getContext(1));
if (location == null) {
return null;
}
WorldGuardPlugin worldGuard = (WorldGuardPlugin) WorldGuardBridge.instance.plugin;
return new Element(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().testBuild(BukkitAdapter.adapt(location), worldGuard.wrapPlayer(player)))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.worldguard.test_flag[<name>]>
// @returns Element(Boolean)
// @description
// Returns the state of a flag for that player at their location.
// For example: .test_flag[pvp] returns 'true' when the player can be attacked.
// @Plugin Depenizen, WorldGuard
// -->
if (attribute.startsWith("test_flag")) {
if (!attribute.hasContext(1)) {
Debug.echoError("The tag p@player.worlduard.test_flag[...] must have a value.");
return null;
}
StateFlag flag = getStateFlag(attribute.getContext(1));
if (flag == null) {
Debug.echoError("The tag p@player.worlduard.test_flag[...] has an invalid value: " + attribute.getContext(1));
return null;
}
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
Location loc = player.getLocation();
int args = 1;
// <--[tag]
// @attribute <p@player.worldguard.test_flag[<name>].at[<location>]>
// @returns Element(Boolean)
// @description
// Returns the state of a flag for that player at the specified location.
// @Plugin Depenizen, WorldGuard
// -->
if (attribute.getAttribute(2).startsWith("at") && attribute.hasContext(2)) {
loc = dLocation.valueOf(attribute.getContext(2));
args = 2;
if (loc == null) {
return null;
}
}
WorldGuardPlugin worldGuard = (WorldGuardPlugin) WorldGuardBridge.instance.plugin;
return new Element(query.testState(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player), flag))
.getAttribute(attribute.fulfill(args));
}
return null;
}
}