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"));
}
}
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"));
}
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();
}
}
Aggregations