From 8fb141bfa0b8d01de6c4680e69f1c29a0acc51d8 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Thu, 22 Mar 2012 22:04:13 +0000 Subject: [PATCH] Implemented new player flight methods. This implements BUKKIT-1281. This also fixes BUKKIT-1146. --- .../craftbukkit/entity/CraftPlayer.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 4c882ac566..6898c063c7 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -577,14 +577,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player { getHandle().getFoodData().foodLevel = value; } - public boolean getAllowFlight() { - return getHandle().itemInWorldManager.player.abilities.canFly; - } - - public void setAllowFlight(boolean flight) { - getHandle().itemInWorldManager.player.abilities.canFly = flight; - } - public Location getBedSpawnLocation() { World world = getServer().getWorld(getHandle().spawnWorld); if ((world != null) && (getHandle().getBed() != null)) { @@ -813,4 +805,30 @@ public class CraftPlayer extends CraftHumanEntity implements Player { public void disconnect(String reason) { conversationTracker.abandonAllConversations(); } + + public boolean isFlying() { + return getHandle().abilities.isFlying; + } + + public void setFlying(boolean value) { + if (!getAllowFlight() && value) { + throw new IllegalArgumentException("Cannot make player fly if getAllowFlight() is false"); + } + + getHandle().abilities.isFlying = value; + getHandle().updateAbilities(); + } + + public boolean getAllowFlight() { + return getHandle().abilities.canFly; + } + + public void setAllowFlight(boolean value) { + if (isFlying() && !value) { + getHandle().abilities.canFly = false; + } + + getHandle().abilities.canFly = value; + getHandle().updateAbilities(); + } }