mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 19:36:41 +00:00
Copy paste/merge FAWE classes to this WorldEdit fork
- so certain people can look at the diff and complain about my sloppy code :( Signed-off-by: Jesse Boyd <jessepaleg@gmail.com>
This commit is contained in:
@ -19,8 +19,22 @@
|
||||
|
||||
package com.sk89q.worldedit.event;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
|
||||
/**
|
||||
* An abstract base class for all WorldEdit events.
|
||||
*/
|
||||
public abstract class Event {
|
||||
|
||||
/**
|
||||
* Returns true if this event was called and not cancelled
|
||||
* @return !isCancelled
|
||||
*/
|
||||
public boolean call() {
|
||||
WorldEdit.getInstance().getEventBus().post(this);
|
||||
if (this instanceof Cancellable) {
|
||||
return !((Cancellable) this).isCancelled();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -19,33 +19,35 @@
|
||||
|
||||
package com.sk89q.worldedit.event.extent;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.EditSession.Stage;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.event.Cancellable;
|
||||
import com.sk89q.worldedit.event.Event;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.EditSession.Stage;
|
||||
|
||||
/**
|
||||
* Raised (several times) when a new {@link EditSession} is being instantiated.
|
||||
*
|
||||
* <p>
|
||||
* <p></p>Block loggers, as well as block set interceptors, can use this event to wrap
|
||||
* the given {@link Extent} with their own, which would allow them to intercept
|
||||
* all changes made to the world. For example, the code below would wrap the
|
||||
* existing extent with a custom one, and the custom extent would receive
|
||||
* all method calls <strong>before</strong> the extent fetched from
|
||||
* {@link #getExtent()} would.</p>
|
||||
*
|
||||
* <p>
|
||||
* <pre>
|
||||
* event.setExtent(new MyExtent(event.getExtent())
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* <p></p>This event is fired several times during the creation of a single
|
||||
* {@link EditSession}, but {@link #getStage()} will differ each time.
|
||||
* The stage determines at which point {@link Extent}s added to this event
|
||||
@ -53,27 +55,29 @@ import javax.annotation.Nullable;
|
||||
* is set to {@link Stage#BEFORE_HISTORY}, then you can drop (or log) changes
|
||||
* before the change has reached the history, reordering, and actual change
|
||||
* extents, <em>but</em> that means that any changes made with
|
||||
* {@link EditSession#rawSetBlock(Vector, BlockStateHolder)} will skip your
|
||||
* {@link EditSession#rawSetBlock(Vector, BaseBlock)} will skip your
|
||||
* custom {@link Extent} because that method bypasses history (and reorder).
|
||||
* It is thus recommended that loggers intercept at {@link Stage#BEFORE_CHANGE}
|
||||
* and block interceptors intercept at BOTH {@link Stage#BEFORE_CHANGE} and
|
||||
* {@link Stage#BEFORE_HISTORY}.</p>
|
||||
*/
|
||||
public class EditSessionEvent extends Event {
|
||||
public class EditSessionEvent extends Event implements Cancellable {
|
||||
|
||||
private final World world;
|
||||
private final Actor actor;
|
||||
private final int maxBlocks;
|
||||
private final Stage stage;
|
||||
private Extent extent;
|
||||
private EditSession session;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* Create a new event.
|
||||
*
|
||||
* @param world the world
|
||||
* @param actor the actor, or null if there is no actor specified
|
||||
* @param world the world
|
||||
* @param actor the actor, or null if there is no actor specified
|
||||
* @param maxBlocks the maximum number of block changes
|
||||
* @param stage the stage
|
||||
* @param stage the stage
|
||||
*/
|
||||
public EditSessionEvent(@Nullable World world, Actor actor, int maxBlocks, Stage stage) {
|
||||
this.world = world;
|
||||
@ -82,12 +86,22 @@ public class EditSessionEvent extends Event {
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
public void setEditSession(EditSession session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public EditSession getEditSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actor for this event.
|
||||
*
|
||||
* @return the actor, which may be null if unavailable
|
||||
*/
|
||||
public @Nullable Actor getActor() {
|
||||
public
|
||||
@Nullable
|
||||
Actor getActor() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
@ -96,7 +110,9 @@ public class EditSessionEvent extends Event {
|
||||
*
|
||||
* @return the world
|
||||
*/
|
||||
public @Nullable World getWorld() {
|
||||
public
|
||||
@Nullable
|
||||
World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@ -138,6 +154,16 @@ public class EditSessionEvent extends Event {
|
||||
this.extent = extent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a clone of this event with the given stage.
|
||||
*
|
||||
@ -145,7 +171,12 @@ public class EditSessionEvent extends Event {
|
||||
* @return a new event
|
||||
*/
|
||||
public EditSessionEvent clone(Stage stage) {
|
||||
return new EditSessionEvent(world, actor, maxBlocks, stage);
|
||||
EditSessionEvent clone = new EditSessionEvent(world, actor, maxBlocks, stage);
|
||||
clone.setEditSession(session);
|
||||
return clone;
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return EditSessionEvent.class;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 static com.sk89q.worldedit.EditSession.Stage;
|
||||
|
||||
public class PasteEvent extends Event implements Cancellable {
|
||||
|
||||
private final Player player;
|
||||
private final Clipboard clipboard;
|
||||
private final URI uri;
|
||||
private final Vector to;
|
||||
private final Extent extent;
|
||||
private boolean cancelled;
|
||||
|
||||
public PasteEvent(Player player, Clipboard clipboard, URI uri, Extent extent, Vector to) {
|
||||
this.player = player;
|
||||
this.clipboard = clipboard;
|
||||
this.uri = uri;
|
||||
this.extent = extent;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public Clipboard getClipboard() {
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
public URI getURI() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public Extent getExtent() {
|
||||
return extent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a clone of this event with the given stage.
|
||||
*
|
||||
* @param stage the stage
|
||||
* @return a new event
|
||||
*/
|
||||
public PasteEvent clone(Stage stage) {
|
||||
PasteEvent clone = new PasteEvent(player, clipboard, uri, extent, to);
|
||||
return clone;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
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 java.net.URI;
|
||||
|
||||
public class PlayerSaveClipboardEvent extends Event implements Cancellable {
|
||||
private final Player player;
|
||||
private final Clipboard clipboard;
|
||||
private final URI source, destination;
|
||||
private boolean cancelled;
|
||||
|
||||
public PlayerSaveClipboardEvent(Player player, Clipboard clipboard, URI source, URI destination) {
|
||||
this.player = player;
|
||||
this.clipboard = clipboard;
|
||||
this.source = source;
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public URI getSourceURI() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public URI getDestinationURI() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public Clipboard getClipboard() {
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
@ -19,13 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.event.platform;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.event.Cancellable;
|
||||
import com.sk89q.worldedit.event.Event;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Called when a block is interacted with.
|
||||
*/
|
||||
|
@ -19,11 +19,11 @@
|
||||
|
||||
package com.sk89q.worldedit.event.platform;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.event.AbstractCancellable;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* This class is currently only for internal use. Do not post or catch this event.
|
||||
*/
|
||||
|
@ -19,14 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.event.platform;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.event.Event;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Posted when suggestions for auto-completion are requested for command input.
|
||||
*/
|
||||
|
@ -19,11 +19,11 @@
|
||||
|
||||
package com.sk89q.worldedit.event.platform;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.event.Event;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Raised when the configuration has been loaded or re-loaded.
|
||||
*/
|
||||
|
@ -19,12 +19,12 @@
|
||||
|
||||
package com.sk89q.worldedit.event.platform;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.event.Cancellable;
|
||||
import com.sk89q.worldedit.event.Event;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Raised whenever a player sends input.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user