2013-01-12 16:00:22 +05:00
|
|
|
package de.diddiz.worldedit;
|
|
|
|
|
|
2018-07-21 15:51:16 +02:00
|
|
|
import com.sk89q.worldedit.IncompleteRegionException;
|
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
|
import com.sk89q.worldedit.Vector;
|
|
|
|
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
2013-01-12 16:00:22 +05:00
|
|
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
2018-07-21 15:51:16 +02:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
|
|
|
|
import com.sk89q.worldedit.regions.Region;
|
|
|
|
|
|
2013-01-12 16:00:22 +05:00
|
|
|
import org.bukkit.Location;
|
|
|
|
|
import org.bukkit.World;
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
|
|
2018-07-31 17:40:14 +02:00
|
|
|
public class RegionContainer implements Cloneable {
|
2013-01-12 16:00:22 +05:00
|
|
|
|
2018-07-21 15:51:16 +02:00
|
|
|
private Region selection;
|
2013-01-12 16:00:22 +05:00
|
|
|
|
2018-07-21 15:51:16 +02:00
|
|
|
public RegionContainer(Region sel) {
|
2015-03-22 20:15:04 +05:00
|
|
|
this.selection = sel;
|
|
|
|
|
}
|
2013-01-12 16:00:22 +05:00
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
public static RegionContainer fromPlayerSelection(Player player, Plugin plugin) {
|
2018-07-21 15:51:16 +02:00
|
|
|
LocalSession session = ((WorldEditPlugin) plugin).getSession(player);
|
|
|
|
|
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(player.getWorld());
|
|
|
|
|
if (!weWorld.equals(session.getSelectionWorld())) {
|
|
|
|
|
throw new IllegalArgumentException("No selection defined");
|
|
|
|
|
}
|
|
|
|
|
Region selection;
|
|
|
|
|
try {
|
|
|
|
|
selection = session.getSelection(weWorld);
|
|
|
|
|
} catch (IncompleteRegionException e) {
|
|
|
|
|
throw new IllegalArgumentException("No selection defined");
|
|
|
|
|
}
|
2015-03-22 20:15:04 +05:00
|
|
|
if (selection == null) {
|
|
|
|
|
throw new IllegalArgumentException("No selection defined");
|
|
|
|
|
}
|
2018-07-21 15:51:16 +02:00
|
|
|
if (!(selection instanceof CuboidRegion)) {
|
2015-03-22 20:15:04 +05:00
|
|
|
throw new IllegalArgumentException("You have to define a cuboid selection");
|
|
|
|
|
}
|
|
|
|
|
return new RegionContainer(selection);
|
|
|
|
|
}
|
2013-01-12 16:00:22 +05:00
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
public static RegionContainer fromCorners(World world, Location first, Location second) {
|
2018-07-21 15:51:16 +02:00
|
|
|
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(world);
|
|
|
|
|
Vector firstVector = BukkitAdapter.asVector(first);
|
|
|
|
|
Vector secondVector = BukkitAdapter.asVector(second);
|
|
|
|
|
|
|
|
|
|
return new RegionContainer(new CuboidRegion(weWorld, firstVector, secondVector));
|
2015-03-22 20:15:04 +05:00
|
|
|
}
|
2013-01-12 16:00:22 +05:00
|
|
|
|
2018-07-21 15:51:16 +02:00
|
|
|
public Region getSelection() {
|
2015-03-22 20:15:04 +05:00
|
|
|
return selection;
|
|
|
|
|
}
|
2013-01-12 16:00:22 +05:00
|
|
|
|
2018-07-21 15:51:16 +02:00
|
|
|
public void setSelection(Region selection) {
|
2015-03-22 20:15:04 +05:00
|
|
|
this.selection = selection;
|
|
|
|
|
}
|
2018-07-31 17:40:14 +02:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RegionContainer clone() {
|
|
|
|
|
try {
|
|
|
|
|
RegionContainer clone = (RegionContainer) super.clone();
|
|
|
|
|
return clone;
|
|
|
|
|
} catch (final CloneNotSupportedException ex) {
|
|
|
|
|
throw new Error("RegionContainer should be cloneable", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-01-12 16:00:22 +05:00
|
|
|
}
|