diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 759a6b1f8..c1a9da5f5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -1372,7 +1372,9 @@ public class PlayerEvents extends PlotListener implements Listener { final PlotArea fromArea = fLocation.getPlotArea(); if (fromArea != null) { final Plot plot = fromArea.getOwnedPlot(fLocation); - if (plot != null && !plot.getFlag(LiquidFlowFlag.class) && event.getBlock().isLiquid()) { + if (plot != null + && plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event + .getBlock().isLiquid()) { event.setCancelled(true); return; } @@ -1391,14 +1393,16 @@ public class PlayerEvents extends PlotListener implements Listener { event.setCancelled(true); return; } - if (plot.getFlag(LiquidFlowFlag.class) && event.getBlock().isLiquid()) { + if (plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.ENABLED && event + .getBlock().isLiquid()) { return; } if (plot.getFlag(DisablePhysicsFlag.class)) { event.setCancelled(true); return; } - if (!plot.getFlag(LiquidFlowFlag.class) && event.getBlock().isLiquid()) { + if (plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event + .getBlock().isLiquid()) { event.setCancelled(true); } } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java index b05f26cb5..af618769f 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java @@ -147,7 +147,6 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(IceFormFlag.ICE_FORM_FALSE); this.addFlag(IceMeltFlag.ICE_MELT_FALSE); this.addFlag(KelpGrowFlag.KELP_GROW_TRUE); - this.addFlag(LiquidFlowFlag.LIQUID_FLOW_TRUE); this.addFlag(RedstoneFlag.REDSTONE_TRUE); this.addFlag(ServerPlotFlag.SERVER_PLOT_FALSE); this.addFlag(MiscBreakFlag.MISC_BREAK_FALSE); @@ -183,6 +182,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(DenyTeleportFlag.DENY_TELEPORT_FLAG_NONE); this.addFlag(TitlesFlag.TITLES_NONE); this.addFlag(FlyFlag.FLIGHT_FLAG_DEFAULT); + this.addFlag(LiquidFlowFlag.LIQUID_FLOW_DEFAULT); // Integer flags this.addFlag(AnimalCapFlag.ANIMAL_CAP_UNLIMITED); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/LiquidFlowFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/LiquidFlowFlag.java index d8bf97e11..c200ed6a9 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/LiquidFlowFlag.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/LiquidFlowFlag.java @@ -26,20 +26,70 @@ package com.plotsquared.core.plot.flag.implementations; import com.plotsquared.core.configuration.Captions; -import com.plotsquared.core.plot.flag.types.BooleanFlag; +import com.plotsquared.core.plot.flag.PlotFlag; import org.jetbrains.annotations.NotNull; -public class LiquidFlowFlag extends BooleanFlag { +import java.util.Arrays; +import java.util.Collection; - public static final LiquidFlowFlag LIQUID_FLOW_TRUE = new LiquidFlowFlag(true); - public static final LiquidFlowFlag LIQUID_FLOW_FALSE = new LiquidFlowFlag(false); +public class LiquidFlowFlag extends PlotFlag { - private LiquidFlowFlag(boolean value) { - super(value, Captions.FLAG_DESCRIPTION_LIQUID_FLOW); + public static final LiquidFlowFlag LIQUID_FLOW_ENABLED = new LiquidFlowFlag(FlowStatus.ENABLED); + public static final LiquidFlowFlag LIQUID_FLOW_DISABLED = + new LiquidFlowFlag(FlowStatus.DISABLED); + public static final LiquidFlowFlag LIQUID_FLOW_DEFAULT = new LiquidFlowFlag(FlowStatus.DEFAULT); + + private LiquidFlowFlag(FlowStatus value) { + super(value, Captions.FLAG_CATEGORY_BOOLEAN, Captions.FLAG_DESCRIPTION_LIQUID_FLOW); } - @Override protected LiquidFlowFlag flagOf(@NotNull Boolean value) { - return value ? LIQUID_FLOW_TRUE : LIQUID_FLOW_FALSE; + @Override public LiquidFlowFlag parse(@NotNull final String input) { + switch (input.toLowerCase()) { + case "true": + case "enabled": + case "allow": + return LIQUID_FLOW_ENABLED; + case "false": + case "disabled": + case "disallow": + return LIQUID_FLOW_DISABLED; + default: + return LIQUID_FLOW_DEFAULT; + } + } + + @Override public LiquidFlowFlag merge(@NotNull final FlowStatus newValue) { + if (newValue == FlowStatus.ENABLED || this.getValue() == FlowStatus.ENABLED) { + return LIQUID_FLOW_ENABLED; + } + return flagOf(newValue); + } + + @Override public String toString() { + return this.getValue().name().toLowerCase(); + } + + @Override public String getExample() { + return "true"; + } + + @Override protected LiquidFlowFlag flagOf(@NotNull final FlowStatus value) { + switch (value) { + case ENABLED: + return LIQUID_FLOW_ENABLED; + case DISABLED: + return LIQUID_FLOW_DISABLED; + default: + return LIQUID_FLOW_DEFAULT; + } + } + + @Override public Collection getTabCompletions() { + return Arrays.asList("true", "false", "default"); + } + + public enum FlowStatus { + ENABLED, DISABLED, DEFAULT } }