Search in sources :

Example 1 with EmptyClipboardException

use of com.sk89q.worldedit.EmptyClipboardException 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)

Aggregations

EmptyClipboardException (com.sk89q.worldedit.EmptyClipboardException)1 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)1 LocalSession (com.sk89q.worldedit.LocalSession)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)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 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)1 SpongePlayer (com.sk89q.worldedit.sponge.SpongePlayer)1 SpongeWorld (com.sk89q.worldedit.sponge.SpongeWorld)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 IOException (java.io.IOException)1