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.WorldEdit;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
|
import com.sk89q.worldedit.event.extent.PlayerSaveClipboardEvent;
|
||||||
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.BlockArrayClipboard;
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
@ -337,7 +338,7 @@ public class SchematicCommands extends MethodCommands {
|
|||||||
} else {
|
} else {
|
||||||
target = clipboard;
|
target = clipboard;
|
||||||
}
|
}
|
||||||
|
if (new PlayerSaveClipboardEvent(player, clipboard, f.toURI()).call()) {
|
||||||
try (ClipboardWriter writer = format.getWriter(fos)) {
|
try (ClipboardWriter writer = format.getWriter(fos)) {
|
||||||
if (writer instanceof StructureFormat) {
|
if (writer instanceof StructureFormat) {
|
||||||
((StructureFormat) writer).write(target, holder.getWorldData(), player.getName());
|
((StructureFormat) writer).write(target, holder.getWorldData(), player.getName());
|
||||||
@ -347,6 +348,9 @@ public class SchematicCommands extends MethodCommands {
|
|||||||
log.info(player.getName() + " saved " + f.getCanonicalPath());
|
log.info(player.getName() + " saved " + f.getCanonicalPath());
|
||||||
BBC.SCHEMATIC_SAVED.send(player, filename);
|
BBC.SCHEMATIC_SAVED.send(player, filename);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
BBC.WORLDEDIT_CANCEL_REASON_MANUAL.send(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -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.Vector;
|
||||||
import com.sk89q.worldedit.entity.Player;
|
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.Extent;
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
import static com.sk89q.worldedit.EditSession.Stage;
|
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 Player player;
|
||||||
private final Clipboard clipboard;
|
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