diff --git a/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EntityListenerOnePointNine.java b/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EntityListenerOnePointNine.java index 97aefe7..d487559 100644 --- a/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EntityListenerOnePointNine.java +++ b/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EntityListenerOnePointNine.java @@ -7,12 +7,12 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityToggleGlideEvent; import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.flags.StateFlag.State; import lombok.Getter; import lombok.RequiredArgsConstructor; import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; import net.goldtreeservers.worldguardextraflags.flags.Flags; +import net.goldtreeservers.worldguardextraflags.flags.helpers.ForcedStateFlag.ForcedState; import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils; @RequiredArgsConstructor @@ -30,11 +30,12 @@ public class EntityListenerOnePointNine implements Listener ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation()); - State state = WorldGuardUtils.queryState(player, player.getWorld(), regions.getRegions(), Flags.GLIDE); - if (state != null) + ForcedState state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.GLIDE); + if (state != ForcedState.ALLOW) { event.setCancelled(true); - player.setGliding(state == State.ALLOW); + + player.setGliding(state == ForcedState.FORCE); } } } diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/Flags.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/Flags.java index 4adce72..b88ce54 100644 --- a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/Flags.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/Flags.java @@ -14,6 +14,7 @@ import com.sk89q.worldguard.protection.flags.StringFlag; import net.goldtreeservers.worldguardextraflags.flags.data.SoundData; import net.goldtreeservers.worldguardextraflags.flags.helpers.BlockMaterialFlag; +import net.goldtreeservers.worldguardextraflags.flags.helpers.ForcedStateFlag; import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectFlag; import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectTypeFlag; import net.goldtreeservers.worldguardextraflags.flags.helpers.SoundDataFlag; @@ -63,7 +64,7 @@ public final class Flags public final static SetFlag ALLOW_BLOCK_BREAK = new SetFlag("allow-block-break", new BlockMaterialFlag(null)); public final static SetFlag DENY_BLOCK_BREAK = new SetFlag("deny-block-break", new BlockMaterialFlag(null)); - public final static StateFlag GLIDE = new StateFlag("glide", false); + public final static ForcedStateFlag GLIDE = new ForcedStateFlag("glide"); public final static StateFlag CHUNK_UNLOAD = new StateFlag("chunk-unload", true); diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/ForcedStateFlag.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/ForcedStateFlag.java new file mode 100644 index 0000000..1ea5763 --- /dev/null +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/ForcedStateFlag.java @@ -0,0 +1,124 @@ +package net.goldtreeservers.worldguardextraflags.flags.helpers; + +import java.util.Collection; + +import com.sk89q.worldguard.protection.flags.Flag; +import com.sk89q.worldguard.protection.flags.FlagContext; +import com.sk89q.worldguard.protection.flags.InvalidFlagFormat; + +import net.goldtreeservers.worldguardextraflags.flags.helpers.ForcedStateFlag.ForcedState; + +public class ForcedStateFlag extends Flag +{ + public static enum ForcedState + { + ALLOW, + DENY, + FORCE + } + + public ForcedStateFlag(String name) + { + super(name); + } + + @Override + public ForcedState getDefault() + { + return ForcedState.ALLOW; + } + + @Override + public boolean hasConflictStrategy() + { + return true; + } + + @Override + public ForcedState chooseValue(Collection values) + { + //Order is the following: Deny > Force > Allow + ForcedState result = null; + + if (!values.isEmpty()) + { + for (ForcedState state : values) + { + if (state == ForcedState.DENY) + { + return ForcedState.DENY; + } + else if (state == ForcedState.FORCE) + { + result = ForcedState.FORCE; + } + else if (state == ForcedState.ALLOW) + { + if (result == null) + { + result = ForcedState.ALLOW; + } + } + } + } + + return result; + } + + + @Override + public ForcedState parseInput(FlagContext context) throws InvalidFlagFormat + { + String input = context.getUserInput(); + + if (input.equalsIgnoreCase("allow")) + { + return ForcedState.ALLOW; + } + else if (input.equalsIgnoreCase("force")) + { + return ForcedState.FORCE; + } + else if (input.equalsIgnoreCase("deny")) + { + return ForcedState.DENY; + } + else if (input.equalsIgnoreCase("none")) + { + return null; + } + else + { + throw new InvalidFlagFormat("Expected none/allow/force/deny but got '" + input + "'"); + } + } + + @Override + public ForcedState unmarshal(Object o) + { + String str = o.toString(); + + switch(str) + { + case "allow": + return ForcedState.ALLOW; + case "force": + return ForcedState.FORCE; + case "deny": + return ForcedState.DENY; + default: + return null; + } + } + + @Override + public Object marshal(ForcedState o) + { + if (o == null) + { + return null; + } + + return o.toString(); + } +} diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GlideFlagHandler.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GlideFlagHandler.java index aa573ac..4ca8166 100644 --- a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GlideFlagHandler.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GlideFlagHandler.java @@ -7,12 +7,12 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.flags.StateFlag.State; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.session.MoveType; import com.sk89q.worldguard.session.Session; import net.goldtreeservers.worldguardextraflags.flags.Flags; +import net.goldtreeservers.worldguardextraflags.flags.helpers.ForcedStateFlag.ForcedState; import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils; import net.goldtreeservers.worldguardextraflags.wg.wrappers.HandlerWrapper; @@ -47,24 +47,31 @@ public class GlideFlagHandler extends HandlerWrapper @Override public void initialize(Player player, Location current, ApplicableRegionSet set) { - State state = WorldGuardUtils.queryState(player, current.getWorld(), set.getRegions(), Flags.GLIDE); + ForcedState state = WorldGuardUtils.queryValue(player, current.getWorld(), set.getRegions(), Flags.GLIDE); + this.handleValue(player, state); } @Override public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set entered, Set exited, MoveType moveType) { - State state = WorldGuardUtils.queryState(player, to.getWorld(), toSet.getRegions(), Flags.GLIDE); + ForcedState state = WorldGuardUtils.queryValue(player, to.getWorld(), toSet.getRegions(), Flags.GLIDE); + this.handleValue(player, state); return true; } - private void handleValue(Player player, State state) + private void handleValue(Player player, ForcedState state) { if (state != null) { - boolean value = (state == State.ALLOW ? true : false); + if (state == ForcedState.ALLOW) + { + return; + } + + boolean value = (state == ForcedState.FORCE ? true : false); if (player.isGliding() != value) {