diff options
author | Wesley Wolfe <weswolf@aol.com> | 2012-08-10 00:00:04 -0500 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2012-08-10 00:00:04 -0500 |
commit | 342f9c3bd304f85b3603fbff805d10ab2bb6593d (patch) | |
tree | e56c25020aa2c661e1919549ac8d46e202c2c923 /src/main | |
parent | 77cda7e715f1a82f5bb9eeb17ae22352ca9e2f75 (diff) | |
download | craftbukkit-342f9c3bd304f85b3603fbff805d10ab2bb6593d.tar craftbukkit-342f9c3bd304f85b3603fbff805d10ab2bb6593d.tar.gz craftbukkit-342f9c3bd304f85b3603fbff805d10ab2bb6593d.tar.lz craftbukkit-342f9c3bd304f85b3603fbff805d10ab2bb6593d.tar.xz craftbukkit-342f9c3bd304f85b3603fbff805d10ab2bb6593d.zip |
Implement player speed API. Addresses BUKKIT-2205
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/net/minecraft/server/PlayerAbilities.java | 4 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | 35 |
2 files changed, 37 insertions, 2 deletions
diff --git a/src/main/java/net/minecraft/server/PlayerAbilities.java b/src/main/java/net/minecraft/server/PlayerAbilities.java index e79ffb58..5ce83dda 100644 --- a/src/main/java/net/minecraft/server/PlayerAbilities.java +++ b/src/main/java/net/minecraft/server/PlayerAbilities.java @@ -7,8 +7,8 @@ public class PlayerAbilities { public boolean canFly = false; public boolean canInstantlyBuild = false; public boolean mayBuild = true; - private float flySpeed = 0.05F; - private float walkSpeed = 0.1F; + public float flySpeed = 0.05F; // CraftBukkit private -> public + public float walkSpeed = 0.1F; // CraftBukkit private -> public public PlayerAbilities() {} diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index b1906046..bb7e5069 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -864,4 +864,39 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return getHandle().noDamageTicks; } } + + public void setFlySpeed(float value) { + validateSpeed(value); + EntityPlayer player = getHandle(); + player.abilities.flySpeed = value / 2f; + player.updateAbilities(); + + } + + public void setWalkSpeed(float value) { + validateSpeed(value); + EntityPlayer player = getHandle(); + player.abilities.walkSpeed = value / 2f; + player.updateAbilities(); + } + + public float getFlySpeed() { + return getHandle().abilities.flySpeed * 2f; + } + + public float getWalkSpeed() { + return getHandle().abilities.walkSpeed * 2f; + } + + private void validateSpeed(float value) { + if (value < 0) { + if (value < -1f) { + throw new IllegalArgumentException(value + " is too low"); + } + } else { + if (value > 1f) { + throw new IllegalArgumentException(value + " is too high"); + } + } + } } |