mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-14 06:36:33 +01:00
Add PlayerSaveClipboardEvent
This commit is contained in:
parent
c12f685f0f
commit
c683b414ba
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user