From 5b103d49c0602080fb0ac4c5407cfa0af9b0d4c4 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Thu, 16 Jun 2016 02:08:01 +0200 Subject: [PATCH] Fixes #1171 --- .../bukkit/object/BukkitPlayer.java | 7 ++++- .../plot/object/ConsolePlayer.java | 7 ++++- .../plot/object/PlotPlayer.java | 2 ++ .../plot/util/ByteArrayUtilities.java | 7 +++++ .../plotsquared/listener/PlotListener.java | 26 +++++++++---------- .../sponge/object/SpongePlayer.java | 8 +++++- 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java index 4756abfbd..039599ccf 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java @@ -172,7 +172,12 @@ public class BukkitPlayer extends PlotPlayer { public void setFlight(boolean fly) { this.player.setAllowFlight(fly); } - + + @Override + public boolean getFlight() { + return player.getAllowFlight(); + } + @Override public void playMusic(Location location, int id) { //noinspection deprecation diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java index da868f259..3d09a95d4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java @@ -112,7 +112,12 @@ public class ConsolePlayer extends PlotPlayer { @Override public void setFlight(boolean fly) {} - + + @Override + public boolean getFlight() { + return true; + } + @Override public void playMusic(Location location, int id) {} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index d7d6d2d49..a96330394 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -324,6 +324,8 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { */ public abstract void setFlight(boolean fly); + public abstract boolean getFlight(); + /** * Play music at a location for the player. * @param location where to play the music diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ByteArrayUtilities.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ByteArrayUtilities.java index 17ac001f0..0cc3931f4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ByteArrayUtilities.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ByteArrayUtilities.java @@ -15,4 +15,11 @@ public class ByteArrayUtilities { return (bytes[0]<<24)&0xff000000|(bytes[1]<<16)&0x00ff0000|(bytes[2]<<8)&0x0000ff00|(bytes[3])&0x000000ff; } + public static boolean bytesToBoolean(byte[] bytes) { + return bytes[0] == 1; + } + + public static byte[] booleanToBytes(boolean b) { + return new byte[] {(byte)(b ? 1 : 0)}; + } } diff --git a/Core/src/main/java/com/plotsquared/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/listener/PlotListener.java index efcedfdaf..e7d5666df 100644 --- a/Core/src/main/java/com/plotsquared/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/listener/PlotListener.java @@ -11,16 +11,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; -import com.intellectualcrafters.plot.util.AbstractTitle; -import com.intellectualcrafters.plot.util.CommentManager; -import com.intellectualcrafters.plot.util.EventUtil; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.PlotGameMode; -import com.intellectualcrafters.plot.util.PlotWeather; -import com.intellectualcrafters.plot.util.StringMan; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.*; import com.intellectualcrafters.plot.util.expiry.ExpireManager; import java.util.HashMap; @@ -94,7 +85,10 @@ public class PlotListener { } Optional flyFlag = plot.getFlag(Flags.FLY); if (flyFlag.isPresent()) { - player.setFlight(flyFlag.get()); + if (flyFlag.get() != player.getFlight()) { + player.setPersistentMeta("flight", ByteArrayUtilities.booleanToBytes(player.getFlight())); + player.setFlight(flyFlag.get()); + } } Optional timeFlag = plot.getFlag(Flags.TIME); if (timeFlag.isPresent()) { @@ -204,9 +198,13 @@ public class PlotListener { } } if (plot.getFlag(Flags.FLY).isPresent()) { - PlotGameMode gamemode = player.getGameMode(); - if (gamemode == PlotGameMode.SURVIVAL || (gamemode == PlotGameMode.ADVENTURE)) { - player.setFlight(false); + if (player.hasPersistentMeta("flight")) { + player.setFlight(ByteArrayUtilities.bytesToBoolean(player.getPersistentMeta("flight"))); + } else { + PlotGameMode gameMode = player.getGameMode(); + if (gameMode == PlotGameMode.SURVIVAL || gameMode == PlotGameMode.ADVENTURE) { + player.setFlight(false); + } } } if (plot.getFlag(Flags.TIME).isPresent()) { diff --git a/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java b/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java index bc012d8ff..52d0f1694 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java @@ -167,7 +167,13 @@ public class SpongePlayer extends PlotPlayer { this.player.offer(Keys.IS_FLYING, fly); this.player.offer(Keys.CAN_FLY, fly); } - + + @Override + public boolean getFlight() { + Optional flying = player.get(Keys.CAN_FLY); + return flying.isPresent() && flying.get(); + } + @Override public void playMusic(Location location, int id) { switch (id) {