Added Sneaking Event

By: Alexander Hesse <azi@MacBook-Pro.local>
This commit is contained in:
Bukkit/Spigot 2011-01-25 19:04:52 +01:00
parent d245d54634
commit b280199e83
5 changed files with 74 additions and 4 deletions

View file

@ -64,4 +64,16 @@ public interface Player extends HumanEntity, CommandSender {
* @return true if the command was successful, otherwise false * @return true if the command was successful, otherwise false
*/ */
public boolean performCommand(String command); public boolean performCommand(String command);
/**
* Returns if the player is in sneak mode
* @return true if player is in sneak mode
*/
public boolean isSneaking();
/**
* Sets the sneak mode the player
* @param sneak true if player should appear sneaking
*/
public void setSneaking(boolean sneak);
} }

View file

@ -195,10 +195,17 @@ public abstract class Event {
/** /**
* Called when a player undergoes an animation, such as arm swinging * Called when a player undergoes an animation, such as arm swinging
* *
* @todo: add javadoc see comment * @see org.bukkit.event.player.PlayerAnimationEvent
*/ */
PLAYER_ANIMATION (Category.PLAYER), PLAYER_ANIMATION (Category.PLAYER),
/**
* Called when a player toggles sneak mode
*
* @todo: add javadoc see comment
*/
PLAYER_TOGGLE_SNEAK (Category.PLAYER),
/** /**
* Called when a player uses an item * Called when a player uses an item
* *

View file

@ -32,9 +32,8 @@ public class PlayerListener implements Listener {
* @param event Relevant event details * @param event Relevant event details
*/ */
public void onPlayerKick(PlayerKickEvent event) { public void onPlayerKick(PlayerKickEvent event) {
} }
/** /**
* Called when a player sends a chat message * Called when a player sends a chat message
* *
@ -66,7 +65,7 @@ public class PlayerListener implements Listener {
*/ */
public void onPlayerTeleport(PlayerMoveEvent event) { public void onPlayerTeleport(PlayerMoveEvent event) {
} }
/** /**
* Called when a player respawns * Called when a player respawns
* *
@ -130,4 +129,12 @@ public class PlayerListener implements Listener {
*/ */
public void onPlayerDropItem(PlayerDropItemEvent event) { public void onPlayerDropItem(PlayerDropItemEvent event) {
} }
/**
* Called when a player toggles sneak mode
*
* @param event Relevant event details
*/
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
}
} }

View file

@ -0,0 +1,39 @@
package org.bukkit.event.player;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
/**
*
* @author azi
*/
public class PlayerToggleSneakEvent extends PlayerEvent implements Cancellable{
private boolean cancel = false;
public PlayerToggleSneakEvent(final Type type, final Player player) {
super(type, player);
}
/**
* 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;
}
}

View file

@ -194,6 +194,11 @@ public final class JavaPluginLoader implements PluginLoader {
((PlayerListener)listener).onPlayerDropItem( (PlayerDropItemEvent)event ); ((PlayerListener)listener).onPlayerDropItem( (PlayerDropItemEvent)event );
} }
}; };
case PLAYER_TOGGLE_SNEAK:
return new EventExecutor() { public void execute( Listener listener, Event event ) {
((PlayerListener)listener).onPlayerToggleSneak( (PlayerToggleSneakEvent)event );
}
};
// Block Events // Block Events
case BLOCK_PHYSICS: case BLOCK_PHYSICS: