Added addRegion for a given selection

This commit is contained in:
Eric 2019-05-31 12:18:58 +02:00
parent 74bd9d22b4
commit e3c030602e

View File

@ -7,6 +7,9 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.codemc.worldguardwrapper.flag.IWrappedFlag; import org.codemc.worldguardwrapper.flag.IWrappedFlag;
import org.codemc.worldguardwrapper.region.IWrappedRegion; import org.codemc.worldguardwrapper.region.IWrappedRegion;
import org.codemc.worldguardwrapper.selection.ICuboidSelection;
import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
import org.codemc.worldguardwrapper.selection.ISelection;
import java.util.*; import java.util.*;
@ -128,6 +131,24 @@ public interface IWorldGuardImplementation {
return addRegion(id, Arrays.asList(point1, point2), 0, 0); return addRegion(id, Arrays.asList(point1, point2), 0, 0);
} }
/**
* Add a region for the given selection.
*
* @param id The region ID
* @param selection The selection for the region's volume
* @return The added region
*/
default Optional<IWrappedRegion> addRegion(@NonNull String id, @NonNull ISelection selection) {
if (selection instanceof ICuboidSelection) {
ICuboidSelection sel = (ICuboidSelection) selection;
return addCuboidRegion(id, sel.getMinimumPoint(), sel.getMaximumPoint());
} else if (selection instanceof IPolygonalSelection) {
IPolygonalSelection sel = (IPolygonalSelection) selection;
return addRegion(id, new ArrayList<>(sel.getPoints()), sel.getMinimumY(), sel.getMaximumY());
}
return Optional.empty();
}
/** /**
* Remove a region, including inheriting children. * Remove a region, including inheriting children.
* *