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 java.util.List;
import java.util.Set;
@SuppressWarnings("unused")
public interface IPolygonalSelection extends ISelection {
Set<Location> getPoints();
List<Location> getPoints();
int getMinimumY();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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