This commit is contained in:
Sauilitired 2016-06-16 02:08:01 +02:00
parent ae5e15e434
commit 5b103d49c0
6 changed files with 40 additions and 17 deletions

View File

@ -173,6 +173,11 @@ public class BukkitPlayer extends PlotPlayer {
this.player.setAllowFlight(fly); this.player.setAllowFlight(fly);
} }
@Override
public boolean getFlight() {
return player.getAllowFlight();
}
@Override @Override
public void playMusic(Location location, int id) { public void playMusic(Location location, int id) {
//noinspection deprecation //noinspection deprecation

View File

@ -113,6 +113,11 @@ public class ConsolePlayer extends PlotPlayer {
@Override @Override
public void setFlight(boolean fly) {} public void setFlight(boolean fly) {}
@Override
public boolean getFlight() {
return true;
}
@Override @Override
public void playMusic(Location location, int id) {} public void playMusic(Location location, int id) {}

View File

@ -324,6 +324,8 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
*/ */
public abstract void setFlight(boolean fly); public abstract void setFlight(boolean fly);
public abstract boolean getFlight();
/** /**
* Play music at a location for the player. * Play music at a location for the player.
* @param location where to play the music * @param location where to play the music

View File

@ -15,4 +15,11 @@ public class ByteArrayUtilities {
return (bytes[0]<<24)&0xff000000|(bytes[1]<<16)&0x00ff0000|(bytes[2]<<8)&0x0000ff00|(bytes[3])&0x000000ff; 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)};
}
} }

View File

@ -11,16 +11,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.*;
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.expiry.ExpireManager; import com.intellectualcrafters.plot.util.expiry.ExpireManager;
import java.util.HashMap; import java.util.HashMap;
@ -94,8 +85,11 @@ public class PlotListener {
} }
Optional<Boolean> flyFlag = plot.getFlag(Flags.FLY); Optional<Boolean> flyFlag = plot.getFlag(Flags.FLY);
if (flyFlag.isPresent()) { if (flyFlag.isPresent()) {
if (flyFlag.get() != player.getFlight()) {
player.setPersistentMeta("flight", ByteArrayUtilities.booleanToBytes(player.getFlight()));
player.setFlight(flyFlag.get()); player.setFlight(flyFlag.get());
} }
}
Optional<Long> timeFlag = plot.getFlag(Flags.TIME); Optional<Long> timeFlag = plot.getFlag(Flags.TIME);
if (timeFlag.isPresent()) { if (timeFlag.isPresent()) {
try { try {
@ -204,11 +198,15 @@ public class PlotListener {
} }
} }
if (plot.getFlag(Flags.FLY).isPresent()) { if (plot.getFlag(Flags.FLY).isPresent()) {
PlotGameMode gamemode = player.getGameMode(); if (player.hasPersistentMeta("flight")) {
if (gamemode == PlotGameMode.SURVIVAL || (gamemode == PlotGameMode.ADVENTURE)) { player.setFlight(ByteArrayUtilities.bytesToBoolean(player.getPersistentMeta("flight")));
} else {
PlotGameMode gameMode = player.getGameMode();
if (gameMode == PlotGameMode.SURVIVAL || gameMode == PlotGameMode.ADVENTURE) {
player.setFlight(false); player.setFlight(false);
} }
} }
}
if (plot.getFlag(Flags.TIME).isPresent()) { if (plot.getFlag(Flags.TIME).isPresent()) {
player.setTime(Long.MAX_VALUE); player.setTime(Long.MAX_VALUE);
} }

View File

@ -168,6 +168,12 @@ public class SpongePlayer extends PlotPlayer {
this.player.offer(Keys.CAN_FLY, fly); this.player.offer(Keys.CAN_FLY, fly);
} }
@Override
public boolean getFlight() {
Optional<Boolean> flying = player.get(Keys.CAN_FLY);
return flying.isPresent() && flying.get();
}
@Override @Override
public void playMusic(Location location, int id) { public void playMusic(Location location, int id) {
switch (id) { switch (id) {