Search in sources :

Example 1 with DiskOptimizedClipboard

use of com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard in project FastAsyncWorldEdit by IntellectualSites.

the class Player method loadClipboardFromDisk.

/**
 * Loads any history items from disk: - Should already be called if history on disk is enabled.
 */
default void loadClipboardFromDisk() {
    File file = MainUtil.getFile(Fawe.platform().getDirectory(), Settings.settings().PATHS.CLIPBOARD + File.separator + getUniqueId() + ".bd");
    try {
        if (file.exists() && file.length() > 5) {
            DiskOptimizedClipboard doc = new DiskOptimizedClipboard(file);
            LocalSession session = getSession();
            try {
                if (session.getClipboard() != null) {
                    return;
                }
            } catch (EmptyClipboardException ignored) {
            }
            Clipboard clip = doc.toClipboard();
            ClipboardHolder holder = new ClipboardHolder(clip);
            getSession().setClipboard(holder);
        }
    } catch (FaweClipboardVersionMismatchException e) {
        print(Caption.of("fawe.error.clipboard.on.disk.version.mismatch"));
    } catch (RuntimeException e) {
        print(Caption.of("fawe.error.clipboard.invalid"));
        e.printStackTrace();
        print(Caption.of("fawe.error.stacktrace"));
        print(Caption.of("fawe.error.clipboard.load.failure"));
        print(Caption.of("fawe.error.clipboard.invalid.info", file.getName(), file.length()));
        print(Caption.of("fawe.error.stacktrace"));
    } catch (Exception e) {
        print(Caption.of("fawe.error.clipboard.invalid"));
        e.printStackTrace();
        print(Caption.of("fawe.error.stacktrace"));
        print(Caption.of("fawe.error.no-failure"));
        print(Caption.of("fawe.error.clipboard.invalid.info", file.getName(), file.length()));
        print(Caption.of("fawe.error.stacktrace"));
    }
}
Also used : EmptyClipboardException(com.sk89q.worldedit.EmptyClipboardException) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) FaweClipboardVersionMismatchException(com.fastasyncworldedit.core.internal.exception.FaweClipboardVersionMismatchException) LocalSession(com.sk89q.worldedit.LocalSession) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) File(java.io.File) FaweClipboardVersionMismatchException(com.fastasyncworldedit.core.internal.exception.FaweClipboardVersionMismatchException) WorldEditException(com.sk89q.worldedit.WorldEditException) EmptyClipboardException(com.sk89q.worldedit.EmptyClipboardException) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException)

Example 2 with DiskOptimizedClipboard

use of com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard in project FastAsyncWorldEdit by IntellectualSites.

the class ClipboardCommands method clearClipboard.

@Command(name = "clearclipboard", aliases = { "/clearclipboard", "/cc", "/clearclip" }, desc = "Clear your clipboard")
@CommandPermissions("worldedit.clipboard.clear")
public void clearClipboard(Actor actor, LocalSession session) throws WorldEditException {
    // FAWE start - delete DOC
    ClipboardHolder holder = session.getExistingClipboard();
    if (holder == null) {
        return;
    }
    for (Clipboard clipboard : holder.getClipboards()) {
        DiskOptimizedClipboard doc;
        if (clipboard instanceof DiskOptimizedClipboard) {
            doc = (DiskOptimizedClipboard) clipboard;
        } else if (clipboard instanceof BlockArrayClipboard && ((BlockArrayClipboard) clipboard).getParent() instanceof DiskOptimizedClipboard) {
            doc = (DiskOptimizedClipboard) ((BlockArrayClipboard) clipboard).getParent();
        } else {
            continue;
        }
        // Ensure closed before deletion
        doc.close();
        doc.getFile().delete();
    }
    // FAWE end
    session.setClipboard(null);
    actor.print(Caption.of("worldedit.clearclipboard.cleared"));
}
Also used : BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) ReadOnlyClipboard(com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 3 with DiskOptimizedClipboard

use of com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard in project FastAsyncWorldEdit by IntellectualSites.

the class Player method unregister.

/**
 * Unregister this player, deleting all data stored during the login session.
 */
default void unregister() {
    cancel(true);
    LocalSession session = getSession();
    if (Settings.settings().CLIPBOARD.USE_DISK && Settings.settings().CLIPBOARD.DELETE_ON_LOGOUT) {
        ClipboardHolder holder = session.getExistingClipboard();
        if (holder != null) {
            for (Clipboard clipboard : holder.getClipboards()) {
                DiskOptimizedClipboard doc;
                if (clipboard instanceof DiskOptimizedClipboard) {
                    doc = (DiskOptimizedClipboard) clipboard;
                } else if (clipboard instanceof BlockArrayClipboard && ((BlockArrayClipboard) clipboard).getParent() instanceof DiskOptimizedClipboard) {
                    doc = (DiskOptimizedClipboard) ((BlockArrayClipboard) clipboard).getParent();
                } else {
                    continue;
                }
                WorldEdit.getInstance().getExecutorService().submit(() -> {
                    // Ensure closed before deletion
                    doc.close();
                    doc.getFile().delete();
                });
            }
        }
    } else if (Settings.settings().CLIPBOARD.DELETE_ON_LOGOUT || Settings.settings().CLIPBOARD.USE_DISK) {
        WorldEdit.getInstance().getExecutorService().submit(() -> session.setClipboard(null));
    }
    if (Settings.settings().HISTORY.DELETE_ON_LOGOUT) {
        session.clearHistory();
    }
}
Also used : BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) LocalSession(com.sk89q.worldedit.LocalSession) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard)

Aggregations

DiskOptimizedClipboard (com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard)3 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)3 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)3 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)3 LocalSession (com.sk89q.worldedit.LocalSession)2 MultiClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder)1 ReadOnlyClipboard (com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard)1 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)1 FaweClipboardVersionMismatchException (com.fastasyncworldedit.core.internal.exception.FaweClipboardVersionMismatchException)1 EmptyClipboardException (com.sk89q.worldedit.EmptyClipboardException)1 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)1 WorldEditException (com.sk89q.worldedit.WorldEditException)1 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)1 File (java.io.File)1 Command (org.enginehub.piston.annotation.Command)1