From ce36ff1cf9e37ab31d9f872692fc08525f3179d6 Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Thu, 28 Jul 2011 01:17:07 -0400 Subject: Added PlayerVelocityEvent. Thanks Evenprime! --- src/main/java/org/bukkit/event/Event.java | 7 +++ .../org/bukkit/event/player/PlayerListener.java | 8 +++ .../bukkit/event/player/PlayerVelocityEvent.java | 63 ++++++++++++++++++++++ .../org/bukkit/plugin/java/JavaPluginLoader.java | 7 +++ 4 files changed, 85 insertions(+) create mode 100644 src/main/java/org/bukkit/event/player/PlayerVelocityEvent.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index 5aa765f0..233d8214 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -197,6 +197,13 @@ public abstract class Event implements Serializable { * @see org.bukkit.event.player.PlayerMoveEvent */ PLAYER_MOVE (Category.PLAYER), + /** + * Called before a player gets a velocity vector sent, which will instruct him to + * get "pushed" into a specific direction, e.g. after an explosion + * + * @see org.bukkit.event.player.PlayerVelocityEvent + */ + PLAYER_VELOCITY (Category.PLAYER), /** * Called when a player undergoes an animation (Arm Swing is the only animation currently supported) * diff --git a/src/main/java/org/bukkit/event/player/PlayerListener.java b/src/main/java/org/bukkit/event/player/PlayerListener.java index 54e5f042..6a5137df 100644 --- a/src/main/java/org/bukkit/event/player/PlayerListener.java +++ b/src/main/java/org/bukkit/event/player/PlayerListener.java @@ -51,6 +51,14 @@ public class PlayerListener implements Listener { */ public void onPlayerMove(PlayerMoveEvent event) {} + /** + * Called before a player gets a velocity vector sent, which will "push" + * the player in a certain direction + * + * @param event Relevant event details + */ + public void onPlayerVelocity(PlayerVelocityEvent event) {} + /** * Called when a player attempts to teleport to a new location in a world * diff --git a/src/main/java/org/bukkit/event/player/PlayerVelocityEvent.java b/src/main/java/org/bukkit/event/player/PlayerVelocityEvent.java new file mode 100644 index 00000000..f658ec05 --- /dev/null +++ b/src/main/java/org/bukkit/event/player/PlayerVelocityEvent.java @@ -0,0 +1,63 @@ +package org.bukkit.event.player; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.util.Vector; + +public class PlayerVelocityEvent extends PlayerEvent implements Cancellable { + + /** + * Holds information for player velocity events + */ + private boolean cancel = false; + private Vector velocity; + + public PlayerVelocityEvent(final Player player, final Vector velocity) { + super(Type.PLAYER_VELOCITY, player); + this.velocity = velocity; + } + + PlayerVelocityEvent(final Event.Type type, final Player player, final Vector velocity) { + super(type, player); + this.velocity = velocity; + } + + /** + * Gets the cancellation state of this event. A cancelled event will not + * be executed in the server, but will still pass to other plugins + * + * @return true if this event is cancelled + */ + public boolean isCancelled() { + return cancel; + } + + /** + * Sets the cancellation state of this event. A cancelled event will not + * be executed in the server, but will still pass to other plugins + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + /** + * Gets the velocity vector that will be sent to the player + * + * @return Vector the player will get + */ + public Vector getVelocity() { + return velocity; + } + + /** + * Sets the velocity vector that will be sent to the player + * + * @param velocity The velocity vector that will be sent to the player + */ + public void setVelocity(Vector velocity) { + this.velocity = velocity; + } +} diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 1bc795dd..846aeb89 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -287,6 +287,13 @@ public final class JavaPluginLoader implements PluginLoader { } }; + case PLAYER_VELOCITY: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((PlayerListener) listener).onPlayerVelocity((PlayerVelocityEvent) event); + } + }; + case PLAYER_TELEPORT: return new EventExecutor() { public void execute(Listener listener, Event event) { -- cgit v1.2.3