Files
LogBlock/src/main/java/de/diddiz/worldedit/RegionContainer.java
T

61 lines
2.1 KiB
Java
Raw Normal View History

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;
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;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class RegionContainer {
2018-07-21 15:51:16 +02:00
private Region selection;
2018-07-21 15:51:16 +02:00
public RegionContainer(Region sel) {
2015-03-22 20:15:04 +05:00
this.selection = sel;
}
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);
}
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
}
2018-07-21 15:51:16 +02:00
public Region getSelection() {
2015-03-22 20:15:04 +05:00
return selection;
}
2018-07-21 15:51:16 +02:00
public void setSelection(Region selection) {
2015-03-22 20:15:04 +05:00
this.selection = selection;
}
}