mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2024-12-23 00:15:06 +00:00
Make the fly flag an enum flag instead. It now accepts: true
, false
and default
, where default
is the default value, and does not change the flight status at all.
This commit is contained in:
parent
e161209a46
commit
ae2867136a
5 changed files with 75 additions and 26 deletions
|
@ -567,13 +567,15 @@ public enum Captions implements Caption {
|
|||
FLAG_CATEGORY_ENUM("Generic Enum Flags", "Flags"),
|
||||
FLAG_CATEGORY_DECIMAL("Decimal Flags", "Flags"),
|
||||
FLAG_CATEGORY_BOOLEAN("Boolean Flags", "Flags"),
|
||||
FLAG_CATEGORY_FLY("Flight Flags", "Flags"),
|
||||
FLAG_CATEGORY_MIXED("Mixed Value Flags", "Flags"),
|
||||
//</editor-fold>
|
||||
//<editor-fold desc="Flag descriptions">
|
||||
FLAG_DESCRIPTION_ENTITY_CAP("Set to an integer value to limit the amount of entities on the plot.", "Flags"),
|
||||
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"),
|
||||
FLAG_DESCRIPTION_FLIGHT("Set to `true` to enable flight within the plot when in survival or adventure mode,"
|
||||
+ " set to `default` to use the gamemode default, and `false` to disable flight entirely.", "Flags"),
|
||||
FLAG_DESCRIPTION_UNTRUSTED("Set to `false` to disallow untrusted players from visiting the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_DENY_EXIT("Set to `true` to disallow players from exiting the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_DESCRIPTION("Plot description. Supports '&' color codes.", "Flags"),
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Block
|
|||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockIgnitionFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockedCmdsFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BreakFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.CoralDryFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyExitFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyTeleportFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag;
|
||||
|
@ -19,7 +20,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Entit
|
|||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FarewellFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FeedFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlyFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ForcefieldFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GamemodeFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GrassGrowFlag;
|
||||
|
@ -60,7 +61,6 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Serve
|
|||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.SnowFormFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.SnowMeltFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.SoilDryFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.CoralDryFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedAttackFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedInteractFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TimeFlag;
|
||||
|
@ -96,7 +96,6 @@ public final class GlobalFlagContainer extends FlagContainer {
|
|||
// Register all default flags here
|
||||
// Boolean flags
|
||||
this.addFlag(ExplosionFlag.EXPLOSION_FALSE);
|
||||
this.addFlag(FlightFlag.FLIGHT_FLAG_FALSE);
|
||||
this.addFlag(UntrustedVisitFlag.UNTRUSTED_VISIT_FLAG_TRUE);
|
||||
this.addFlag(DenyExitFlag.DENY_EXIT_FLAG_FALSE);
|
||||
this.addFlag(DescriptionFlag.DESCRIPTION_FLAG_EMPTY);
|
||||
|
@ -150,6 +149,7 @@ public final class GlobalFlagContainer extends FlagContainer {
|
|||
this.addFlag(WeatherFlag.PLOT_WEATHER_FLAG_OFF);
|
||||
this.addFlag(DenyTeleportFlag.DENY_TELEPORT_FLAG_NONE);
|
||||
this.addFlag(TitlesFlag.TITLES_NONE);
|
||||
this.addFlag(FlyFlag.FLIGHT_FLAG_DEFAULT);
|
||||
|
||||
// Integer flags
|
||||
this.addFlag(AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
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 protected FlightFlag flagOf(@NotNull Boolean value) {
|
||||
return new FlightFlag(value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.github.intellectualsites.plotsquared.plot.flags.implementations;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FlyFlag extends PlotFlag<FlyFlag.FlyStatus, FlyFlag> {
|
||||
|
||||
public static final FlyFlag FLIGHT_FLAG_DISABLED = new FlyFlag(FlyStatus.DISABLED);
|
||||
public static final FlyFlag FLIGHT_FLAG_ENABLED = new FlyFlag(FlyStatus.ENABLED);
|
||||
public static final FlyFlag FLIGHT_FLAG_DEFAULT = new FlyFlag(FlyStatus.DEFAULT);
|
||||
|
||||
protected FlyFlag(final FlyStatus value) {
|
||||
super(value, Captions.FLAG_CATEGORY_BOOLEAN, Captions.FLAG_DESCRIPTION_FLIGHT);
|
||||
}
|
||||
|
||||
@Override public FlyFlag parse(@NotNull final String input) {
|
||||
switch (input.toLowerCase()) {
|
||||
case "true":
|
||||
case "enabled":
|
||||
case "allow":
|
||||
return FLIGHT_FLAG_ENABLED;
|
||||
case "false":
|
||||
case "disabled":
|
||||
case "disallow":
|
||||
return FLIGHT_FLAG_DISABLED;
|
||||
default:
|
||||
return FLIGHT_FLAG_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public FlyFlag merge(@NotNull final FlyStatus newValue) {
|
||||
if (newValue == FlyStatus.ENABLED || this.getValue() == FlyStatus.ENABLED) {
|
||||
return FLIGHT_FLAG_ENABLED;
|
||||
}
|
||||
return flagOf(newValue);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return this.getValue().name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override public String getExample() {
|
||||
return "true";
|
||||
}
|
||||
|
||||
@Override protected FlyFlag flagOf(@NotNull final FlyStatus value) {
|
||||
switch (value) {
|
||||
case ENABLED:
|
||||
return FLIGHT_FLAG_ENABLED;
|
||||
case DISABLED:
|
||||
return FLIGHT_FLAG_DISABLED;
|
||||
default:
|
||||
return FLIGHT_FLAG_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
public enum FlyStatus {
|
||||
ENABLED,
|
||||
DISABLED,
|
||||
DEFAULT
|
||||
}
|
||||
|
||||
}
|
|
@ -124,7 +124,8 @@ public class PlotListener {
|
|||
}
|
||||
}
|
||||
|
||||
if (plot.getFlag(FlightFlag.class)) {
|
||||
final FlyFlag.FlyStatus flyStatus = plot.getFlag(FlyFlag.class);
|
||||
if (flyStatus != FlyFlag.FlyStatus.DEFAULT) {
|
||||
boolean flight = player.getFlight();
|
||||
GameMode gamemode = player.getGameMode();
|
||||
if (flight != (gamemode == GameModes.CREATIVE
|
||||
|
@ -132,7 +133,7 @@ public class PlotListener {
|
|||
player.setPersistentMeta("flight",
|
||||
ByteArrayUtilities.booleanToBytes(player.getFlight()));
|
||||
}
|
||||
player.setFlight(true);
|
||||
player.setFlight(flyStatus == FlyFlag.FlyStatus.ENABLED);
|
||||
}
|
||||
|
||||
final GameMode gameMode = plot.getFlag(GamemodeFlag.class);
|
||||
|
@ -299,7 +300,8 @@ public class PlotListener {
|
|||
}
|
||||
}
|
||||
|
||||
if (plot.getFlag(FlightFlag.class)) {
|
||||
final FlyFlag.FlyStatus flyStatus = plot.getFlag(FlyFlag.class);
|
||||
if (flyStatus != FlyFlag.FlyStatus.DEFAULT) {
|
||||
if (player.hasPersistentMeta("flight")) {
|
||||
player.setFlight(
|
||||
ByteArrayUtilities.bytesToBoolean(player.getPersistentMeta("flight")));
|
||||
|
|
Loading…
Reference in a new issue