mirror of
https://github.com/TotalFreedomMC/TF-WorldGuardExtraFlagsPlugin.git
synced 2024-12-28 10:04:50 +00:00
Make glide have seprate forced value, closes #23
This commit is contained in:
parent
2df13dcc81
commit
3b55c219f8
4 changed files with 143 additions and 10 deletions
|
@ -7,12 +7,12 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityToggleGlideEvent;
|
import org.bukkit.event.entity.EntityToggleGlideEvent;
|
||||||
|
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
|
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
|
||||||
import net.goldtreeservers.worldguardextraflags.flags.Flags;
|
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.WorldGuardUtils;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ -30,11 +30,12 @@ public class EntityListenerOnePointNine implements Listener
|
||||||
|
|
||||||
ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
|
ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
|
||||||
|
|
||||||
State state = WorldGuardUtils.queryState(player, player.getWorld(), regions.getRegions(), Flags.GLIDE);
|
ForcedState state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.GLIDE);
|
||||||
if (state != null)
|
if (state != ForcedState.ALLOW)
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
player.setGliding(state == State.ALLOW);
|
|
||||||
|
player.setGliding(state == ForcedState.FORCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.sk89q.worldguard.protection.flags.StringFlag;
|
||||||
|
|
||||||
import net.goldtreeservers.worldguardextraflags.flags.data.SoundData;
|
import net.goldtreeservers.worldguardextraflags.flags.data.SoundData;
|
||||||
import net.goldtreeservers.worldguardextraflags.flags.helpers.BlockMaterialFlag;
|
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.PotionEffectFlag;
|
||||||
import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectTypeFlag;
|
import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectTypeFlag;
|
||||||
import net.goldtreeservers.worldguardextraflags.flags.helpers.SoundDataFlag;
|
import net.goldtreeservers.worldguardextraflags.flags.helpers.SoundDataFlag;
|
||||||
|
@ -63,7 +64,7 @@ public final class Flags
|
||||||
public final static SetFlag<Material> ALLOW_BLOCK_BREAK = new SetFlag<Material>("allow-block-break", new BlockMaterialFlag(null));
|
public final static SetFlag<Material> ALLOW_BLOCK_BREAK = new SetFlag<Material>("allow-block-break", new BlockMaterialFlag(null));
|
||||||
public final static SetFlag<Material> DENY_BLOCK_BREAK = new SetFlag<Material>("deny-block-break", new BlockMaterialFlag(null));
|
public final static SetFlag<Material> DENY_BLOCK_BREAK = new SetFlag<Material>("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);
|
public final static StateFlag CHUNK_UNLOAD = new StateFlag("chunk-unload", true);
|
||||||
|
|
||||||
|
|
|
@ -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<ForcedState>
|
||||||
|
{
|
||||||
|
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<ForcedState> 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,12 +7,12 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
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.protection.regions.ProtectedRegion;
|
||||||
import com.sk89q.worldguard.session.MoveType;
|
import com.sk89q.worldguard.session.MoveType;
|
||||||
import com.sk89q.worldguard.session.Session;
|
import com.sk89q.worldguard.session.Session;
|
||||||
|
|
||||||
import net.goldtreeservers.worldguardextraflags.flags.Flags;
|
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.WorldGuardUtils;
|
||||||
import net.goldtreeservers.worldguardextraflags.wg.wrappers.HandlerWrapper;
|
import net.goldtreeservers.worldguardextraflags.wg.wrappers.HandlerWrapper;
|
||||||
|
|
||||||
|
@ -47,24 +47,31 @@ public class GlideFlagHandler extends HandlerWrapper
|
||||||
@Override
|
@Override
|
||||||
public void initialize(Player player, Location current, ApplicableRegionSet set)
|
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);
|
this.handleValue(player, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
|
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> 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);
|
this.handleValue(player, state);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleValue(Player player, State state)
|
private void handleValue(Player player, ForcedState state)
|
||||||
{
|
{
|
||||||
if (state != null)
|
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)
|
if (player.isGliding() != value)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue