Search in sources :

Example 11 with RegionManager

use of com.sk89q.worldguard.protection.managers.RegionManager in project EliteMobs by MagmaGuy.

the class WorldGuardCompatibility method defineMinidungeon.

/**
 * Automatically creates a worldguard region protected as an EliteMobs minidungeon using two x y z vectors for the
 * locations of the diagonally opposed locations
 *
 * @param corner1
 * @param corner2
 */
public static void defineMinidungeon(Location corner1, Location corner2, Location anchorLocation, String schematicName, Minidungeon minidungeon) {
    try {
        RegionContainer regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer();
        RegionManager regionManager = regionContainer.get(BukkitAdapter.adapt(anchorLocation.getWorld()));
        BlockVector3 min = BlockVector3.at(corner1.getBlockX(), corner1.getBlockY(), corner1.getBlockZ());
        BlockVector3 max = BlockVector3.at(corner2.getBlockX(), corner2.getBlockY(), corner2.getBlockZ());
        ProtectedRegion region = new ProtectedCuboidRegion(schematicName.replace(".schem", ""), min, max);
        protectMinidungeonArea(region, minidungeon);
        regionManager.addRegion(region);
    } catch (Exception ex) {
        new WarningMessage("Failed to add Minidungeon WorldGuard zone!");
    }
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) FlagConflictException(com.sk89q.worldguard.protection.flags.registry.FlagConflictException)

Example 12 with RegionManager

use of com.sk89q.worldguard.protection.managers.RegionManager in project EliteMobs by MagmaGuy.

the class WorldGuardCompatibility method removeMinidungeon.

public static void removeMinidungeon(String schematicName, Location anchorLocation) {
    try {
        RegionContainer regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer();
        RegionManager regionManager = regionContainer.get(BukkitAdapter.adapt(anchorLocation.getWorld()));
        regionManager.removeRegion(schematicName.replace(".schem", ""));
    } catch (Exception ex) {
        new WarningMessage("Failed to remove Minidungeon WorldGuard zone!");
    }
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) FlagConflictException(com.sk89q.worldguard.protection.flags.registry.FlagConflictException)

Example 13 with RegionManager

use of com.sk89q.worldguard.protection.managers.RegionManager in project EliteMobs by MagmaGuy.

the class WorldGuardCompatibility method protectMinidungeonArea.

public static boolean protectMinidungeonArea(String regionName, Location location, Minidungeon minidungeon) {
    try {
        RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
        RegionManager regions = container.get(BukkitAdapter.adapt(location.getWorld()));
        ProtectedRegion protectedRegion = regions.getRegion(regionName);
        if (protectedRegion == null) {
            new WarningMessage("The region name picked did not exist!");
            return false;
        }
        protectMinidungeonArea(protectedRegion, minidungeon);
        return true;
    } catch (Exception ex) {
        new WarningMessage("Failed to protect region " + regionName + " !");
        return false;
    }
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) FlagConflictException(com.sk89q.worldguard.protection.flags.registry.FlagConflictException)

Example 14 with RegionManager

use of com.sk89q.worldguard.protection.managers.RegionManager in project MyPet by xXKeyleXx.

the class WorldGuardCustomFlagsHook method canHurt.

@Override
public boolean canHurt(Player attacker, Entity defender) {
    try {
        Location location = defender.getLocation();
        RegionManager mgr = wgPlugin.getRegionManager(location.getWorld());
        ApplicableRegionSet set = mgr.getApplicableRegions(location);
        StateFlag.State s = set.queryState(null, WorldGuardHook.DAMAGE_FLAG);
        return s == null || s == StateFlag.State.ALLOW;
    } catch (Throwable ignored) {
    }
    return true;
}
Also used : RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) Location(org.bukkit.Location) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet)

Example 15 with RegionManager

use of com.sk89q.worldguard.protection.managers.RegionManager in project MyPet by xXKeyleXx.

the class WorldGuardHook method canHurt.

@Override
public boolean canHurt(Player attacker, Entity defender) {
    if (customFlags) {
        try {
            Location location = defender.getLocation();
            RegionManager mgr = wgp.getRegionManager(location.getWorld());
            ApplicableRegionSet set = mgr.getApplicableRegions(location);
            StateFlag.State s;
            if (defender instanceof Animals) {
                s = set.queryState(null, DefaultFlag.DAMAGE_ANIMALS, DAMAGE_FLAG);
            } else {
                s = set.queryState(null, DAMAGE_FLAG);
            }
            return s == null || s == StateFlag.State.ALLOW;
        } catch (Throwable ignored) {
        }
    }
    return true;
}
Also used : Animals(org.bukkit.entity.Animals) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) Location(org.bukkit.Location) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet)

Aggregations

RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)26 ApplicableRegionSet (com.sk89q.worldguard.protection.ApplicableRegionSet)12 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)11 WarningMessage (com.magmaguy.elitemobs.utils.WarningMessage)6 FlagConflictException (com.sk89q.worldguard.protection.flags.registry.FlagConflictException)6 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)6 StateFlag (com.sk89q.worldguard.protection.flags.StateFlag)5 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)5 Nullable (javax.annotation.Nullable)5 Location (org.bukkit.Location)5 ProtectedCuboidRegion (com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion)4 BlockVector (com.sk89q.worldedit.BlockVector)3 DefaultDomain (com.sk89q.worldguard.domains.DefaultDomain)3 BuyRegion (me.wiefferink.areashop.regions.BuyRegion)3 RentRegion (me.wiefferink.areashop.regions.RentRegion)3 World (org.bukkit.World)3 Player (org.bukkit.entity.Player)3 OwnedLand (biz.princeps.landlord.util.OwnedLand)2 ArrayList (java.util.ArrayList)2 GeneralRegion (me.wiefferink.areashop.regions.GeneralRegion)2