From e6e9cec1e9b0b718d19816a767845a27fdffcb66 Mon Sep 17 00:00:00 2001 From: Rigby Date: Wed, 21 Sep 2011 11:48:24 +0100 Subject: [PATCH] Added PlayerToggleSprint event and sprinting related API. --- .../java/net/minecraft/server/NetServerHandler.java | 10 ++++++++++ .../org/bukkit/craftbukkit/entity/CraftPlayer.java | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java index e0dfeac59b..11c2438d48 100644 --- a/src/main/java/net/minecraft/server/NetServerHandler.java +++ b/src/main/java/net/minecraft/server/NetServerHandler.java @@ -28,6 +28,7 @@ import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.event.player.PlayerToggleSprintEvent; // CraftBukkit end public class NetServerHandler extends NetHandler implements ICommandListener { @@ -846,6 +847,15 @@ public class NetServerHandler extends NetHandler implements ICommandListener { return; } } + + if (packet19entityaction.animation == 4 || packet19entityaction.animation == 5) { + PlayerToggleSprintEvent event = new PlayerToggleSprintEvent(this.getPlayer(), packet19entityaction.animation == 4); + this.server.getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return; + } + } // CraftBukkit end if (packet19entityaction.animation == 1) { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index e38ec9b08e..7ce51a200a 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -298,6 +298,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return getHandle().isSneaking(); } + public boolean isSprinting() { + return getHandle().at(); + } + + public void setSprinting(boolean sprinting) { + getHandle().g(sprinting); + } + public void loadData() { server.getHandle().playerFileData.b(getHandle()); } @@ -411,7 +419,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override public void setGameMode(GameMode mode) { if (getHandle().netServerHandler == null) return; - + if (mode == null) { throw new IllegalArgumentException("Mode cannot be null"); }