Search in sources :

Example 1 with SpongeWorld

use of com.sk89q.worldedit.sponge.SpongeWorld 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();
    }
}
Also used : Closer(com.sk89q.worldedit.util.io.Closer) SpongePlayer(com.sk89q.worldedit.sponge.SpongePlayer) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) LocalSession(com.sk89q.worldedit.LocalSession) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) WorldData(com.sk89q.worldedit.world.registry.WorldData) Operation(com.sk89q.worldedit.function.operation.Operation) IOException(java.io.IOException) ClipboardFormat(com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat) FileInputStream(java.io.FileInputStream) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) EmptyClipboardException(com.sk89q.worldedit.EmptyClipboardException) BufferedInputStream(java.io.BufferedInputStream) SpongeWorld(com.sk89q.worldedit.sponge.SpongeWorld) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) ClipboardReader(com.sk89q.worldedit.extent.clipboard.io.ClipboardReader)

Example 2 with SpongeWorld

use of com.sk89q.worldedit.sponge.SpongeWorld 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);
}
Also used : SpongeWorld(com.sk89q.worldedit.sponge.SpongeWorld) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) EditSession(com.sk89q.worldedit.EditSession) Vector(com.sk89q.worldedit.Vector) EditSessionFactory(com.sk89q.worldedit.EditSessionFactory)

Aggregations

SpongeWorld (com.sk89q.worldedit.sponge.SpongeWorld)2 EditSession (com.sk89q.worldedit.EditSession)1 EditSessionFactory (com.sk89q.worldedit.EditSessionFactory)1 EmptyClipboardException (com.sk89q.worldedit.EmptyClipboardException)1 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)1 LocalSession (com.sk89q.worldedit.LocalSession)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 Vector (com.sk89q.worldedit.Vector)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 ClipboardFormat (com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat)1 ClipboardReader (com.sk89q.worldedit.extent.clipboard.io.ClipboardReader)1 Operation (com.sk89q.worldedit.function.operation.Operation)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 Region (com.sk89q.worldedit.regions.Region)1 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)1 SpongePlayer (com.sk89q.worldedit.sponge.SpongePlayer)1 Closer (com.sk89q.worldedit.util.io.Closer)1 WorldData (com.sk89q.worldedit.world.registry.WorldData)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1