From 19ef34bd0f072393d6205490c2b4d476997dfaa6 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Thu, 22 Nov 2018 15:18:33 +0100 Subject: [PATCH] Enhance the region area/selection api, add region owner/members getters --- .../region/WrappedPolygonalRegion.java | 11 -- .../region/WrappedRegion.java | 10 +- .../selection/CuboidSelection.java | 11 ++ .../selection/PolygonalSelection.java | 15 ++ .../selection/Selection.java | 4 + .../v6/WorldGuardImplementation.java | 145 ++++++++---------- .../v7/WorldGuardImplementation.java | 145 ++++++++---------- 7 files changed, 171 insertions(+), 170 deletions(-) delete mode 100644 api/src/main/java/org/codemc/worldguardwrapper/region/WrappedPolygonalRegion.java create mode 100644 api/src/main/java/org/codemc/worldguardwrapper/selection/CuboidSelection.java create mode 100644 api/src/main/java/org/codemc/worldguardwrapper/selection/PolygonalSelection.java create mode 100644 api/src/main/java/org/codemc/worldguardwrapper/selection/Selection.java diff --git a/api/src/main/java/org/codemc/worldguardwrapper/region/WrappedPolygonalRegion.java b/api/src/main/java/org/codemc/worldguardwrapper/region/WrappedPolygonalRegion.java deleted file mode 100644 index 5d4389b..0000000 --- a/api/src/main/java/org/codemc/worldguardwrapper/region/WrappedPolygonalRegion.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.codemc.worldguardwrapper.region; - -import org.bukkit.Location; - -import java.util.Set; - -public interface WrappedPolygonalRegion extends WrappedRegion { - - Set getPoints(); - -} diff --git a/api/src/main/java/org/codemc/worldguardwrapper/region/WrappedRegion.java b/api/src/main/java/org/codemc/worldguardwrapper/region/WrappedRegion.java index b242e77..299b420 100644 --- a/api/src/main/java/org/codemc/worldguardwrapper/region/WrappedRegion.java +++ b/api/src/main/java/org/codemc/worldguardwrapper/region/WrappedRegion.java @@ -1,16 +1,16 @@ package org.codemc.worldguardwrapper.region; import org.bukkit.Location; +import org.codemc.worldguardwrapper.selection.Selection; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.UUID; public interface WrappedRegion { - Location getMinimumPoint(); - - Location getMaximumPoint(); + Selection getSelection(); String getId(); @@ -20,6 +20,10 @@ public interface WrappedRegion { int getPriority(); + Set getOwners(); + + Set getMembers(); + boolean contains(Location location); } diff --git a/api/src/main/java/org/codemc/worldguardwrapper/selection/CuboidSelection.java b/api/src/main/java/org/codemc/worldguardwrapper/selection/CuboidSelection.java new file mode 100644 index 0000000..384af0c --- /dev/null +++ b/api/src/main/java/org/codemc/worldguardwrapper/selection/CuboidSelection.java @@ -0,0 +1,11 @@ +package org.codemc.worldguardwrapper.selection; + +import org.bukkit.Location; + +public interface CuboidSelection extends Selection { + + Location getMinimumPoint(); + + Location getMaximumPoint(); + +} diff --git a/api/src/main/java/org/codemc/worldguardwrapper/selection/PolygonalSelection.java b/api/src/main/java/org/codemc/worldguardwrapper/selection/PolygonalSelection.java new file mode 100644 index 0000000..29a2192 --- /dev/null +++ b/api/src/main/java/org/codemc/worldguardwrapper/selection/PolygonalSelection.java @@ -0,0 +1,15 @@ +package org.codemc.worldguardwrapper.selection; + +import org.bukkit.Location; + +import java.util.Set; + +public interface PolygonalSelection extends Selection { + + Set getPoints(); + + int getMinimumY(); + + int getMaximumY(); + +} diff --git a/api/src/main/java/org/codemc/worldguardwrapper/selection/Selection.java b/api/src/main/java/org/codemc/worldguardwrapper/selection/Selection.java new file mode 100644 index 0000000..fc7b2f0 --- /dev/null +++ b/api/src/main/java/org/codemc/worldguardwrapper/selection/Selection.java @@ -0,0 +1,4 @@ +package org.codemc.worldguardwrapper.selection; + +public interface Selection { +} diff --git a/implementation/v6/src/main/java/org/codemc/worldguardwrapper/implementation/v6/WorldGuardImplementation.java b/implementation/v6/src/main/java/org/codemc/worldguardwrapper/implementation/v6/WorldGuardImplementation.java index 1e6e81c..573c648 100644 --- a/implementation/v6/src/main/java/org/codemc/worldguardwrapper/implementation/v6/WorldGuardImplementation.java +++ b/implementation/v6/src/main/java/org/codemc/worldguardwrapper/implementation/v6/WorldGuardImplementation.java @@ -23,7 +23,9 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag; import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation; -import org.codemc.worldguardwrapper.region.WrappedPolygonalRegion; +import org.codemc.worldguardwrapper.selection.CuboidSelection; +import org.codemc.worldguardwrapper.selection.PolygonalSelection; +import org.codemc.worldguardwrapper.selection.Selection; import org.codemc.worldguardwrapper.region.WrappedRegion; import java.util.*; @@ -75,97 +77,84 @@ public class WorldGuardImplementation implements IWorldGuardImplementation { } private WrappedRegion toRegion(World world, ProtectedRegion region) { - if (region instanceof ProtectedPolygonalRegion) { - return new WrappedPolygonalRegion() { + return new WrappedRegion() { - @Override - public Location getMinimumPoint() { - return fromBlockVector(world, region.getMinimumPoint()); - } + @Override + public Selection getSelection() { + if (region instanceof PolygonalSelection) { + return new PolygonalSelection() { - @Override - public Location getMaximumPoint() { - return fromBlockVector(world, region.getMaximumPoint()); - } + @Override + public Set getPoints() { + return region.getPoints().stream() + .map(vector -> new BlockVector(vector.toVector())) + .map(vector -> fromBlockVector(world, vector)) + .collect(Collectors.toSet()); + } - @Override - public Set getPoints() { - return region.getPoints().stream() - .map(vector -> new BlockVector(vector.toVector())) - .map(vector -> fromBlockVector(world, vector)) - .collect(Collectors.toSet()); - } + @Override + public int getMinimumY() { + return ((PolygonalSelection) region).getMinimumY(); + } - @Override - public String getId() { - return region.getId(); + @Override + public int getMaximumY() { + return ((PolygonalSelection) region).getMaximumY(); + } + }; } + return new CuboidSelection() { - @Override - public Map getFlags() { - Map map = new HashMap<>(); - region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value)); - return map; - } + @Override + public Location getMinimumPoint() { + return fromBlockVector(world, region.getMinimumPoint()); + } - @Override - public Optional getFlag(String name) { - return Optional.ofNullable(flagRegistry.get(name)) - .map(region::getFlag); - } + @Override + public Location getMaximumPoint() { + return fromBlockVector(world, region.getMaximumPoint()); + } + }; + } - @Override - public int getPriority() { - return region.getPriority(); - } + @Override + public String getId() { + return region.getId(); + } - @Override - public boolean contains(Location location) { - return region.contains(toBlockVector(location)); - } - }; - } else { - return new WrappedRegion() { + @Override + public Map getFlags() { + Map map = new HashMap<>(); + region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value)); + return map; + } - @Override - public Location getMinimumPoint() { - return fromBlockVector(world, region.getMinimumPoint()); - } + @Override + public Optional getFlag(String name) { + return Optional.ofNullable(flagRegistry.get(name)) + .map(region::getFlag); + } - @Override - public Location getMaximumPoint() { - return fromBlockVector(world, region.getMaximumPoint()); - } + @Override + public int getPriority() { + return region.getPriority(); + } - @Override - public String getId() { - return region.getId(); - } + @Override + public Set getOwners() { + return region.getOwners().getUniqueIds(); + } - @Override - public Map getFlags() { - Map map = new HashMap<>(); - region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value)); - return map; - } + @Override + public Set getMembers() { + return region.getMembers().getUniqueIds(); + } - @Override - public Optional 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 + public boolean contains(Location location) { + return region.contains(toBlockVector(location)); + } + }; } @Override diff --git a/implementation/v7/src/main/java/org/codemc/worldguardwrapper/implementation/v7/WorldGuardImplementation.java b/implementation/v7/src/main/java/org/codemc/worldguardwrapper/implementation/v7/WorldGuardImplementation.java index a7b2e42..5eb7033 100644 --- a/implementation/v7/src/main/java/org/codemc/worldguardwrapper/implementation/v7/WorldGuardImplementation.java +++ b/implementation/v7/src/main/java/org/codemc/worldguardwrapper/implementation/v7/WorldGuardImplementation.java @@ -25,8 +25,10 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag; import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation; -import org.codemc.worldguardwrapper.region.WrappedPolygonalRegion; import org.codemc.worldguardwrapper.region.WrappedRegion; +import org.codemc.worldguardwrapper.selection.CuboidSelection; +import org.codemc.worldguardwrapper.selection.PolygonalSelection; +import org.codemc.worldguardwrapper.selection.Selection; import java.util.*; import java.util.stream.Collectors; @@ -75,97 +77,84 @@ public class WorldGuardImplementation implements IWorldGuardImplementation { } private WrappedRegion toRegion(World world, ProtectedRegion region) { - if (region instanceof ProtectedPolygonalRegion) { - return new WrappedPolygonalRegion() { + return new WrappedRegion() { - @Override - public Location getMinimumPoint() { - return BukkitAdapter.adapt(world, region.getMinimumPoint()); - } + @Override + public Selection getSelection() { + if (region instanceof PolygonalSelection) { + return new PolygonalSelection() { - @Override - public Location getMaximumPoint() { - return BukkitAdapter.adapt(world, region.getMaximumPoint()); - } + @Override + public Set getPoints() { + return region.getPoints().stream() + .map(BlockVector2::toBlockVector3) + .map(vector -> BukkitAdapter.adapt(world, vector)) + .collect(Collectors.toSet()); + } - @Override - public Set getPoints() { - return region.getPoints().stream() - .map(BlockVector2::toBlockVector3) - .map(vector -> BukkitAdapter.adapt(world, vector)) - .collect(Collectors.toSet()); - } + @Override + public int getMinimumY() { + return ((PolygonalSelection) region).getMinimumY(); + } - @Override - public String getId() { - return region.getId(); + @Override + public int getMaximumY() { + return ((PolygonalSelection) region).getMaximumY(); + } + }; } + return new CuboidSelection() { - @Override - public Map getFlags() { - Map map = new HashMap<>(); - region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value)); - return map; - } + @Override + public Location getMinimumPoint() { + return BukkitAdapter.adapt(world, region.getMinimumPoint()); + } - @Override - public Optional getFlag(String name) { - return Optional.ofNullable(flagRegistry.get(name)) - .map(region::getFlag); - } + @Override + public Location getMaximumPoint() { + return BukkitAdapter.adapt(world, region.getMaximumPoint()); + } + }; + } - @Override - public int getPriority() { - return region.getPriority(); - } + @Override + public String getId() { + return region.getId(); + } - @Override - public boolean contains(Location location) { - return region.contains(BukkitAdapter.asBlockVector(location)); - } - }; - } else { - return new WrappedRegion() { + @Override + public Map getFlags() { + Map map = new HashMap<>(); + region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value)); + return map; + } - @Override - public Location getMinimumPoint() { - return BukkitAdapter.adapt(world, region.getMinimumPoint()); - } + @Override + public Optional getFlag(String name) { + return Optional.ofNullable(flagRegistry.get(name)) + .map(region::getFlag); + } - @Override - public Location getMaximumPoint() { - return BukkitAdapter.adapt(world, region.getMaximumPoint()); - } + @Override + public int getPriority() { + return region.getPriority(); + } - @Override - public String getId() { - return region.getId(); - } + @Override + public Set getOwners() { + return region.getOwners().getUniqueIds(); + } - @Override - public Map getFlags() { - Map map = new HashMap<>(); - region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value)); - return map; - } + @Override + public Set getMembers() { + return region.getMembers().getUniqueIds(); + } - @Override - public Optional 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 + public boolean contains(Location location) { + return region.contains(BukkitAdapter.asBlockVector(location)); + } + }; } @Override