mirror of
https://github.com/CodeMC/WorldGuardWrapper.git
synced 2024-11-10 05:05:20 +01:00
Enhance the region area/selection api, add region owner/members getters
This commit is contained in:
parent
946809ebad
commit
19ef34bd0f
|
@ -1,11 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.region;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface WrappedPolygonalRegion extends WrappedRegion {
|
||||
|
||||
Set<Location> getPoints();
|
||||
|
||||
}
|
|
@ -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<UUID> getOwners();
|
||||
|
||||
Set<UUID> getMembers();
|
||||
|
||||
boolean contains(Location location);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package org.codemc.worldguardwrapper.selection;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public interface CuboidSelection extends Selection {
|
||||
|
||||
Location getMinimumPoint();
|
||||
|
||||
Location getMaximumPoint();
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.codemc.worldguardwrapper.selection;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface PolygonalSelection extends Selection {
|
||||
|
||||
Set<Location> getPoints();
|
||||
|
||||
int getMinimumY();
|
||||
|
||||
int getMaximumY();
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package org.codemc.worldguardwrapper.selection;
|
||||
|
||||
public interface Selection {
|
||||
}
|
|
@ -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<Location> getPoints() {
|
||||
return region.getPoints().stream()
|
||||
.map(vector -> new BlockVector(vector.toVector()))
|
||||
.map(vector -> fromBlockVector(world, vector))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Location> 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<String, Object> getFlags() {
|
||||
Map<String, Object> 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<Object> 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<String, Object> getFlags() {
|
||||
Map<String, Object> 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<Object> 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<UUID> getOwners() {
|
||||
return region.getOwners().getUniqueIds();
|
||||
}
|
||||
|
||||
@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 Set<UUID> getMembers() {
|
||||
return region.getMembers().getUniqueIds();
|
||||
}
|
||||
|
||||
@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
|
||||
public boolean contains(Location location) {
|
||||
return region.contains(toBlockVector(location));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<Location> getPoints() {
|
||||
return region.getPoints().stream()
|
||||
.map(BlockVector2::toBlockVector3)
|
||||
.map(vector -> BukkitAdapter.adapt(world, vector))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Location> 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<String, Object> getFlags() {
|
||||
Map<String, Object> 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<Object> 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<String, Object> getFlags() {
|
||||
Map<String, Object> 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<Object> 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<UUID> getOwners() {
|
||||
return region.getOwners().getUniqueIds();
|
||||
}
|
||||
|
||||
@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 Set<UUID> getMembers() {
|
||||
return region.getMembers().getUniqueIds();
|
||||
}
|
||||
|
||||
@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
|
||||
public boolean contains(Location location) {
|
||||
return region.contains(BukkitAdapter.asBlockVector(location));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue
Block a user