forked from clone/WorldGuardWrapper
Implement region points, implement get regions from area
This commit is contained in:
parent
487394e256
commit
946809ebad
|
@ -0,0 +1,11 @@
|
||||||
|
package org.codemc.worldguardwrapper.region;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public interface WrappedPolygonalRegion extends WrappedRegion {
|
||||||
|
|
||||||
|
Set<Location> getPoints();
|
||||||
|
|
||||||
|
}
|
|
@ -1,12 +1,17 @@
|
||||||
package org.codemc.worldguardwrapper.region;
|
package org.codemc.worldguardwrapper.region;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface WrappedRegion {
|
public interface WrappedRegion {
|
||||||
|
|
||||||
|
Location getMinimumPoint();
|
||||||
|
|
||||||
|
Location getMaximumPoint();
|
||||||
|
|
||||||
String getId();
|
String getId();
|
||||||
|
|
||||||
Optional<Object> getFlag(String name);
|
Optional<Object> getFlag(String name);
|
||||||
|
|
|
@ -8,11 +8,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
|
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.region.WrappedRegion;
|
import org.codemc.worldguardwrapper.region.WrappedRegion;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public interface IWorldGuardImplementation {
|
public interface IWorldGuardImplementation {
|
||||||
|
|
||||||
|
@ -109,6 +105,16 @@ public interface IWorldGuardImplementation {
|
||||||
*/
|
*/
|
||||||
Set<WrappedRegion> getRegions(@NonNull Location location);
|
Set<WrappedRegion> getRegions(@NonNull Location location);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a set of regions in the given cuboid area.
|
||||||
|
*
|
||||||
|
* @param minimum The minimum location of the area
|
||||||
|
* @param maximum The maximum location of the area
|
||||||
|
* @return A set of regions
|
||||||
|
*/
|
||||||
|
Set<WrappedRegion> getRegions(@NonNull Location minimum, @NonNull Location maximum);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a region. If only two points are given, a cuboid region will be created.
|
* Add a region. If only two points are given, a cuboid region will be created.
|
||||||
*
|
*
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
|
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||||
|
import org.codemc.worldguardwrapper.region.WrappedPolygonalRegion;
|
||||||
import org.codemc.worldguardwrapper.region.WrappedRegion;
|
import org.codemc.worldguardwrapper.region.WrappedRegion;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -46,54 +47,125 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(location));
|
return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location minimum, @NonNull Location maximum) {
|
||||||
|
return getWorldManager(minimum.getWorld()).map(manager -> manager.getApplicableRegions(
|
||||||
|
new ProtectedCuboidRegion("temp", toBlockVector(minimum), toBlockVector(maximum))));
|
||||||
|
}
|
||||||
|
|
||||||
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
|
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
|
||||||
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player).orElse(null), flag));
|
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player)
|
||||||
|
.orElse(null), flag));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<StateFlag.State> queryState(Player player, @NonNull Location location, @NonNull StateFlag... stateFlags) {
|
private Optional<StateFlag.State> queryState(Player player, @NonNull Location location, @NonNull StateFlag... stateFlags) {
|
||||||
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryState(wrapPlayer(player).orElse(null), stateFlags));
|
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryState(wrapPlayer(player)
|
||||||
|
.orElse(null), stateFlags));
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockVector toBlockVector(Location location) {
|
private BlockVector toBlockVector(Location location) {
|
||||||
return new BlockVector(location.getX(), location.getY(), location.getZ());
|
return new BlockVector(location.getX(), location.getY(), location.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Location fromBlockVector(World world, BlockVector vector) {
|
||||||
|
return new Location(world, vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
private List<BlockVector2D> toBlockVector2DList(List<Location> locations) {
|
private List<BlockVector2D> toBlockVector2DList(List<Location> locations) {
|
||||||
return locations.stream().map(location -> new BlockVector2D(location.getX(), location.getZ())).collect(Collectors.toList());
|
return locations.stream().map(location -> new BlockVector2D(location.getX(), location.getZ())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private WrappedRegion toRegion(ProtectedRegion region) {
|
private WrappedRegion toRegion(World world, ProtectedRegion region) {
|
||||||
return new WrappedRegion() {
|
if (region instanceof ProtectedPolygonalRegion) {
|
||||||
|
return new WrappedPolygonalRegion() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public Location getMinimumPoint() {
|
||||||
return region.getId();
|
return fromBlockVector(world, region.getMinimumPoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getFlags() {
|
public Location getMaximumPoint() {
|
||||||
Map<String, Object> map = new HashMap<>();
|
return fromBlockVector(world, region.getMaximumPoint());
|
||||||
region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value));
|
}
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Object> getFlag(String name) {
|
public Set<Location> getPoints() {
|
||||||
return Optional.ofNullable(flagRegistry.get(name))
|
return region.getPoints().stream()
|
||||||
.map(region::getFlag);
|
.map(vector -> new BlockVector(vector.toVector()))
|
||||||
}
|
.map(vector -> fromBlockVector(world, vector))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPriority() {
|
public String getId() {
|
||||||
return region.getPriority();
|
return region.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Location location) {
|
public Map<String, Object> getFlags() {
|
||||||
return region.contains(toBlockVector(location));
|
Map<String, Object> map = new HashMap<>();
|
||||||
}
|
region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
@Override
|
||||||
|
public Optional<Object> getFlag(String name) {
|
||||||
|
return Optional.ofNullable(flagRegistry.get(name))
|
||||||
|
.map(region::getFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return region.getPriority();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Location location) {
|
||||||
|
return region.contains(toBlockVector(location));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return new WrappedRegion() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getMinimumPoint() {
|
||||||
|
return fromBlockVector(world, region.getMinimumPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getMaximumPoint() {
|
||||||
|
return fromBlockVector(world, region.getMaximumPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return region.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getFlags() {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Object> getFlag(String name) {
|
||||||
|
return Optional.ofNullable(flagRegistry.get(name))
|
||||||
|
.map(region::getFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return region.getPriority();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Location location) {
|
||||||
|
return region.contains(toBlockVector(location));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -170,7 +242,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<WrappedRegion> getRegion(World world, String id) {
|
public Optional<WrappedRegion> getRegion(World world, String id) {
|
||||||
return getWorldManager(world).map(regionManager -> toRegion(regionManager.getRegion(id)));
|
return getWorldManager(world).map(regionManager -> toRegion(world, regionManager.getRegion(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -179,7 +251,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
Map<String, ProtectedRegion> regions = regionManager.getRegions();
|
Map<String, ProtectedRegion> regions = regionManager.getRegions();
|
||||||
|
|
||||||
Map<String, WrappedRegion> map = new HashMap<>();
|
Map<String, WrappedRegion> map = new HashMap<>();
|
||||||
regions.forEach((name, region) -> map.put(name, toRegion(region)));
|
regions.forEach((name, region) -> map.put(name, toRegion(world, region)));
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -193,23 +265,37 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
regionSet.forEach(region -> set.add(toRegion(region)));
|
regionSet.forEach(region -> set.add(toRegion(location.getWorld(), region)));
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<WrappedRegion> getRegions(Location minimum, Location maximum) {
|
||||||
|
ApplicableRegionSet regionSet = getApplicableRegions(minimum, maximum).orElse(null);
|
||||||
|
Set<WrappedRegion> set = new HashSet<>();
|
||||||
|
|
||||||
|
if (regionSet == null) {
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
regionSet.forEach(region -> set.add(toRegion(minimum.getWorld(), region)));
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<WrappedRegion> addRegion(String id, List<Location> points, int minY, int maxY) {
|
public Optional<WrappedRegion> addRegion(String id, List<Location> points, int minY, int maxY) {
|
||||||
ProtectedRegion region;
|
ProtectedRegion region;
|
||||||
|
World world = points.get(0).getWorld();
|
||||||
if (points.size() == 2) {
|
if (points.size() == 2) {
|
||||||
region = new ProtectedCuboidRegion(id, toBlockVector(points.get(0)), toBlockVector(points.get(1)));
|
region = new ProtectedCuboidRegion(id, toBlockVector(points.get(0)), toBlockVector(points.get(1)));
|
||||||
} else {
|
} else {
|
||||||
region = new ProtectedPolygonalRegion(id, toBlockVector2DList(points), minY, maxY);
|
region = new ProtectedPolygonalRegion(id, toBlockVector2DList(points), minY, maxY);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<RegionManager> manager = getWorldManager(points.get(0).getWorld());
|
Optional<RegionManager> manager = getWorldManager(world);
|
||||||
if (manager.isPresent()) {
|
if (manager.isPresent()) {
|
||||||
manager.get().addRegion(region);
|
manager.get().addRegion(region);
|
||||||
return Optional.of(toRegion(region));
|
return Optional.of(toRegion(world, region));
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
@ -218,11 +304,8 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
@Override
|
@Override
|
||||||
public Optional<Set<WrappedRegion>> removeRegion(World world, String id) {
|
public Optional<Set<WrappedRegion>> removeRegion(World world, String id) {
|
||||||
Optional<Set<ProtectedRegion>> set = getWorldManager(world).map(manager -> manager.removeRegion(id));
|
Optional<Set<ProtectedRegion>> set = getWorldManager(world).map(manager -> manager.removeRegion(id));
|
||||||
if (set.isPresent()) {
|
return set.map(protectedRegions -> protectedRegions.stream().map(region -> toRegion(world, region))
|
||||||
return Optional.of(set.get().stream().map(region -> toRegion(region)).collect(Collectors.toSet()));
|
.collect(Collectors.toSet()));
|
||||||
} else {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
|
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||||
|
import org.codemc.worldguardwrapper.region.WrappedPolygonalRegion;
|
||||||
import org.codemc.worldguardwrapper.region.WrappedRegion;
|
import org.codemc.worldguardwrapper.region.WrappedRegion;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -58,46 +59,113 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(BukkitAdapter.asBlockVector(location)));
|
return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(BukkitAdapter.asBlockVector(location)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location minimum, @NonNull Location maximum) {
|
||||||
|
return getWorldManager(minimum.getWorld()).map(manager -> manager.getApplicableRegions(
|
||||||
|
new ProtectedCuboidRegion("temp", BukkitAdapter.asBlockVector(minimum), BukkitAdapter.asBlockVector(maximum))));
|
||||||
|
}
|
||||||
|
|
||||||
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
|
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
|
||||||
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player).orElse(null), flag));
|
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player)
|
||||||
|
.orElse(null), flag));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<StateFlag.State> queryState(Player player, @NonNull Location location, @NonNull StateFlag... stateFlags) {
|
private Optional<StateFlag.State> queryState(Player player, @NonNull Location location, @NonNull StateFlag... stateFlags) {
|
||||||
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryState(wrapPlayer(player).orElse(null), stateFlags));
|
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryState(wrapPlayer(player)
|
||||||
|
.orElse(null), stateFlags));
|
||||||
}
|
}
|
||||||
|
|
||||||
private WrappedRegion toRegion(ProtectedRegion region) {
|
private WrappedRegion toRegion(World world, ProtectedRegion region) {
|
||||||
return new WrappedRegion() {
|
if (region instanceof ProtectedPolygonalRegion) {
|
||||||
|
return new WrappedPolygonalRegion() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public Location getMinimumPoint() {
|
||||||
return region.getId();
|
return BukkitAdapter.adapt(world, region.getMinimumPoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getFlags() {
|
public Location getMaximumPoint() {
|
||||||
Map<String, Object> map = new HashMap<>();
|
return BukkitAdapter.adapt(world, region.getMaximumPoint());
|
||||||
region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value));
|
}
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Object> getFlag(String name) {
|
public Set<Location> getPoints() {
|
||||||
return Optional.ofNullable(flagRegistry.get(name))
|
return region.getPoints().stream()
|
||||||
.map(region::getFlag);
|
.map(BlockVector2::toBlockVector3)
|
||||||
}
|
.map(vector -> BukkitAdapter.adapt(world, vector))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPriority() {
|
public String getId() {
|
||||||
return region.getPriority();
|
return region.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Location location) {
|
public Map<String, Object> getFlags() {
|
||||||
return region.contains(BukkitAdapter.asBlockVector(location));
|
Map<String, Object> map = new HashMap<>();
|
||||||
}
|
region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
@Override
|
||||||
|
public Optional<Object> getFlag(String name) {
|
||||||
|
return Optional.ofNullable(flagRegistry.get(name))
|
||||||
|
.map(region::getFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return region.getPriority();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Location location) {
|
||||||
|
return region.contains(BukkitAdapter.asBlockVector(location));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return new WrappedRegion() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getMinimumPoint() {
|
||||||
|
return BukkitAdapter.adapt(world, region.getMinimumPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getMaximumPoint() {
|
||||||
|
return BukkitAdapter.adapt(world, region.getMaximumPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return region.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getFlags() {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Object> getFlag(String name) {
|
||||||
|
return Optional.ofNullable(flagRegistry.get(name))
|
||||||
|
.map(region::getFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return region.getPriority();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Location location) {
|
||||||
|
return region.contains(BukkitAdapter.asBlockVector(location));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -176,7 +244,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
public Optional<WrappedRegion> getRegion(World world, String id) {
|
public Optional<WrappedRegion> getRegion(World world, String id) {
|
||||||
return getWorldManager(world)
|
return getWorldManager(world)
|
||||||
.map(regionManager -> regionManager.getRegion(id))
|
.map(regionManager -> regionManager.getRegion(id))
|
||||||
.map(this::toRegion);
|
.map(region -> toRegion(world, region));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -188,7 +256,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
|
|
||||||
Map<String, ProtectedRegion> regions = regionManager.getRegions();
|
Map<String, ProtectedRegion> regions = regionManager.getRegions();
|
||||||
Map<String, WrappedRegion> map = new HashMap<>();
|
Map<String, WrappedRegion> map = new HashMap<>();
|
||||||
regions.forEach((name, region) -> map.put(name, toRegion(region)));
|
regions.forEach((name, region) -> map.put(name, toRegion(world, region)));
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,15 +268,29 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
}
|
}
|
||||||
|
|
||||||
return regionSet.getRegions().stream()
|
return regionSet.getRegions().stream()
|
||||||
.map(this::toRegion)
|
.map(region -> toRegion(location.getWorld(), region))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<WrappedRegion> getRegions(Location minimum, Location maximum) {
|
||||||
|
ApplicableRegionSet regionSet = getApplicableRegions(minimum, maximum).orElse(null);
|
||||||
|
if (regionSet == null) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
return regionSet.getRegions().stream()
|
||||||
|
.map(region -> toRegion(minimum.getWorld(), region))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<WrappedRegion> addRegion(String id, List<Location> points, int minY, int maxY) {
|
public Optional<WrappedRegion> addRegion(String id, List<Location> points, int minY, int maxY) {
|
||||||
ProtectedRegion region;
|
ProtectedRegion region;
|
||||||
|
World world = points.get(0).getWorld();
|
||||||
if (points.size() == 2) {
|
if (points.size() == 2) {
|
||||||
region = new ProtectedCuboidRegion(id, BukkitAdapter.asBlockVector(points.get(0)), BukkitAdapter.asBlockVector(points.get(1)));
|
region = new ProtectedCuboidRegion(id, BukkitAdapter.asBlockVector(points.get(0)),
|
||||||
|
BukkitAdapter.asBlockVector(points.get(1)));
|
||||||
} else {
|
} else {
|
||||||
List<BlockVector2> vectorPoints = points.stream()
|
List<BlockVector2> vectorPoints = points.stream()
|
||||||
.map(location -> BukkitAdapter.asBlockVector(location).toBlockVector2())
|
.map(location -> BukkitAdapter.asBlockVector(location).toBlockVector2())
|
||||||
|
@ -217,10 +299,10 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
region = new ProtectedPolygonalRegion(id, vectorPoints, minY, maxY);
|
region = new ProtectedPolygonalRegion(id, vectorPoints, minY, maxY);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<RegionManager> manager = getWorldManager(points.get(0).getWorld());
|
Optional<RegionManager> manager = getWorldManager(world);
|
||||||
if (manager.isPresent()) {
|
if (manager.isPresent()) {
|
||||||
manager.get().addRegion(region);
|
manager.get().addRegion(region);
|
||||||
return Optional.of(toRegion(region));
|
return Optional.of(toRegion(world, region));
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
@ -229,6 +311,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
@Override
|
@Override
|
||||||
public Optional<Set<WrappedRegion>> removeRegion(World world, String id) {
|
public Optional<Set<WrappedRegion>> removeRegion(World world, String id) {
|
||||||
Optional<Set<ProtectedRegion>> set = getWorldManager(world).map(manager -> manager.removeRegion(id));
|
Optional<Set<ProtectedRegion>> set = getWorldManager(world).map(manager -> manager.removeRegion(id));
|
||||||
return set.map(protectedRegions -> protectedRegions.stream().map(this::toRegion).collect(Collectors.toSet()));
|
return set.map(protectedRegions -> protectedRegions.stream()
|
||||||
|
.map(region -> toRegion(world, region)).collect(Collectors.toSet()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user