Search in sources :

Example 1 with FaweClipboardVersionMismatchException

use of com.fastasyncworldedit.core.internal.exception.FaweClipboardVersionMismatchException in project FastAsyncWorldEdit by IntellectualSites.

the class DiskOptimizedClipboard method readSize.

private static BlockVector3 readSize(File file) {
    try (DataInputStream is = new DataInputStream(new FileInputStream(file))) {
        is.skipBytes(2);
        int version = is.readChar();
        if (version != VERSION) {
            throw new FaweClipboardVersionMismatchException();
        }
        return BlockVector3.at(is.readChar(), is.readChar(), is.readChar());
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : FaweClipboardVersionMismatchException(com.fastasyncworldedit.core.internal.exception.FaweClipboardVersionMismatchException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream)

Example 2 with FaweClipboardVersionMismatchException

use of com.fastasyncworldedit.core.internal.exception.FaweClipboardVersionMismatchException 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) {
            LocalSession session = getSession();
            try {
                if (session.getClipboard() != null) {
                    return;
                }
            } catch (EmptyClipboardException ignored) {
            }
            DiskOptimizedClipboard doc = new DiskOptimizedClipboard(file);
            Clipboard clip = doc.toClipboard();
            ClipboardHolder holder = new ClipboardHolder(clip);
            session.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)

Aggregations

FaweClipboardVersionMismatchException (com.fastasyncworldedit.core.internal.exception.FaweClipboardVersionMismatchException)2 DiskOptimizedClipboard (com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard)1 EmptyClipboardException (com.sk89q.worldedit.EmptyClipboardException)1 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)1 LocalSession (com.sk89q.worldedit.LocalSession)1 WorldEditException (com.sk89q.worldedit.WorldEditException)1 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1