use of com.sk89q.worldedit.LocalSession in project RedProtect by FabioZumbi12.
the class WEListener method pasteWithWE.
public static void pasteWithWE(Player p, File f) throws DataException {
SpongePlayer sp = SpongeWorldEdit.inst().wrapPlayer(p);
SpongeWorld ws = SpongeWorldEdit.inst().getWorld(p.getWorld());
LocalSession session = SpongeWorldEdit.inst().getSession(p);
Closer closer = Closer.create();
try {
ClipboardFormat format = ClipboardFormat.findByAlias("schematic");
FileInputStream fis = closer.register(new FileInputStream(f));
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
ClipboardReader reader = format.getReader(bis);
WorldData worldData = ws.getWorldData();
Clipboard clipboard = reader.read(ws.getWorldData());
session.setClipboard(new ClipboardHolder(clipboard, worldData));
ClipboardHolder holder = session.getClipboard();
Operation op = holder.createPaste(session.createEditSession(sp), ws.getWorldData()).to(session.getPlacementPosition(sp)).build();
Operations.completeLegacy(op);
} catch (IOException | MaxChangedBlocksException | EmptyClipboardException | IncompleteRegionException e) {
e.printStackTrace();
}
}
use of com.sk89q.worldedit.LocalSession in project Prism-Bukkit by prism.
the class WorldEditBridge method getSelectedArea.
/**
* Worldedit bridge.
*
* @param plugin Prism
* @param player Player
* @param parameters {@link QueryParameters}
* @return boolean.
*/
public static boolean getSelectedArea(Plugin plugin, Player player, QueryParameters parameters) {
// Get selected area
Region region = null;
try {
final BukkitPlayer lp = BukkitAdapter.adapt(player);
final World lw = lp.getWorld();
LocalSession session = WorldEdit.getInstance().getSessionManager().getIfPresent(lp);
if (session != null) {
region = session.getSelection(lw);
}
if (region == null) {
return false;
}
final Vector minLoc = new Vector(region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ());
final Vector maxLoc = new Vector(region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ());
final Region sel = session.getRegionSelector(lw).getRegion();
final double lRadius = ((float) sel.getLength() + 1) / 2;
final double wRadius = ((float) sel.getWidth() + 1) / 2;
final double hRadius = ((float) sel.getHeight() + 1) / 2;
String procType = "applier";
if (parameters.getProcessType().equals(PrismProcessType.LOOKUP)) {
procType = "lookup";
}
final int maxRadius = plugin.getConfig().getInt("prism.queries.max-" + procType + "-radius");
if (maxRadius != 0 && (lRadius > maxRadius || wRadius > maxRadius || hRadius > maxRadius) && !player.hasPermission("prism.override-max-" + procType + "-radius")) {
return false;
} else {
parameters.setWorld(region.getWorld().getName());
parameters.setMinLocation(minLoc);
parameters.setMaxLocation(maxLoc);
}
} catch (final IncompleteRegionException e) {
return false;
}
return true;
}
use of com.sk89q.worldedit.LocalSession in project AreaShop by NLthijs48.
the class WorldEditHandler6 method restoreRegionBlocks.
@Override
public boolean restoreRegionBlocks(File file, GeneralRegionInterface regionInterface) {
com.sk89q.worldedit.world.World world = null;
if (regionInterface.getName() != null) {
world = LocalWorldAdapter.adapt(new BukkitWorld(regionInterface.getWorld()));
}
if (world == null) {
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
return false;
}
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
editSession.enableQueue();
ProtectedRegion region = regionInterface.getRegion();
// Get the origin and size of the region
Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
// Read the schematic and paste it into the world
try (Closer closer = Closer.create()) {
FileInputStream fis = closer.register(new FileInputStream(file));
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
ClipboardReader reader = ClipboardFormat.SCHEMATIC.getReader(bis);
WorldData worldData = world.getWorldData();
LocalSession session = new LocalSession(pluginInterface.getWorldEdit().getLocalConfiguration());
Clipboard clipboard = reader.read(worldData);
if (clipboard.getDimensions().getY() != regionInterface.getHeight() || clipboard.getDimensions().getX() != regionInterface.getWidth() || clipboard.getDimensions().getZ() != regionInterface.getDepth()) {
pluginInterface.getLogger().warning("Size of the region " + regionInterface.getName() + " is not the same as the schematic to restore!");
pluginInterface.debugI("schematic|region, x:" + clipboard.getDimensions().getX() + "|" + regionInterface.getWidth() + ", y:" + clipboard.getDimensions().getY() + "|" + regionInterface.getHeight() + ", z:" + clipboard.getDimensions().getZ() + "|" + regionInterface.getDepth());
}
clipboard.setOrigin(clipboard.getMinimumPoint());
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, worldData);
session.setBlockChangeLimit(pluginInterface.getConfig().getInt("maximumBlocks"));
session.setClipboard(clipboardHolder);
// Build operation
BlockTransformExtent extent = new BlockTransformExtent(clipboardHolder.getClipboard(), clipboardHolder.getTransform(), editSession.getWorld().getWorldData().getBlockRegistry());
ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), editSession, origin);
copy.setTransform(clipboardHolder.getTransform());
// TODO make this more efficient (especially for polygon regions)
if (region.getType() != RegionType.CUBOID) {
copy.setSourceMask(new Mask() {
@Override
public boolean test(Vector vector) {
return region.contains(vector);
}
@Nullable
@Override
public Mask2D toMask2D() {
return null;
}
});
}
Operations.completeLegacy(copy);
} catch (MaxChangedBlocksException e) {
pluginInterface.getLogger().warning("Exeeded the block limit while restoring schematic of " + regionInterface.getName() + ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: " + pluginInterface.getConfig().getInt("maximumBlocks"));
return false;
} catch (IOException e) {
pluginInterface.getLogger().warning("An error occured while restoring schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
}
editSession.flushQueue();
return true;
}
Aggregations