Add PlayerSaveClipboardEvent

This commit is contained in:
Jesse Boyd 2018-08-11 15:03:43 +10:00
parent c12f685f0f
commit c683b414ba
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 74 additions and 12 deletions

View File

@ -41,6 +41,7 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.PlayerSaveClipboardEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -337,15 +338,18 @@ public class SchematicCommands extends MethodCommands {
} else {
target = clipboard;
}
try (ClipboardWriter writer = format.getWriter(fos)) {
if (writer instanceof StructureFormat) {
((StructureFormat) writer).write(target, holder.getWorldData(), player.getName());
} else {
writer.write(target, holder.getWorldData());
if (new PlayerSaveClipboardEvent(player, clipboard, f.toURI()).call()) {
try (ClipboardWriter writer = format.getWriter(fos)) {
if (writer instanceof StructureFormat) {
((StructureFormat) writer).write(target, holder.getWorldData(), player.getName());
} else {
writer.write(target, holder.getWorldData());
}
log.info(player.getName() + " saved " + f.getCanonicalPath());
BBC.SCHEMATIC_SAVED.send(player, filename);
}
log.info(player.getName() + " saved " + f.getCanonicalPath());
BBC.SCHEMATIC_SAVED.send(player, filename);
} else {
BBC.WORLDEDIT_CANCEL_REASON_MANUAL.send(player);
}
}
} catch (IllegalArgumentException e) {

View File

@ -0,0 +1,16 @@
package com.sk89q.worldedit.event.extent;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.event.Cancellable;
import com.sk89q.worldedit.event.Event;
public abstract class FaweEvent extends Event implements Cancellable {
/**
* Returns true if this event was called and not cancelled
* @return !isCancelled
*/
public boolean call() {
WorldEdit.getInstance().getEventBus().post(this);
return !this.isCancelled();
}
}

View File

@ -21,16 +21,14 @@ package com.sk89q.worldedit.event.extent;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.Cancellable;
import com.sk89q.worldedit.event.Event;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import java.net.URI;
import java.net.URI;
import static com.sk89q.worldedit.EditSession.Stage;
public class PasteEvent extends Event implements Cancellable {
public class PasteEvent extends FaweEvent {
private final Player player;
private final Clipboard clipboard;

View File

@ -0,0 +1,44 @@
package com.sk89q.worldedit.event.extent;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.Cancellable;
import com.sk89q.worldedit.event.Event;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.session.ClipboardHolder;
import java.net.URI;
public class PlayerSaveClipboardEvent extends FaweEvent {
private final Player player;
private final Clipboard clipboard;
private final URI uri;
private boolean cancelled;
public PlayerSaveClipboardEvent(Player player, Clipboard clipboard, URI destination) {
this.player = player;
this.clipboard = clipboard;
this.uri = destination;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
public URI getUri() {
return uri;
}
public Clipboard getClipboard() {
return clipboard;
}
public Player getPlayer() {
return player;
}
}