diff --git a/plugin.yml b/plugin.yml index 20756cab..510aa877 100644 --- a/plugin.yml +++ b/plugin.yml @@ -5,7 +5,7 @@ website: ${project.url} description: ${project.description} authors: [Madus, Cayorion, Ulumulu1510, MarkehMe, Brettflan, AlkorZ3] depend: [MassiveCore] -softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, LocalAreaChat, LWC, ChatManager, AuthMe, Vault, WorldEdit, WorldGuard] +softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, LocalAreaChat, LWC, ChatManager, AuthMe, Vault, WorldEdit, WorldGuard, WorldGuardExtraFlags] api-version: 1.13 permissions: # -------------------------------------------- # diff --git a/pom.xml b/pom.xml index 5ac3a876..9aabd6fd 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,11 @@ com.sk89q.worldguard worldguard-bukkit + + + net.goldtreeservers + worldguardextraflags + net.milkbowl.vault diff --git a/src/com/massivecraft/factions/engine/EngineFly.java b/src/com/massivecraft/factions/engine/EngineFly.java index e1cebb0e..5d59c895 100644 --- a/src/com/massivecraft/factions/engine/EngineFly.java +++ b/src/com/massivecraft/factions/engine/EngineFly.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.engine; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.CmdFactions; +import com.massivecraft.factions.integration.worldguard.EngineWorldGuard; import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; @@ -189,8 +190,8 @@ public class EngineFly extends Engine { throw new MassiveException().addMsg("You are not allowed to fly within " + locationFaction.getName() + " faction."); } - - // If the faction does not have the flag ... + + // If the location faction does not have the flag ... if (!locationFaction.getFlag(MFlag.getFlagFly())) { MFlag flag = MFlag.getFlagFly(); @@ -207,7 +208,8 @@ public class EngineFly extends Engine ex.addMessage(CmdFactions.get().cmdFactionsFlag.cmdFactionsFlagSet.getTemplate(false, true, mplayer.getSender())); } // ... otherwise ... - else { + else + { // .. tell them to have someone else edit it ... ex.addMsg("You can ask a faction admin to change the flag."); } @@ -245,6 +247,12 @@ public class EngineFly extends Engine } throw ex; } + + // If the WorldGuard Region doesn't allows the player to fly... + if (!EngineWorldGuard.isFlyAllowed(mplayer)) + { + throw new MassiveException().addMsg("You are not allowed to fly within this WorldGuard region."); + } } public static void deactivateForPlayer(Player player) diff --git a/src/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java b/src/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java index fd8f7198..a35d7532 100644 --- a/src/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java +++ b/src/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java @@ -6,15 +6,22 @@ import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.event.EventFactionsChunksChange; import com.massivecraft.massivecore.Engine; import com.massivecraft.massivecore.ps.PS; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.Flags; +import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import com.sk89q.worldguard.protection.regions.RegionQuery; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -61,7 +68,7 @@ public class EngineWorldGuard extends Engine // Only do this for players if (player == null) return; - LocalPlayer wrapperPlayer = WorldGuardPlugin.inst() .wrapPlayer(player); + LocalPlayer wrapperPlayer = WorldGuardPlugin.inst().wrapPlayer(player); if ( ! MConf.get().worldguardCheckWorldsEnabled.contains(player)) return; @@ -123,5 +130,25 @@ public class EngineWorldGuard extends Engine return overlapRegions; } - + + + + public static boolean isFlyAllowed(MPlayer mplayer) + { + // Skip checks if the configuration has worldguardCheckEnabled disabled + if ( ! MConf.get().worldguardCheckEnabled) return(true); + + LocalPlayer wrapperPlayer = WorldGuardPlugin.inst().wrapPlayer(mplayer.getPlayer()); + RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); + ApplicableRegionSet set = query.getApplicableRegions(BukkitAdapter.adapt(mplayer.getPlayer().getLocation())); + + if( set.queryState( wrapperPlayer, net.goldtreeservers.worldguardextraflags.flags.Flags.FLY) == StateFlag.State.DENY) + { + return(false); + } + else + { + return(true); + } + } }