diff --git a/paper-api/src/main/java/org/bukkit/entity/Player.java b/paper-api/src/main/java/org/bukkit/entity/Player.java index c439ebeca4..8a82677448 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Player.java +++ b/paper-api/src/main/java/org/bukkit/entity/Player.java @@ -64,4 +64,16 @@ public interface Player extends HumanEntity, CommandSender { * @return true if the command was successful, otherwise false */ 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); } diff --git a/paper-api/src/main/java/org/bukkit/event/Event.java b/paper-api/src/main/java/org/bukkit/event/Event.java index a9448252ed..e0f7ac4633 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -195,10 +195,17 @@ public abstract class Event { /** * 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), + /** + * Called when a player toggles sneak mode + * + * @todo: add javadoc see comment + */ + PLAYER_TOGGLE_SNEAK (Category.PLAYER), + /** * Called when a player uses an item * diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java index 271bf3d868..9137e670df 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java @@ -32,9 +32,8 @@ public class PlayerListener implements Listener { * @param event Relevant event details */ public void onPlayerKick(PlayerKickEvent event) { - } - + /** * Called when a player sends a chat message * @@ -66,7 +65,7 @@ public class PlayerListener implements Listener { */ public void onPlayerTeleport(PlayerMoveEvent event) { } - + /** * Called when a player respawns * @@ -130,4 +129,12 @@ public class PlayerListener implements Listener { */ public void onPlayerDropItem(PlayerDropItemEvent event) { } + + /** + * Called when a player toggles sneak mode + * + * @param event Relevant event details + */ + public void onPlayerToggleSneak(PlayerToggleSneakEvent event) { + } } diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerToggleSneakEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerToggleSneakEvent.java new file mode 100644 index 0000000000..bf12cf7769 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerToggleSneakEvent.java @@ -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; + } +} diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index f3a470ec10..a467f34ee3 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -194,6 +194,11 @@ public final class JavaPluginLoader implements PluginLoader { ((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 case BLOCK_PHYSICS: