getPoints returns no longer a Set but a List to maintains object order but removing dupicates (distinct)

This commit is contained in:
webadmin 2024-04-19 15:30:09 +02:00
parent 900e0a5017
commit 70aa8186e2
No known key found for this signature in database
GPG Key ID: 273E77110F9C224B
8 changed files with 25 additions and 18 deletions

View File

@ -2,12 +2,13 @@ package org.codemc.worldguardwrapper.selection;
import org.bukkit.Location; import org.bukkit.Location;
import java.util.List;
import java.util.Set; import java.util.Set;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public interface IPolygonalSelection extends ISelection { public interface IPolygonalSelection extends ISelection {
Set<Location> getPoints(); List<Location> getPoints();
int getMinimumY(); int getMinimumY();

View File

@ -5,9 +5,8 @@ import org.bukkit.Location;
import org.codemc.worldguardwrapper.selection.ICuboidSelection; import org.codemc.worldguardwrapper.selection.ICuboidSelection;
import org.codemc.worldguardwrapper.selection.IPolygonalSelection; import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
import java.util.Collection; import java.util.*;
import java.util.HashSet; import java.util.stream.Collectors;
import java.util.Set;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@UtilityClass @UtilityClass
@ -54,8 +53,9 @@ public class SelectionUtilities {
public IPolygonalSelection createPolygonalSelection(Collection<Location> points, int minY, int maxY) { public IPolygonalSelection createPolygonalSelection(Collection<Location> points, int minY, int maxY) {
return new IPolygonalSelection() { return new IPolygonalSelection() {
@Override @Override
public Set<Location> getPoints() { public List<Location> getPoints() {
return new HashSet<>(points); //recoreHosting -> set to list , maintains order but remove duplicates
return new ArrayList<>(points).stream().distinct().collect(Collectors.toList());
} }
@Override @Override

View File

@ -314,8 +314,9 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
} else if (selection instanceof Polygonal2DSelection) { } else if (selection instanceof Polygonal2DSelection) {
return new IPolygonalSelection() { return new IPolygonalSelection() {
@Override @Override
public Set<Location> getPoints() { public List<Location> getPoints() {
return ((Polygonal2DSelection) selection).getNativePoints().stream() return ((Polygonal2DSelection) selection).getNativePoints().stream()
.distinct()
.map(vector -> new BlockVector(vector.toVector())) .map(vector -> new BlockVector(vector.toVector()))
.map(vector -> .map(vector ->
WorldGuardVectorUtilities.fromBlockVector( WorldGuardVectorUtilities.fromBlockVector(
@ -323,7 +324,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
vector vector
) )
) )
.collect(Collectors.toSet()); .collect(Collectors.toList());
} }
@Override @Override

View File

@ -46,11 +46,12 @@ public class WrappedRegion implements IWrappedRegion {
} else if (handle instanceof ProtectedPolygonalRegion) { } else if (handle instanceof ProtectedPolygonalRegion) {
return new IPolygonalSelection() { return new IPolygonalSelection() {
@Override @Override
public Set<Location> getPoints() { public List<Location> getPoints() {
return handle.getPoints().stream() return handle.getPoints().stream()
.distinct()
.map(vector -> new BlockVector(vector.toVector())) .map(vector -> new BlockVector(vector.toVector()))
.map(vector -> WorldGuardVectorUtilities.fromBlockVector(world, vector)) .map(vector -> WorldGuardVectorUtilities.fromBlockVector(world, vector))
.collect(Collectors.toSet()); .collect(Collectors.toList());
} }
@Override @Override

View File

@ -381,8 +381,9 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
} else if (selection instanceof Polygonal2DSelection) { } else if (selection instanceof Polygonal2DSelection) {
return new IPolygonalSelection() { return new IPolygonalSelection() {
@Override @Override
public Set<Location> getPoints() { public List<Location> getPoints() {
return ((Polygonal2DSelection) selection).getNativePoints().stream() return ((Polygonal2DSelection) selection).getNativePoints().stream()
.distinct()
.map(vector -> new BlockVector(vector.toVector())) .map(vector -> new BlockVector(vector.toVector()))
.map(vector -> .map(vector ->
WorldGuardVectorUtilities.fromBlockVector( WorldGuardVectorUtilities.fromBlockVector(
@ -390,7 +391,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
vector vector
) )
) )
.collect(Collectors.toSet()); .collect(Collectors.toList());
} }
@Override @Override

View File

@ -46,11 +46,12 @@ public class WrappedRegion implements IWrappedRegion {
} else if (handle instanceof ProtectedPolygonalRegion) { } else if (handle instanceof ProtectedPolygonalRegion) {
return new IPolygonalSelection() { return new IPolygonalSelection() {
@Override @Override
public Set<Location> getPoints() { public List<Location> getPoints() {
return handle.getPoints().stream() return handle.getPoints().stream()
.distinct()
.map(vector -> new BlockVector(vector.toVector())) .map(vector -> new BlockVector(vector.toVector()))
.map(vector -> WorldGuardVectorUtilities.fromBlockVector(world, vector)) .map(vector -> WorldGuardVectorUtilities.fromBlockVector(world, vector))
.collect(Collectors.toSet()); .collect(Collectors.toList());
} }
@Override @Override

View File

@ -383,11 +383,12 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
} else if (selection instanceof Polygonal2DRegion) { } else if (selection instanceof Polygonal2DRegion) {
return new IPolygonalSelection() { return new IPolygonalSelection() {
@Override @Override
public Set<Location> getPoints() { public List<Location> getPoints() {
return ((Polygonal2DRegion) selection).getPoints().stream() return ((Polygonal2DRegion) selection).getPoints().stream()
.distinct()
.map(BlockVector2::toBlockVector3) .map(BlockVector2::toBlockVector3)
.map(vector -> BukkitAdapter.adapt(world, vector)) .map(vector -> BukkitAdapter.adapt(world, vector))
.collect(Collectors.toSet()); .collect(Collectors.toList());
} }
@Override @Override

View File

@ -46,11 +46,12 @@ public class WrappedRegion implements IWrappedRegion {
} else if (handle instanceof ProtectedPolygonalRegion) { } else if (handle instanceof ProtectedPolygonalRegion) {
return new IPolygonalSelection() { return new IPolygonalSelection() {
@Override @Override
public Set<Location> getPoints() { public List<Location> getPoints() {
return handle.getPoints().stream() return handle.getPoints().stream()
.distinct()
.map(BlockVector2::toBlockVector3) .map(BlockVector2::toBlockVector3)
.map(vector -> BukkitAdapter.adapt(world, vector)) .map(vector -> BukkitAdapter.adapt(world, vector))
.collect(Collectors.toSet()); .collect(Collectors.toList());
} }
@Override @Override