mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 10:17:38 +01:00
Implement player speed API. Addresses BUKKIT-2205
By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
parent
7c3b98a7f9
commit
939c2c8477
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user