Port flight flag

This commit is contained in:
Alexander Söderberg 2020-02-13 13:25:22 +01:00
parent 8e729f6949
commit 30d2785ef2
5 changed files with 33 additions and 7 deletions

View File

@ -549,6 +549,7 @@ public enum Captions implements Caption {
//<editor-fold desc="Flag descriptions">
FLAG_DESCRIPTION_EXPLOSION("Set to 'true' to enable explosions in the plot, and 'false' to disable them", "Flags"),
FLAG_DESCRIPTION_MUSIC("Set to a music disk ID (item name) to play the music disc inside of the plot", "Flags"),
FLAG_DESCRIPTION_FLIGHT("Set to 'true' to enable flight within the plot when in survival or adventure mode", "Flags"),
//</editor-fold>
//<editor-fold desc="Flag category errors">
FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"),

View File

@ -24,7 +24,6 @@ public final class Flags {
public static final GameModeFlag GUEST_GAMEMODE = new GameModeFlag("guest-gamemode");
public static final StringFlag DONE = (StringFlag) new StringFlag("done").reserve();
public static final BooleanFlag REDSTONE = new BooleanFlag("redstone");
public static final BooleanFlag FLY = new BooleanFlag("fly");
public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave");
public static final BooleanFlag TITLES = new BooleanFlag("titles");
public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter");

View File

@ -1,6 +1,7 @@
package com.github.intellectualsites.plotsquared.plot.flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag;
import lombok.Getter;
@ -40,6 +41,7 @@ public final class GlobalFlagContainer extends FlagContainer {
// Register all default flags here
this.addFlag(ExplosionFlag.EXPLOSION_FALSE);
this.addFlag(MusicFlag.MUSIC_FLAG_NONE);
this.addFlag(FlightFlag.FLIGHT_FLAG_FALSE);
}
@Override public void addFlag(PlotFlag<?, ?> flag) {

View File

@ -0,0 +1,22 @@
package com.github.intellectualsites.plotsquared.plot.flags.implementations;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.flags.types.BooleanFlag;
import org.jetbrains.annotations.NotNull;
public class FlightFlag extends BooleanFlag<FlightFlag> {
public static final FlightFlag FLIGHT_FLAG_FALSE = new FlightFlag(false);
protected FlightFlag(final boolean value) {
super(value, Captions.FLAG_DESCRIPTION_FLIGHT);
}
@Override public String getExample() {
return "true";
}
@Override protected FlightFlag flagOf(@NotNull Boolean value) {
return new FlightFlag(value);
}
}

View File

@ -5,6 +5,7 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
@ -94,8 +95,8 @@ public class PlotListener {
}
}
}
Optional<Boolean> flyFlag = plot.getFlag(Flags.FLY);
if (flyFlag.isPresent()) {
if (plot.getFlag(FlightFlag.class)) {
boolean flight = player.getFlight();
GameMode gamemode = player.getGameMode();
if (flight != (gamemode == GameModes.CREATIVE
@ -103,10 +104,9 @@ public class PlotListener {
player.setPersistentMeta("flight",
ByteArrayUtilities.booleanToBytes(player.getFlight()));
}
if (flyFlag.get() != player.getFlight()) {
player.setFlight(flyFlag.get());
}
player.setFlight(true);
}
Optional<GameMode> gamemodeFlag = plot.getFlag(Flags.GAMEMODE);
if (gamemodeFlag.isPresent()) {
if (player.getGameMode() != gamemodeFlag.get()) {
@ -254,7 +254,8 @@ public class PlotListener {
}
}
}
if (plot.getFlag(Flags.FLY).isPresent()) {
if (plot.getFlag(FlightFlag.class)) {
if (player.hasPersistentMeta("flight")) {
player.setFlight(
ByteArrayUtilities.bytesToBoolean(player.getPersistentMeta("flight")));
@ -268,6 +269,7 @@ public class PlotListener {
}
}
}
if (plot.getFlag(Flags.TIME).isPresent()) {
player.setTime(Long.MAX_VALUE);
}