Allow deletion of DOC

Fixes #1325
This commit is contained in:
dordsor21 2021-09-27 14:39:21 +01:00
parent b73db47e01
commit 1cf5899586
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
3 changed files with 42 additions and 6 deletions

View File

@ -511,8 +511,7 @@ public class Settings extends Config {
@Comment("Number of days to keep history on disk before deleting it") @Comment("Number of days to keep history on disk before deleting it")
public int DELETE_AFTER_DAYS = 1; public int DELETE_AFTER_DAYS = 1;
@Comment({ @Comment({
"If a players clipboard should be removed from memory upon player logout,", "If a player's clipboard should be deleted upon logout"
" - Will not delete clipboards on disk"
}) })
public boolean DELETE_ON_LOGOUT = false; public boolean DELETE_ON_LOGOUT = false;

View File

@ -24,6 +24,7 @@ import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.configuration.Settings; import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.event.extent.PasteEvent; import com.fastasyncworldedit.core.event.extent.PasteEvent;
import com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard;
import com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder; import com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder;
import com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard; import com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard;
import com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder; import com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder;
@ -609,6 +610,24 @@ public class ClipboardCommands {
) )
@CommandPermissions("worldedit.clipboard.clear") @CommandPermissions("worldedit.clipboard.clear")
public void clearClipboard(Actor actor, LocalSession session) throws WorldEditException { 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;
}
doc.close(); // Ensure closed before deletion
doc.getFile().delete();
}
//FAWE end
session.setClipboard(null); session.setClipboard(null);
actor.print(Caption.of("worldedit.clearclipboard.cleared")); actor.print(Caption.of("worldedit.clearclipboard.cleared"));
} }

View File

@ -33,6 +33,7 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
@ -387,15 +388,32 @@ public interface Player extends Entity, Actor {
} }
/** /**
* Unregister this player, deleting all data stored during the logon session. * Unregister this player, deleting all data stored during the login session.
*/ */
default void unregister() { default void unregister() {
cancel(true); cancel(true);
if (Settings.IMP.CLIPBOARD.DELETE_ON_LOGOUT || Settings.IMP.CLIPBOARD.USE_DISK) { LocalSession session = getSession();
getSession().setClipboard(null); if (Settings.IMP.CLIPBOARD.USE_DISK && Settings.IMP.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;
}
doc.close(); // Ensure closed before deletion
doc.getFile().delete();
}
}
} else if (Settings.IMP.CLIPBOARD.DELETE_ON_LOGOUT || Settings.IMP.CLIPBOARD.USE_DISK) {
session.setClipboard(null);
} }
if (Settings.IMP.HISTORY.DELETE_ON_LOGOUT) { if (Settings.IMP.HISTORY.DELETE_ON_LOGOUT) {
getSession().clearHistory(); session.clearHistory();
} }
} }