getRegion(@NonNull World world, @NonNull String id);
95 |
96 | /**
97 | * Get an unmodifiable map of regions containing the state of the
98 | * index at the time of call.
99 | *
100 | * This call is relatively heavy (and may block other threads),
101 | * so refrain from calling it frequently.
102 | *
103 | * @param world The world
104 | * @return A map of regions
105 | */
106 | Map getRegions(@NonNull World world);
107 |
108 | /**
109 | * Get a set of regions at the given location.
110 | *
111 | * @param location The location
112 | * @return A set of regions
113 | */
114 | Set getRegions(@NonNull Location location);
115 |
116 |
117 | /**
118 | * Get a set of regions in the given cuboid area.
119 | *
120 | * @param minimum The minimum location of the area
121 | * @param maximum The maximum location of the area
122 | * @return A set of regions
123 | */
124 | Set getRegions(@NonNull Location minimum, @NonNull Location maximum);
125 |
126 | /**
127 | * Get the applicable region set at the given location-
128 | *
129 | * @param location The location
130 | * @return The region set
131 | */
132 | Optional getRegionSet(@NonNull Location location);
133 |
134 | /**
135 | * Add a region. If only two points are given, a cuboid region will be created.
136 | *
137 | * @param id The region ID
138 | * @param points A {@link List} of points that the region should contain
139 | * @param minY The minimum y coordinate
140 | * @param maxY The maximum y coordinate
141 | * @return The added region
142 | */
143 | Optional addRegion(@NonNull String id, @NonNull List points, int minY, int maxY);
144 |
145 | /**
146 | * Add a cuboid region.
147 | *
148 | * @param id The region ID
149 | * @param point1 The first point of the region
150 | * @param point2 The second point of the region
151 | * @return The added region
152 | */
153 | default Optional addCuboidRegion(
154 | @NonNull String id,
155 | @NonNull Location point1,
156 | @NonNull Location point2
157 | ) {
158 | return addRegion(id, Arrays.asList(point1, point2), 0, 0);
159 | }
160 |
161 | /**
162 | * Add a region for the given selection.
163 | *
164 | * @param id The region ID
165 | * @param selection The selection for the region's volume
166 | * @return The added region
167 | */
168 | default Optional addRegion(@NonNull String id, @NonNull ISelection selection) {
169 | if (selection instanceof ICuboidSelection) {
170 | ICuboidSelection sel = (ICuboidSelection) selection;
171 | return addCuboidRegion(id, sel.getMinimumPoint(), sel.getMaximumPoint());
172 | } else if (selection instanceof IPolygonalSelection) {
173 | IPolygonalSelection sel = (IPolygonalSelection) selection;
174 | return addRegion(id, new ArrayList<>(sel.getPoints()), sel.getMinimumY(), sel.getMaximumY());
175 | } else {
176 | throw new UnsupportedOperationException("Unknown " + selection.getClass().getSimpleName()
177 | + " selection type!");
178 | }
179 | }
180 |
181 | /**
182 | * Remove a region, including inheriting children.
183 | *
184 | * @param world The world
185 | * @param id The region ID
186 | * @return A list of removed regions where the first entry is the region specified by {@code id}
187 | */
188 | Optional> removeRegion(@NonNull World world, @NonNull String id);
189 |
190 | /**
191 | * Returns the current selection of the given player.
192 | *
193 | * @param player The player
194 | * @return The current player's selection
195 | */
196 | Optional getPlayerSelection(@NonNull Player player);
197 |
198 | }
199 |
--------------------------------------------------------------------------------
/api/src/main/java/org/codemc/worldguardwrapper/region/IWrappedDomain.java:
--------------------------------------------------------------------------------
1 | package org.codemc.worldguardwrapper.region;
2 |
3 | import java.util.Set;
4 | import java.util.UUID;
5 |
6 | @SuppressWarnings("unused")
7 | public interface IWrappedDomain {
8 |
9 | Set getPlayers();
10 |
11 | void addPlayer(UUID uuid);
12 |
13 | void removePlayer(UUID uuid);
14 |
15 | Set getGroups();
16 |
17 | void addGroup(String name);
18 |
19 | void removeGroup(String name);
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/api/src/main/java/org/codemc/worldguardwrapper/region/IWrappedRegion.java:
--------------------------------------------------------------------------------
1 | package org.codemc.worldguardwrapper.region;
2 |
3 | import org.bukkit.Location;
4 | import org.codemc.worldguardwrapper.flag.IWrappedFlag;
5 | import org.codemc.worldguardwrapper.selection.ISelection;
6 |
7 | import java.util.Map;
8 | import java.util.Optional;
9 |
10 | @SuppressWarnings("unused")
11 | public interface IWrappedRegion {
12 |
13 | ISelection getSelection();
14 |
15 | String getId();
16 |
17 | Map, Object> getFlags();
18 |
19 | Optional getFlag(IWrappedFlag flag);
20 |
21 | void setFlag(IWrappedFlag flag, T value);
22 |
23 | int getPriority();
24 |
25 | void setPriority(int priority);
26 |
27 | IWrappedDomain getOwners();
28 |
29 | IWrappedDomain getMembers();
30 |
31 | boolean contains(Location location);
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/api/src/main/java/org/codemc/worldguardwrapper/region/IWrappedRegionSet.java:
--------------------------------------------------------------------------------
1 | package org.codemc.worldguardwrapper.region;
2 |
3 | import org.bukkit.OfflinePlayer;
4 | import org.codemc.worldguardwrapper.flag.IWrappedFlag;
5 |
6 | import java.util.Collection;
7 | import java.util.Optional;
8 | import java.util.Set;
9 |
10 | @SuppressWarnings("unused")
11 | public interface IWrappedRegionSet extends Iterable {
12 |
13 | boolean isVirtual();
14 |
15 | Optional queryValue(OfflinePlayer subject, IWrappedFlag flag);
16 |
17 | Collection queryAllValues(OfflinePlayer subject, IWrappedFlag flag);
18 |
19 | boolean isOwnerOfAll(OfflinePlayer player);
20 |
21 | boolean isMemberOfAll(OfflinePlayer player);
22 |
23 | int size();
24 |
25 | Set getRegions();
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/api/src/main/java/org/codemc/worldguardwrapper/selection/ICuboidSelection.java:
--------------------------------------------------------------------------------
1 | package org.codemc.worldguardwrapper.selection;
2 |
3 | import org.bukkit.Location;
4 |
5 | @SuppressWarnings("unused")
6 | public interface ICuboidSelection extends ISelection {
7 |
8 | Location getMinimumPoint();
9 |
10 | Location getMaximumPoint();
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/api/src/main/java/org/codemc/worldguardwrapper/selection/IPolygonalSelection.java:
--------------------------------------------------------------------------------
1 | package org.codemc.worldguardwrapper.selection;
2 |
3 | import org.bukkit.Location;
4 |
5 | import java.util.Set;
6 |
7 | @SuppressWarnings("unused")
8 | public interface IPolygonalSelection extends ISelection {
9 |
10 | Set getPoints();
11 |
12 | int getMinimumY();
13 |
14 | int getMaximumY();
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/api/src/main/java/org/codemc/worldguardwrapper/selection/ISelection.java:
--------------------------------------------------------------------------------
1 | package org.codemc.worldguardwrapper.selection;
2 |
3 | @SuppressWarnings("unused")
4 | public interface ISelection {
5 | }
6 |
--------------------------------------------------------------------------------
/api/src/main/java/org/codemc/worldguardwrapper/utility/SelectionUtilities.java:
--------------------------------------------------------------------------------
1 | package org.codemc.worldguardwrapper.utility;
2 |
3 | import lombok.experimental.UtilityClass;
4 | import org.bukkit.Location;
5 | import org.codemc.worldguardwrapper.selection.ICuboidSelection;
6 | import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
7 |
8 | import java.util.Collection;
9 | import java.util.HashSet;
10 | import java.util.Set;
11 |
12 | @SuppressWarnings("unused")
13 | @UtilityClass
14 | public class SelectionUtilities {
15 |
16 | /**
17 | * Creates a static cuboid selection.
18 | *
19 | * @param first the first point of the cuboid
20 | * @param second the second point of the cuboid
21 | * @return the selection
22 | */
23 | public ICuboidSelection createCuboidSelection(Location first, Location second) {
24 | Location minimum;
25 | Location maximum;
26 | if (first.getBlockY() > second.getBlockY()) {
27 | maximum = first;
28 | minimum = second;
29 | } else {
30 | maximum = second;
31 | minimum = first;
32 | }
33 | return new ICuboidSelection() {
34 | @Override
35 | public Location getMinimumPoint() {
36 | return minimum;
37 | }
38 |
39 | @Override
40 | public Location getMaximumPoint() {
41 | return maximum;
42 | }
43 | };
44 | }
45 |
46 | /**
47 | * Creates a static polygonal selection.
48 | *
49 | * @param points the points of the selection
50 | * @param minY the minimum Y coordinate of the selection
51 | * @param maxY the maximum Y coordinate of the selection
52 | * @return the selection
53 | */
54 | public IPolygonalSelection createPolygonalSelection(Collection points, int minY, int maxY) {
55 | return new IPolygonalSelection() {
56 | @Override
57 | public Set getPoints() {
58 | return new HashSet<>(points);
59 | }
60 |
61 | @Override
62 | public int getMinimumY() {
63 | return minY;
64 | }
65 |
66 | @Override
67 | public int getMaximumY() {
68 | return maxY;
69 | }
70 | };
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/implementation/legacy/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.codemc.worldguardwrapper
9 | worldguardwrapper-implementation
10 | 1.2.1-SNAPSHOT
11 | ../pom.xml
12 |
13 |
14 | worldguardwrapper-implementation-legacy
15 |
16 | WorldGuardWrapper-Implementation-Legacy
17 |
18 |
19 |
20 | enginehub-repo
21 | https://maven.enginehub.org/repo/
22 |
23 | always
24 |
25 |
26 |
27 |
28 |
29 |
30 | ${project.groupId}
31 | worldguardwrapper-api
32 | 1.2.1-SNAPSHOT
33 | provided
34 |
35 |
36 | com.sk89q
37 | worldguard
38 | 6.1
39 | provided
40 |
41 |
42 | com.sk89q.spigot
43 | bukkit-classloader-check
44 |
45 |
46 | org.bukkit
47 | bukkit
48 |
49 |
50 | com.sk89q
51 | commandbook
52 |
53 |
54 | de.schlichtherle
55 | truezip
56 |
57 |
58 | rhino
59 | js
60 |
61 |
62 | com.sk89q
63 | jchronic
64 |
65 |
66 | com.google.code.findbugs
67 | jsr305
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/implementation/legacy/src/main/java/org/codemc/worldguardwrapper/implementation/legacy/WorldGuardImplementation.java:
--------------------------------------------------------------------------------
1 | package org.codemc.worldguardwrapper.implementation.legacy;
2 |
3 | import com.google.common.collect.Iterators;
4 | import com.sk89q.minecraft.util.commands.CommandException;
5 | import com.sk89q.worldedit.BlockVector;
6 | import com.sk89q.worldedit.bukkit.WorldEditPlugin;
7 | import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
8 | import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
9 | import com.sk89q.worldguard.LocalPlayer;
10 | import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
11 | import com.sk89q.worldguard.protection.ApplicableRegionSet;
12 | import com.sk89q.worldguard.protection.flags.DefaultFlag;
13 | import com.sk89q.worldguard.protection.flags.Flag;
14 | import com.sk89q.worldguard.protection.managers.RegionManager;
15 | import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
16 | import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
17 | import com.sk89q.worldguard.protection.regions.ProtectedRegion;
18 | import lombok.NonNull;
19 | import org.bukkit.Location;
20 | import org.bukkit.OfflinePlayer;
21 | import org.bukkit.World;
22 | import org.bukkit.entity.Player;
23 | import org.bukkit.plugin.java.JavaPlugin;
24 | import org.codemc.worldguardwrapper.flag.IWrappedFlag;
25 | import org.codemc.worldguardwrapper.handler.IHandler;
26 | import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
27 | import org.codemc.worldguardwrapper.implementation.legacy.flag.AbstractWrappedFlag;
28 | import org.codemc.worldguardwrapper.implementation.legacy.region.WrappedRegion;
29 | import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardFlagUtilities;
30 | import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardVectorUtilities;
31 | import org.codemc.worldguardwrapper.region.IWrappedRegion;
32 | import org.codemc.worldguardwrapper.region.IWrappedRegionSet;
33 | import org.codemc.worldguardwrapper.selection.ICuboidSelection;
34 | import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
35 | import org.codemc.worldguardwrapper.selection.ISelection;
36 |
37 | import java.util.*;
38 | import java.util.function.Supplier;
39 | import java.util.stream.Collectors;
40 |
41 | public class WorldGuardImplementation implements IWorldGuardImplementation {
42 |
43 | private final WorldGuardPlugin worldGuardPlugin;
44 | private final WorldEditPlugin worldEditPlugin;
45 |
46 | public WorldGuardImplementation() {
47 | worldGuardPlugin = WorldGuardPlugin.inst();
48 | try {
49 | worldEditPlugin = worldGuardPlugin.getWorldEdit();
50 | } catch (CommandException e) {
51 | throw new RuntimeException(e);
52 | }
53 | }
54 |
55 | private Optional wrapPlayer(OfflinePlayer player) {
56 | return Optional.ofNullable(player).map(bukkitPlayer -> bukkitPlayer.isOnline() ?
57 | worldGuardPlugin.wrapPlayer((Player) bukkitPlayer) : worldGuardPlugin.wrapOfflinePlayer(bukkitPlayer));
58 | }
59 |
60 | private Optional getWorldManager(@NonNull World world) {
61 | return Optional.ofNullable(worldGuardPlugin.getRegionManager(world));
62 | }
63 |
64 | private Optional getApplicableRegions(@NonNull Location location) {
65 | return getWorldManager(Objects.requireNonNull(location.getWorld()))
66 | .map(manager -> manager.getApplicableRegions(location));
67 | }
68 |
69 | private Optional getApplicableRegions(@NonNull Location minimum, @NonNull Location maximum) {
70 | return getWorldManager(Objects.requireNonNull(minimum.getWorld()))
71 | .map(manager ->
72 | manager.getApplicableRegions(
73 | new ProtectedCuboidRegion(
74 | "temp",
75 | WorldGuardVectorUtilities.toBlockVector(minimum),
76 | WorldGuardVectorUtilities.toBlockVector(maximum)
77 | )
78 | )
79 | );
80 | }
81 |
82 | private Optional queryValue(Player player, @NonNull Location location, @NonNull Flag flag) {
83 | return getApplicableRegions(location)
84 | .map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player).orElse(null), flag));
85 | }
86 |
87 | private IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) {
88 | return new IWrappedRegionSet() {
89 |
90 | @Override
91 | public Iterator iterator() {
92 | return Iterators.transform(regionSet.iterator(), region -> new WrappedRegion(world, region));
93 | }
94 |
95 | @Override
96 | public boolean isVirtual() {
97 | return regionSet.isVirtual();
98 | }
99 |
100 | @Override
101 | public Optional queryValue(OfflinePlayer subject, IWrappedFlag flag) {
102 | LocalPlayer subjectHandle = wrapPlayer(subject).orElse(null);
103 | AbstractWrappedFlag wrappedFlag = (AbstractWrappedFlag) flag;
104 | return Optional.ofNullable(regionSet.queryValue(subjectHandle, wrappedFlag.getHandle()))
105 | .flatMap(wrappedFlag::fromWGValue);
106 | }
107 |
108 | @Override
109 | public Collection queryAllValues(OfflinePlayer subject, IWrappedFlag flag) {
110 | LocalPlayer subjectHandle = wrapPlayer(subject).orElse(null);
111 | AbstractWrappedFlag wrappedFlag = (AbstractWrappedFlag) flag;
112 | return regionSet.queryAllValues(subjectHandle, wrappedFlag.getHandle()).stream()
113 | .map(wrappedFlag::fromWGValue)
114 | .filter(Optional::isPresent)
115 | .map(Optional::get)
116 | .collect(Collectors.toList());
117 | }
118 |
119 | @Override
120 | public boolean isOwnerOfAll(OfflinePlayer player) {
121 | LocalPlayer playerHandle = wrapPlayer(player).orElse(null);
122 | return regionSet.isOwnerOfAll(playerHandle);
123 | }
124 |
125 | @Override
126 | public boolean isMemberOfAll(OfflinePlayer player) {
127 | LocalPlayer playerHandle = wrapPlayer(player).orElse(null);
128 | return regionSet.isMemberOfAll(playerHandle);
129 | }
130 |
131 | @Override
132 | public int size() {
133 | return regionSet.size();
134 | }
135 |
136 | @Override
137 | public Set getRegions() {
138 | return regionSet.getRegions().stream()
139 | .map(region -> new WrappedRegion(world, region)).collect(Collectors.toSet());
140 | }
141 | };
142 | }
143 |
144 | @Override
145 | public JavaPlugin getWorldGuardPlugin() {
146 | return WorldGuardPlugin.inst();
147 | }
148 |
149 | @Override
150 | public int getApiVersion() {
151 | return -6;
152 | }
153 |
154 | @Override
155 | public void registerHandler(Supplier factory) {
156 | throw new UnsupportedOperationException("Custom flag handlers aren't supported in this version of WorldGuard!");
157 | }
158 |
159 | @Override
160 | public Optional> getFlag(String name, Class type) {
161 | for (Flag> currentFlag : DefaultFlag.getFlags()) {
162 | if (currentFlag.getName().equalsIgnoreCase(name)) {
163 | return Optional.of(WorldGuardFlagUtilities.wrap(currentFlag, type));
164 | }
165 | }
166 | return Optional.empty();
167 | }
168 |
169 | @Override
170 | public Optional queryFlag(Player player, @NonNull Location location, @NonNull IWrappedFlag flag) {
171 | AbstractWrappedFlag wrappedFlag = (AbstractWrappedFlag) flag;
172 |
173 | return queryValue(player, location, wrappedFlag.getHandle()).flatMap(wrappedFlag::fromWGValue);
174 | }
175 |
176 | @Override
177 | public Map, Object> queryApplicableFlags(Player player, Location location) {
178 | ApplicableRegionSet applicableSet = getApplicableRegions(location).orElse(null);
179 | if (applicableSet == null) {
180 | return Collections.emptyMap();
181 | }
182 |
183 | LocalPlayer localPlayer = wrapPlayer(player).orElse(null);
184 | Map, Object> flags = new HashMap<>();
185 | Set seen = new HashSet<>();
186 |
187 | for (ProtectedRegion region : applicableSet.getRegions()) {
188 | for (Flag> flag : region.getFlags().keySet()) {
189 | if (seen.add(flag.getName())) {
190 | Object value = applicableSet.queryValue(localPlayer, flag);
191 | if (value == null) {
192 | continue;
193 | }
194 |
195 | try {
196 | Map.Entry, Object> wrapped = WorldGuardFlagUtilities.wrap(flag, value);
197 | flags.put(wrapped.getKey(), wrapped.getValue());
198 | } catch (IllegalArgumentException e) {
199 | // Unsupported flag type
200 | }
201 | }
202 | }
203 | }
204 |
205 | return flags;
206 | }
207 |
208 | @Override
209 | public Optional> registerFlag(@NonNull String name, @NonNull Class type, T defaultValue) {
210 | throw new UnsupportedOperationException("Custom flags aren't supported in this version of WorldGuard!");
211 | }
212 |
213 | @Override
214 | public Optional getRegion(@NonNull World world, @NonNull String id) {
215 | return getWorldManager(world)
216 | .map(regionManager -> regionManager.getRegion(id))
217 | .map(region -> new WrappedRegion(world, region));
218 | }
219 |
220 | @Override
221 | public Map getRegions(@NonNull World world) {
222 | RegionManager regionManager = worldGuardPlugin.getRegionManager(world);
223 | Map regions = regionManager.getRegions();
224 |
225 | Map map = new HashMap<>();
226 | regions.forEach((name, region) -> map.put(name, new WrappedRegion(world, region)));
227 |
228 | return map;
229 | }
230 |
231 | @Override
232 | public Set getRegions(@NonNull Location location) {
233 | ApplicableRegionSet regionSet = getApplicableRegions(location).orElse(null);
234 | Set set = new HashSet<>();
235 |
236 | if (regionSet == null) {
237 | return set;
238 | }
239 |
240 | regionSet.forEach(region -> set.add(new WrappedRegion(location.getWorld(), region)));
241 | return set;
242 | }
243 |
244 | @Override
245 | public Set getRegions(@NonNull Location minimum, @NonNull Location maximum) {
246 | ApplicableRegionSet regionSet = getApplicableRegions(minimum, maximum).orElse(null);
247 | Set set = new HashSet<>();
248 |
249 | if (regionSet == null) {
250 | return set;
251 | }
252 |
253 | regionSet.forEach(region -> set.add(new WrappedRegion(minimum.getWorld(), region)));
254 | return set;
255 | }
256 |
257 | @Override
258 | public Optional getRegionSet(@NonNull Location location) {
259 | return getApplicableRegions(location)
260 | .map(regionSet -> wrapRegionSet(Objects.requireNonNull(location.getWorld()), regionSet));
261 | }
262 |
263 | @Override
264 | public Optional addRegion(@NonNull String id, @NonNull List points, int minY, int maxY) {
265 | ProtectedRegion region;
266 | World world = Objects.requireNonNull(points.get(0).getWorld());
267 | if (points.size() == 2) {
268 | region = new ProtectedCuboidRegion(
269 | id,
270 | WorldGuardVectorUtilities.toBlockVector(points.get(0)),
271 | WorldGuardVectorUtilities.toBlockVector(points.get(1))
272 | );
273 | } else {
274 | region = new ProtectedPolygonalRegion(
275 | id,
276 | WorldGuardVectorUtilities.toBlockVector2DList(points),
277 | minY,
278 | maxY
279 | );
280 | }
281 |
282 | Optional manager = getWorldManager(world);
283 | if (manager.isPresent()) {
284 | manager.get().addRegion(region);
285 | return Optional.of(new WrappedRegion(world, region));
286 | } else {
287 | return Optional.empty();
288 | }
289 | }
290 |
291 | @Override
292 | public Optional> removeRegion(@NonNull World world, @NonNull String id) {
293 | Optional> set = getWorldManager(world).map(manager -> manager.removeRegion(id));
294 | return set.map(protectedRegions -> protectedRegions.stream().map(region -> new WrappedRegion(world, region))
295 | .collect(Collectors.toSet()));
296 | }
297 |
298 | @Override
299 | public Optional getPlayerSelection(@NonNull Player player) {
300 | return Optional.ofNullable(worldEditPlugin.getSelection(player))
301 | .map(selection -> {
302 | if (selection instanceof CuboidSelection) {
303 | return new ICuboidSelection() {
304 | @Override
305 | public Location getMinimumPoint() {
306 | return selection.getMinimumPoint();
307 | }
308 |
309 | @Override
310 | public Location getMaximumPoint() {
311 | return selection.getMaximumPoint();
312 | }
313 | };
314 | } else if (selection instanceof Polygonal2DSelection) {
315 | return new IPolygonalSelection() {
316 | @Override
317 | public Set getPoints() {
318 | return ((Polygonal2DSelection) selection).getNativePoints().stream()
319 | .map(vector -> new BlockVector(vector.toVector()))
320 | .map(vector ->
321 | WorldGuardVectorUtilities.fromBlockVector(
322 | selection.getWorld(),
323 | vector
324 | )
325 | )
326 | .collect(Collectors.toSet());
327 | }
328 |
329 | @Override
330 | public int getMinimumY() {
331 | return selection.getMinimumPoint().getBlockY();
332 | }
333 |
334 | @Override
335 | public int getMaximumY() {
336 | return selection.getMaximumPoint().getBlockY();
337 | }
338 | };
339 | } else {
340 | throw new UnsupportedOperationException("Unsupported " + selection.getClass().getSimpleName()
341 | + " selection!");
342 | }
343 | });
344 | }
345 | }
346 |
--------------------------------------------------------------------------------
/implementation/legacy/src/main/java/org/codemc/worldguardwrapper/implementation/legacy/event/EventListener.java:
--------------------------------------------------------------------------------
1 | package org.codemc.worldguardwrapper.implementation.legacy.event;
2 |
3 | import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent;
4 | import com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent;
5 | import com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent;
6 | import com.sk89q.worldguard.protection.events.DisallowedPVPEvent;
7 | import lombok.NoArgsConstructor;
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.entity.Player;
10 | import org.bukkit.event.Event.Result;
11 | import org.bukkit.event.EventHandler;
12 | import org.bukkit.event.EventPriority;
13 | import org.bukkit.event.Listener;
14 | import org.codemc.worldguardwrapper.event.*;
15 |
16 | @NoArgsConstructor
17 | public class EventListener implements Listener {
18 |
19 | @EventHandler(priority = EventPriority.LOW)
20 | public void onUseBlock(UseBlockEvent worldGuardEvent) {
21 | Player player = worldGuardEvent.getCause().getFirstPlayer();
22 | if (player == null) {
23 | // Only forward player events for now
24 | return;
25 | }
26 |
27 | AbstractWrappedEvent event = new WrappedUseBlockEvent(
28 | worldGuardEvent.getOriginalEvent(),
29 | player, worldGuardEvent.getWorld(),
30 | worldGuardEvent.getBlocks(),
31 | worldGuardEvent.getEffectiveMaterial());
32 | Bukkit.getServer().getPluginManager().callEvent(event);
33 |
34 | if (event.getResult() != Result.DEFAULT) {
35 | // DEFAULT = Result probably has not been touched by the handler,
36 | // so don't touch the original result either.
37 | worldGuardEvent.setResult(event.getResult());
38 | }
39 | }
40 |
41 | @EventHandler(priority = EventPriority.LOW)
42 | public void onUseEntity(UseEntityEvent worldGuardEvent) {
43 | Player player = worldGuardEvent.getCause().getFirstPlayer();
44 | if (player == null) {
45 | // Only forward player events for now
46 | return;
47 | }
48 |
49 | AbstractWrappedEvent event = new WrappedUseEntityEvent(
50 | worldGuardEvent.getOriginalEvent(),
51 | player,
52 | worldGuardEvent.getTarget(),
53 | worldGuardEvent.getEntity());
54 | Bukkit.getServer().getPluginManager().callEvent(event);
55 |
56 | if (event.getResult() != Result.DEFAULT) {
57 | // DEFAULT = Result probably has not been touched by the handler,
58 | // so don't touch the original result either.
59 | worldGuardEvent.setResult(event.getResult());
60 | }
61 | }
62 |
63 | @EventHandler(priority = EventPriority.LOW)
64 | public void onDamageEntity(DamageEntityEvent worldGuardEvent) {
65 | Player player = worldGuardEvent.getCause().getFirstPlayer();
66 | if (player == null) {
67 | // Only forward player events for now
68 | return;
69 | }
70 |
71 | AbstractWrappedEvent event = new WrappedDamageEntityEvent(
72 | worldGuardEvent.getOriginalEvent(),
73 | player,
74 | worldGuardEvent.getTarget(),
75 | worldGuardEvent.getEntity());
76 | Bukkit.getServer().getPluginManager().callEvent(event);
77 |
78 | if (event.getResult() != Result.DEFAULT) {
79 | // DEFAULT = Result probably has not been touched by the handler,
80 | // so don't touch the original result either.
81 | worldGuardEvent.setResult(event.getResult());
82 | }
83 | }
84 |
85 | @EventHandler(priority = EventPriority.LOW)
86 | public void onDisallowedPVP(DisallowedPVPEvent worldGuardEvent) {
87 | AbstractWrappedEvent event = new WrappedDisallowedPVPEvent(
88 | worldGuardEvent.getAttacker(),
89 | worldGuardEvent.getDefender(),
90 | worldGuardEvent.getCause());
91 | Bukkit.getServer().getPluginManager().callEvent(event);
92 |
93 | if (event.getResult() != Result.DEFAULT) {
94 | // DEFAULT = Result probably has not been touched by the handler,
95 | // so don't touch the original result either.
96 | worldGuardEvent.setCancelled(event.getResult() == Result.DENY);
97 | }
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/implementation/legacy/src/main/java/org/codemc/worldguardwrapper/implementation/legacy/flag/AbstractWrappedFlag.java:
--------------------------------------------------------------------------------
1 | package org.codemc.worldguardwrapper.implementation.legacy.flag;
2 |
3 | import com.sk89q.worldguard.protection.flags.Flag;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Getter;
6 | import org.codemc.worldguardwrapper.flag.IWrappedFlag;
7 |
8 | import java.util.Optional;
9 |
10 | @AllArgsConstructor
11 | @Getter
12 | public abstract class AbstractWrappedFlag implements IWrappedFlag {
13 |
14 | private final Flag> handle;
15 |
16 | @Override
17 | public String getName() {
18 | return handle.getName();
19 | }
20 |
21 | public abstract Optional fromWGValue(Object value);
22 |
23 | public abstract Optional