Enhance the region area/selection api, add region owner/members getters

This commit is contained in:
Gabriele C 2018-11-22 15:18:33 +01:00
parent 946809ebad
commit 19ef34bd0f
7 changed files with 171 additions and 170 deletions

View File

@ -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();
}

View File

@ -1,16 +1,16 @@
package org.codemc.worldguardwrapper.region; package org.codemc.worldguardwrapper.region;
import org.bukkit.Location; import org.bukkit.Location;
import org.codemc.worldguardwrapper.selection.Selection;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID;
public interface WrappedRegion { public interface WrappedRegion {
Location getMinimumPoint(); Selection getSelection();
Location getMaximumPoint();
String getId(); String getId();
@ -20,6 +20,10 @@ public interface WrappedRegion {
int getPriority(); int getPriority();
Set<UUID> getOwners();
Set<UUID> getMembers();
boolean contains(Location location); boolean contains(Location location);
} }

View File

@ -0,0 +1,11 @@
package org.codemc.worldguardwrapper.selection;
import org.bukkit.Location;
public interface CuboidSelection extends Selection {
Location getMinimumPoint();
Location getMaximumPoint();
}

View File

@ -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();
}

View File

@ -0,0 +1,4 @@
package org.codemc.worldguardwrapper.selection;
public interface Selection {
}

View File

@ -23,7 +23,9 @@ 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.selection.CuboidSelection;
import org.codemc.worldguardwrapper.selection.PolygonalSelection;
import org.codemc.worldguardwrapper.selection.Selection;
import org.codemc.worldguardwrapper.region.WrappedRegion; import org.codemc.worldguardwrapper.region.WrappedRegion;
import java.util.*; import java.util.*;
@ -75,18 +77,12 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
} }
private WrappedRegion toRegion(World world, ProtectedRegion region) { private WrappedRegion toRegion(World world, ProtectedRegion region) {
if (region instanceof ProtectedPolygonalRegion) { return new WrappedRegion() {
return new WrappedPolygonalRegion() {
@Override @Override
public Location getMinimumPoint() { public Selection getSelection() {
return fromBlockVector(world, region.getMinimumPoint()); if (region instanceof PolygonalSelection) {
} return new PolygonalSelection() {
@Override
public Location getMaximumPoint() {
return fromBlockVector(world, region.getMaximumPoint());
}
@Override @Override
public Set<Location> getPoints() { public Set<Location> getPoints() {
@ -97,35 +93,17 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
} }
@Override @Override
public String getId() { public int getMinimumY() {
return region.getId(); return ((PolygonalSelection) region).getMinimumY();
} }
@Override @Override
public Map<String, Object> getFlags() { public int getMaximumY() {
Map<String, Object> map = new HashMap<>(); return ((PolygonalSelection) region).getMaximumY();
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() { return new CuboidSelection() {
@Override @Override
public Location getMinimumPoint() { public Location getMinimumPoint() {
@ -136,6 +114,8 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
public Location getMaximumPoint() { public Location getMaximumPoint() {
return fromBlockVector(world, region.getMaximumPoint()); return fromBlockVector(world, region.getMaximumPoint());
} }
};
}
@Override @Override
public String getId() { public String getId() {
@ -160,13 +140,22 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
return region.getPriority(); return region.getPriority();
} }
@Override
public Set<UUID> getOwners() {
return region.getOwners().getUniqueIds();
}
@Override
public Set<UUID> getMembers() {
return region.getMembers().getUniqueIds();
}
@Override @Override
public boolean contains(Location location) { public boolean contains(Location location) {
return region.contains(toBlockVector(location)); return region.contains(toBlockVector(location));
} }
}; };
} }
}
@Override @Override
public JavaPlugin getWorldGuardPlugin() { public JavaPlugin getWorldGuardPlugin() {

View File

@ -25,8 +25,10 @@ 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 org.codemc.worldguardwrapper.selection.CuboidSelection;
import org.codemc.worldguardwrapper.selection.PolygonalSelection;
import org.codemc.worldguardwrapper.selection.Selection;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -75,18 +77,12 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
} }
private WrappedRegion toRegion(World world, ProtectedRegion region) { private WrappedRegion toRegion(World world, ProtectedRegion region) {
if (region instanceof ProtectedPolygonalRegion) { return new WrappedRegion() {
return new WrappedPolygonalRegion() {
@Override @Override
public Location getMinimumPoint() { public Selection getSelection() {
return BukkitAdapter.adapt(world, region.getMinimumPoint()); if (region instanceof PolygonalSelection) {
} return new PolygonalSelection() {
@Override
public Location getMaximumPoint() {
return BukkitAdapter.adapt(world, region.getMaximumPoint());
}
@Override @Override
public Set<Location> getPoints() { public Set<Location> getPoints() {
@ -97,35 +93,17 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
} }
@Override @Override
public String getId() { public int getMinimumY() {
return region.getId(); return ((PolygonalSelection) region).getMinimumY();
} }
@Override @Override
public Map<String, Object> getFlags() { public int getMaximumY() {
Map<String, Object> map = new HashMap<>(); return ((PolygonalSelection) region).getMaximumY();
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() { return new CuboidSelection() {
@Override @Override
public Location getMinimumPoint() { public Location getMinimumPoint() {
@ -136,6 +114,8 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
public Location getMaximumPoint() { public Location getMaximumPoint() {
return BukkitAdapter.adapt(world, region.getMaximumPoint()); return BukkitAdapter.adapt(world, region.getMaximumPoint());
} }
};
}
@Override @Override
public String getId() { public String getId() {
@ -160,13 +140,22 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
return region.getPriority(); return region.getPriority();
} }
@Override
public Set<UUID> getOwners() {
return region.getOwners().getUniqueIds();
}
@Override
public Set<UUID> getMembers() {
return region.getMembers().getUniqueIds();
}
@Override @Override
public boolean contains(Location location) { public boolean contains(Location location) {
return region.contains(BukkitAdapter.asBlockVector(location)); return region.contains(BukkitAdapter.asBlockVector(location));
} }
}; };
} }
}
@Override @Override
public JavaPlugin getWorldGuardPlugin() { public JavaPlugin getWorldGuardPlugin() {