mirror of
https://github.com/TotalFreedomMC/TF-WorldGuardExtraFlagsPlugin.git
synced 2024-12-28 10:04:50 +00:00
Made block-place & block-break flags work smarted, changed little things
This commit is contained in:
parent
e3b75533ff
commit
b8064708d6
5 changed files with 109 additions and 43 deletions
|
@ -1,5 +1,7 @@
|
|||
package net.goldtreeservers.worldguardextraflags;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.entity.EntityToggleGlideEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
@ -17,7 +19,6 @@ import com.sk89q.worldguard.protection.flags.StateFlag;
|
|||
import com.sk89q.worldguard.protection.flags.StringFlag;
|
||||
|
||||
import net.goldtreeservers.worldguardextraflags.flags.BlockedEffectsFlag;
|
||||
import net.goldtreeservers.worldguardextraflags.flags.CaseForcedStringFlag;
|
||||
import net.goldtreeservers.worldguardextraflags.flags.CommandOnEntryFlag;
|
||||
import net.goldtreeservers.worldguardextraflags.flags.CommandOnExitFlag;
|
||||
import net.goldtreeservers.worldguardextraflags.flags.ConsoleCommandOnEntryFlag;
|
||||
|
@ -27,6 +28,7 @@ import net.goldtreeservers.worldguardextraflags.flags.FlyFlag;
|
|||
import net.goldtreeservers.worldguardextraflags.flags.GiveEffectsFlag;
|
||||
import net.goldtreeservers.worldguardextraflags.flags.GlideFlag;
|
||||
import net.goldtreeservers.worldguardextraflags.flags.GodmodeFlag;
|
||||
import net.goldtreeservers.worldguardextraflags.flags.MaterialFlag;
|
||||
import net.goldtreeservers.worldguardextraflags.flags.PlaySoundsFlag;
|
||||
import net.goldtreeservers.worldguardextraflags.flags.PotionEffectFlag;
|
||||
import net.goldtreeservers.worldguardextraflags.flags.PotionEffectTypeFlag;
|
||||
|
@ -36,6 +38,7 @@ import net.goldtreeservers.worldguardextraflags.flags.TeleportOnExitFlag;
|
|||
import net.goldtreeservers.worldguardextraflags.flags.WalkSpeedFlag;
|
||||
import net.goldtreeservers.worldguardextraflags.listeners.BlockListener;
|
||||
import net.goldtreeservers.worldguardextraflags.listeners.EntityListener;
|
||||
import net.goldtreeservers.worldguardextraflags.listeners.EntityListenerOnePointNine;
|
||||
import net.goldtreeservers.worldguardextraflags.listeners.EssentialsListener;
|
||||
import net.goldtreeservers.worldguardextraflags.listeners.PlayerListener;
|
||||
import net.goldtreeservers.worldguardextraflags.listeners.WorldEditListener;
|
||||
|
@ -74,21 +77,26 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
|
|||
public final static StateFlag mythicMobsEggs = new StateFlag("mythicmobs-eggs", true);
|
||||
public final static StateFlag frostwalker = new StateFlag("frostwalker", true);
|
||||
public final static StateFlag netherPortals = new StateFlag("nether-portals", true);
|
||||
public final static SetFlag<String> allowBlockPlace = new SetFlag<String>("allow-block-place", new CaseForcedStringFlag(null, true));
|
||||
public final static SetFlag<String> denyBlockPlace = new SetFlag<String>("deny-block-place", new CaseForcedStringFlag(null, true));
|
||||
public final static SetFlag<String> allowBlockBreak = new SetFlag<String>("allow-block-break", new CaseForcedStringFlag(null, true));
|
||||
public final static SetFlag<String> denyBlockBreak = new SetFlag<String>("deny-block-break", new CaseForcedStringFlag(null, true));
|
||||
public final static SetFlag<Material> allowBlockPlace = new SetFlag<Material>("allow-block-place", new MaterialFlag(null));
|
||||
public final static SetFlag<Material> denyBlockPlace = new SetFlag<Material>("deny-block-place", new MaterialFlag(null));
|
||||
public final static SetFlag<Material> allowBlockBreak = new SetFlag<Material>("allow-block-break", new MaterialFlag(null));
|
||||
public final static SetFlag<Material> denyBlockBreak = new SetFlag<Material>("deny-block-break", new MaterialFlag(null));
|
||||
public final static StateFlag glide = new StateFlag("glide", false);
|
||||
|
||||
public WorldGuardExtraFlagsPlugin()
|
||||
{
|
||||
WorldGuardExtraFlagsPlugin.plugin = this;
|
||||
|
||||
String a = getServer().getClass().getPackage().getName();
|
||||
String version = a.substring(a.lastIndexOf('.') + 1);
|
||||
if (version.equalsIgnoreCase("v1_10_R1") || version.equalsIgnoreCase("v1_9_R1"))
|
||||
try
|
||||
{
|
||||
WorldGuardExtraFlagsPlugin.supportFrostwalker = true;
|
||||
if (Material.FROSTED_ICE != null) //LOL, Just making it look nice xD
|
||||
{
|
||||
WorldGuardExtraFlagsPlugin.supportFrostwalker = true;
|
||||
}
|
||||
}
|
||||
catch (NoSuchFieldError ignored)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,6 +154,18 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
|
|||
this.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new BlockListener(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new EntityListener(), this);
|
||||
|
||||
try
|
||||
{
|
||||
if (EntityToggleGlideEvent.class != null) //LOL, Just making it look nice xD
|
||||
{
|
||||
this.getServer().getPluginManager().registerEvents(new EntityListenerOnePointNine(), this);
|
||||
}
|
||||
}
|
||||
catch(NoClassDefFoundError ignored)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Plugin essentialsPlugin = this.getServer().getPluginManager().getPlugin("Essentials");
|
||||
if (essentialsPlugin != null)
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package net.goldtreeservers.worldguardextraflags.flags;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.FlagContext;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
|
||||
public class MaterialFlag extends Flag<Material>
|
||||
{
|
||||
public MaterialFlag(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object marshal(Material o)
|
||||
{
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material parseInput(FlagContext context) throws InvalidFlagFormat
|
||||
{
|
||||
return Material.getMaterial(context.getUserInput().trim());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material unmarshal(Object o)
|
||||
{
|
||||
return Material.getMaterial(o.toString());
|
||||
}
|
||||
}
|
|
@ -63,15 +63,15 @@ public class BlockListener implements Listener
|
|||
{
|
||||
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
|
||||
|
||||
Set<String> state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.allowBlockPlace);
|
||||
if (state != null && state.contains(block.getType().toString().toUpperCase()))
|
||||
Set<Material> state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.allowBlockPlace);
|
||||
if (state != null && state.contains(block.getType()))
|
||||
{
|
||||
event.setResult(Result.ALLOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
Set<String> state2 = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.denyBlockPlace);
|
||||
if (state2 != null && state2.contains(block.getType().toString().toUpperCase()))
|
||||
Set<Material> state2 = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.denyBlockPlace);
|
||||
if (state2 != null && state2.contains(block.getType()))
|
||||
{
|
||||
event.setResult(Result.DENY);
|
||||
return;
|
||||
|
@ -105,15 +105,15 @@ public class BlockListener implements Listener
|
|||
{
|
||||
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
|
||||
|
||||
Set<String> state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.allowBlockBreak);
|
||||
if (state != null && state.contains(block.getType().toString().toUpperCase()))
|
||||
Set<Material> state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.allowBlockBreak);
|
||||
if (state != null && state.contains(block.getType()))
|
||||
{
|
||||
event.setResult(Result.ALLOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
Set<String> state2 = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.denyBlockBreak);
|
||||
if (state2 != null && state2.contains(block.getType().toString().toUpperCase()))
|
||||
Set<Material> state2 = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.denyBlockBreak);
|
||||
if (state2 != null && state2.contains(block.getType()))
|
||||
{
|
||||
event.setResult(Result.DENY);
|
||||
return;
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package net.goldtreeservers.worldguardextraflags.listeners;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityToggleGlideEvent;
|
||||
import org.bukkit.event.world.PortalCreateEvent;
|
||||
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
|
@ -30,27 +27,4 @@ public class EntityListener implements Listener
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityToggleGlideEvent(EntityToggleGlideEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof LivingEntity)
|
||||
{
|
||||
if (event.getEntity() instanceof Player)
|
||||
{
|
||||
if (WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().hasBypass((Player)event.getEntity(), ((Player)event.getEntity()).getWorld()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(event.getEntity().getLocation());
|
||||
State allowGliding = regions.queryValue(event.getEntity() instanceof Player ? WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer((Player)event.getEntity()) : null, WorldGuardExtraFlagsPlugin.glide);
|
||||
if (allowGliding != null)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
((LivingEntity)event.getEntity()).setGliding(allowGliding == State.ALLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package net.goldtreeservers.worldguardextraflags.listeners;
|
||||
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
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 net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
|
||||
|
||||
public class EntityListenerOnePointNine implements Listener
|
||||
{
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityToggleGlideEvent(EntityToggleGlideEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof LivingEntity)
|
||||
{
|
||||
if (event.getEntity() instanceof Player)
|
||||
{
|
||||
if (WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().hasBypass((Player)event.getEntity(), ((Player)event.getEntity()).getWorld()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(event.getEntity().getLocation());
|
||||
State allowGliding = regions.queryValue(event.getEntity() instanceof Player ? WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer((Player)event.getEntity()) : null, WorldGuardExtraFlagsPlugin.glide);
|
||||
if (allowGliding != null)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
((LivingEntity)event.getEntity()).setGliding(allowGliding == State.ALLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue