use of com.sk89q.worldedit.regions.CuboidRegion in project RedProtect by FabioZumbi12.
the class WEListener method regenRegion.
public static void regenRegion(final br.net.fabiozumbi12.RedProtect.Sponge.Region r, final World w, final Location<World> p1, final Location<World> p2, final int delay, final CommandSource sender, final boolean remove) {
Sponge.getScheduler().createSyncExecutor(RedProtect.get().container).schedule(() -> {
if (RPUtil.stopRegen) {
return;
}
Region wreg = new CuboidRegion(new Vector(p1.getX(), p1.getY(), p1.getZ()), new Vector(p2.getX(), p2.getY(), p2.getZ())).getFaces();
SpongeWorld ws = SpongeWorldEdit.inst().getWorld(w);
EditSession esession = new EditSessionFactory().getEditSession(ws, -1);
eSessions.put(r.getID(), esession);
int delayCount = 1 + delay / 10;
if (sender != null) {
if (ws.regenerate(wreg, esession)) {
RPLang.sendMessage(sender, "[" + delayCount + "]" + " &aRegion " + r.getID().split("@")[0] + " regenerated with success!");
} else {
RPLang.sendMessage(sender, "[" + delayCount + "]" + " &cTheres an error when regen the region " + r.getID().split("@")[0] + "!");
}
} else {
if (ws.regenerate(wreg, esession)) {
RedProtect.get().logger.warning("[" + delayCount + "]" + " &aRegion " + r.getID().split("@")[0] + " regenerated with success!");
} else {
RedProtect.get().logger.warning("[" + delayCount + "]" + " &cTheres an error when regen the region " + r.getID().split("@")[0] + "!");
}
}
if (remove) {
RedProtect.get().rm.remove(r, RedProtect.get().serv.getWorld(r.getWorld()).get());
}
}, delay, TimeUnit.MILLISECONDS);
}
use of com.sk89q.worldedit.regions.CuboidRegion in project AreaShop by NLthijs48.
the class WorldEditHandler6 method saveRegionBlocks.
@Override
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
com.sk89q.worldedit.world.World world = null;
if (regionInterface.getWorld() != null) {
world = LocalWorldAdapter.adapt(new BukkitWorld(regionInterface.getWorld()));
}
if (world == null) {
pluginInterface.getLogger().warning("Did not save region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
return false;
}
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
// Create a clipboard
CuboidRegion selection = new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint());
BlockArrayClipboard clipboard = new BlockArrayClipboard(selection);
clipboard.setOrigin(regionInterface.getRegion().getMinimumPoint());
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint()), clipboard, regionInterface.getRegion().getMinimumPoint());
try {
Operations.completeLegacy(copy);
} catch (MaxChangedBlocksException e) {
pluginInterface.getLogger().warning("Exeeded the block limit while saving schematic of " + regionInterface.getName() + ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: " + pluginInterface.getConfig().getInt("maximumBlocks"));
return false;
}
try (Closer closer = Closer.create()) {
FileOutputStream fos = closer.register(new FileOutputStream(file));
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
ClipboardWriter writer = closer.register(ClipboardFormat.SCHEMATIC.getWriter(bos));
writer.write(clipboard, world.getWorldData());
} catch (IOException e) {
pluginInterface.getLogger().warning("An error occured while saving schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
}
return true;
}
Aggregations