com.sk89q.worldguard.WorldGuard Java Examples

The following examples show how to use com.sk89q.worldguard.WorldGuard. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegionCondition.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Boolean execute(String playerID) {
    Player player = PlayerConverter.getPlayer(playerID);
    WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform();
    RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(player.getWorld()));
    if (manager == null) {
        return false;
    }
    ProtectedRegion region = manager.getRegion(name);
    ApplicableRegionSet set = manager.getApplicableRegions(BlockVector3.at(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()));
    for (ProtectedRegion compare : set) {
        if (compare.equals(region))
            return true;
    }
    return false;
}
 
Example #2
Source File: RegionObjective.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Return true if location is inside region
 *
 * @param loc Location to Check
 * @return boolean True if in region
 */
private boolean isInsideRegion(Location loc) {
    if (loc == null || loc.getWorld() == null) {
        return false;
    }

    WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform();
    RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
    if (manager == null) {
        return false;
    }

    ProtectedRegion region = manager.getRegion(name);
    if (region == null) {
        return false;
    }

    return region.contains(BukkitAdapter.asBlockVector(loc));
}
 
Example #3
Source File: NPCRegionCondition.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Boolean execute(String playerID) throws QuestRuntimeException {
    NPC npc = CitizensAPI.getNPCRegistry().getById(ID);
    if (npc == null) {
        throw new QuestRuntimeException("NPC with ID " + ID + " does not exist");
    }
    Entity npcEntity = npc.getEntity();
    if (npcEntity == null) return false;

    Player player = PlayerConverter.getPlayer(playerID);
    WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform();
    RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(player.getWorld()));
    if (manager == null) {
        return false;
    }
    ApplicableRegionSet set = manager.getApplicableRegions(BlockVector3.at(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()));

    for (ProtectedRegion compare : set) {
        if (compare.equals(region))
            return true;
    }
    return false;
}
 
Example #4
Source File: HookWorldGuard_V7_0.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
public static boolean allowsTagging(Location location) {
    WorldGuard api = getAPI();
    WorldGuardPlatform platform = api.getPlatform();
    RegionContainer container = platform.getRegionContainer();
    RegionQuery query = container.createQuery();
    
    if(NO_TAGGING_FLAG instanceof BooleanFlag) {
        BooleanFlag noTaggingFlag = (BooleanFlag) NO_TAGGING_FLAG;
        com.sk89q.worldedit.util.Location weLocation = BukkitAdapter.adapt(location);
        
        Boolean value = query.queryValue(weLocation, null, noTaggingFlag);
        return (value == null || !value);
    }
    
    return true;
}
 
Example #5
Source File: HookWorldGuard_V7_0.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
public static boolean allowsMobCombat(Location location) {
    WorldGuard api = getAPI();
    WorldGuardPlatform platform = api.getPlatform();
    RegionContainer container = platform.getRegionContainer();
    
    RegionQuery query = container.createQuery();
    com.sk89q.worldedit.util.Location weLocation = BukkitAdapter.adapt(location);
    
    if(MOB_COMBAT_FLAG instanceof StateFlag) {
        StateFlag mobCombatFlag = (StateFlag) MOB_COMBAT_FLAG;
        State state = query.queryState(weLocation, null, mobCombatFlag);
        return (state != State.DENY);
    }
    
    return true;
}
 
Example #6
Source File: WorldGuardApi.java    From ClaimChunk with MIT License 6 votes vote down vote up
static boolean _init(ClaimChunk claimChunk) {
    FLAG_CHUNK_CLAIM = new StateFlag(CHUNK_CLAIM_FLAG_NAME,
            claimChunk.chConfig().getBool("worldguard", "allowClaimsInRegionsByDefault"));

    try {
        FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
        registry.register(FLAG_CHUNK_CLAIM);
        return true;
    } catch (FlagConflictException ignored) {
        Utils.err("Flag \"%s\" is already registered with WorldGuard. Another plugin conflicts with us!", CHUNK_CLAIM_FLAG_NAME);
    } catch (Exception e) {
        Utils.err("Failed to initialize WorldGuard support");
        e.printStackTrace();
    }
    return false;
}
 
Example #7
Source File: WorldGuardHook.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
public Collection<? extends Region> getRegionsAt_i(@Nullable final Location l) {
	final ArrayList<Region> r = new ArrayList<>();
	
	if (l == null) // Working around possible cause of issue #280
		return Collections.emptyList();
	if (l.getWorld() == null)
		return Collections.emptyList();
	
	WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
	RegionManager manager = platform.getRegionContainer().get(BukkitAdapter.adapt(l.getWorld()));
	if (manager == null)
		return r;
	ApplicableRegionSet applicable = manager.getApplicableRegions(BukkitAdapter.asBlockVector(l));
	if (applicable == null)
		return r;
	for (ProtectedRegion region : applicable)
		r.add(new WorldGuardRegion(l.getWorld(), region));
	return r;
}
 
Example #8
Source File: WorldGuard7FAWEHook.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
public Collection<? extends Region> getRegionsAt_i(@Nullable final Location l) {
    final ArrayList<Region> r = new ArrayList<>();
    
    if (l == null) // Working around possible cause of issue #280
        return Collections.emptyList();
    if (l.getWorld() == null)
        return Collections.emptyList();
    RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
    if (query == null)
        return r;
    ApplicableRegionSet applicable = query.getApplicableRegions(BukkitAdapter.adapt(l));
    if (applicable == null)
        return r;
    final Iterator<ProtectedRegion> i = applicable.iterator();
    while (i.hasNext())
        r.add(new WorldGuardRegion(l.getWorld(), i.next()));
    return r;
}
 
Example #9
Source File: RadiationPlugin.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoad() {
    FlagRegistry flagRegistry = WorldGuard.getInstance().getFlagRegistry();
    if (flagRegistry == null) {
        throw new IllegalStateException("Flag registry is not set! Plugin must shut down...");
    }

    this.radiationFlag = this.getOrCreateRadiationFlag(flagRegistry);
}
 
Example #10
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static WorldGuardPlatform getWorldGuard() {
    final Plugin plugin = uSkyBlock.getInstance().getServer().getPluginManager().getPlugin("WorldGuard");
    if (!(plugin instanceof WorldGuardPlugin)) {
        return null;
    }
    return WorldGuard.getInstance().getPlatform();
}
 
Example #11
Source File: HookWorldGuard_V7_0.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
public static boolean allowsPVP(Location location) {
    WorldGuard api = getAPI();
    WorldGuardPlatform platform = api.getPlatform();
    RegionContainer container = platform.getRegionContainer();
    RegionQuery query = container.createQuery();

    com.sk89q.worldedit.util.Location weLocation = BukkitAdapter.adapt(location);
    StateFlag.State state = query.queryState(weLocation, null, Flags.PVP);
    return (state != StateFlag.State.DENY);
}
 
Example #12
Source File: WorldGuardSevenCommunicator.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@Override
public void onEnable(Plugin plugin) throws Exception
{
	this.sessionManager = new SessionManagerWrapper(WorldGuard.getInstance().getPlatform().getSessionManager());
	this.regionContainer = new RegionContainerWrapper();
	
	WorldGuardCommunicator.super.onEnable(plugin);
}
 
Example #13
Source File: WorldEditFlagHandler.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException
{
	ApplicableRegionSet regions = WorldGuard.getInstance().getPlatform().getRegionContainer().get(this.weWorld).getApplicableRegions(location);

	State state = WorldGuardUtils.queryState(this.player, this.world, regions.getRegions(), Flags.WORLDEDIT);
	if (state != State.DENY)
	{
		return super.setBlock(location, block);
	}
	
	return false;
}
 
Example #14
Source File: WorldGuardHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Region getRegion_i(final World world, final String name) {
	WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
	ProtectedRegion region = platform.getRegionContainer().get(BukkitAdapter.adapt(world)).getRegion(name);
	if (region != null)
		return new WorldGuardRegion(world, region);
	return null;
}
 
Example #15
Source File: WorldGuardHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void deserialize(final Fields fields) throws StreamCorruptedException, NotSerializableException {
	final String r = fields.getAndRemoveObject("region", String.class);
	fields.setFields(this);
	
	WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
	ProtectedRegion region = platform.getRegionContainer().get(BukkitAdapter.adapt(world)).getRegion(r);
	if (region == null)
		throw new StreamCorruptedException("Invalid region " + r + " in world " + world);
	this.region = region;
}
 
Example #16
Source File: WorldGuardHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canBuild_i(Player p, Location l) {
	if (p.hasPermission("worldguard.region.bypass." + l.getWorld().getName()))
		return true; // Build access always granted by permission
	WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
	RegionQuery query = platform.getRegionContainer().createQuery();
	return query.testBuild(BukkitAdapter.adapt(l), plugin.wrapPlayer(p));
}
 
Example #17
Source File: WorldGuard7FAWEHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void deserialize(final Fields fields) throws StreamCorruptedException, NotSerializableException {
    final String r = fields.getAndRemoveObject("region", String.class);
    fields.setFields(this);
    RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
    final ProtectedRegion region = regionManager.getRegion(r);
    if (region == null)
        throw new StreamCorruptedException("Invalid region " + r + " in world " + world);
    this.region = region;
}
 
Example #18
Source File: WorldGuardIntegration.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void load() {
    FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
    try {
        // create a flag with the name "my-custom-flag", defaulting to true
        registry.register(this.createFlag);
        registry.register(this.tradeFlag);
        plugin.getLogger().info(ChatColor.GREEN + getName() + " flags register successfully.");
        Util.debugLog("Success register " + getName() + " flags.");
    } catch (FlagConflictException e) {
        e.printStackTrace();
    }
}
 
Example #19
Source File: BridgeImpl.java    From TabooLib with MIT License 5 votes vote down vote up
private RegionManager worldguardRegionManager(World world) {
    if (WorldGuardPlugin.inst().getDescription().getVersion().startsWith("7")) {
        return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
    } else {
        try {
            return (RegionManager) getRegionManager.invoke(WorldGuardPlugin.inst(), world);
        } catch (Throwable t) {
            t.printStackTrace();
        }
        return null;
    }
}
 
Example #20
Source File: WorldGuardSupport.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
public static boolean a(Location loc){
		WorldGuard wGuard = WorldGuard.getInstance();
		for (ProtectedRegion k : wGuard.getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld())).getRegions().values()) {
			if (k.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
				if (k.getFlag(Flags.PVP) == com.sk89q.worldguard.protection.flags.StateFlag.State.DENY)
					return false;
			}
		}
	return true;
}
 
Example #21
Source File: WorldGuardSupport.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
public static boolean canExplode(Location loc){
	WorldGuard wGuard = WorldGuard.getInstance();
	for (ProtectedRegion k : wGuard.getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld())).getRegions().values()) {
		if (k.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
			if (k.getFlag(Flags.OTHER_EXPLOSION) == com.sk89q.worldguard.protection.flags.StateFlag.State.DENY)
				return false;
		}
	}
	return true;
}
 
Example #22
Source File: WorldGuardCompat.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
public boolean test(Entity entity){
    try {
        RegionQuery rq = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
        return !(rq.testState(BukkitAdapter.adapt(entity.getLocation()), null, ENTITY_FLAG));
    }catch (NullPointerException e){
        return false;
    }
}
 
Example #23
Source File: WorldGuardApi.java    From ClaimChunk with MIT License 5 votes vote down vote up
static boolean _isAllowedClaim(ClaimChunk claimChunk, Chunk chunk) {
    try {
        // Generate a region in the given chunk to get all intersecting regions
        int bx = chunk.getX() << 4;
        int bz = chunk.getZ() << 4;
        BlockVector3 pt1 = BlockVector3.at(bx, 0, bz);
        BlockVector3 pt2 = BlockVector3.at(bx + 15, 256, bz + 15);
        ProtectedCuboidRegion region = new ProtectedCuboidRegion("_", pt1, pt2);
        RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(chunk.getWorld()));

        // No regions in this world, claiming should be determined by the config
        if (regionManager == null) {
            return claimChunk.chConfig().getBool("worldguard", "allowClaimingInNonGuardedWorlds");
        }

        // If any regions in the given chunk deny chunk claiming, false is returned
        for (ProtectedRegion regionIn : regionManager.getApplicableRegions(region)) {
            StateFlag.State flag = regionIn.getFlag(FLAG_CHUNK_CLAIM);
            if (flag == StateFlag.State.DENY) return false;
        }

        // No objections
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    // An error occurred, better to be on the safe side so false is returned
    return false;
}
 
Example #24
Source File: WorldGuard7FAWEHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canBuild_i(final Player p, final Location l) {
    if (p.hasPermission("worldguard.region.bypass." + l.getWorld().getName())) return true;
    RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
    LocalPlayer player = WorldGuardPlugin.inst().wrapPlayer(p);
    return query.testState(BukkitAdapter.adapt(l), player, Flags.BUILD);
}
 
Example #25
Source File: WorldGuardCompat.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
public void registerFlag(){
    FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
    try {
        registry.register(ENTITY_FLAG);
        sm.getLogger().info("Registered WorldGuard region flag.");
    } catch (FlagConflictException e) {
        sm.getLogger().warning("A conflict occurred while trying to register the WorldGuard flag.");
        e.printStackTrace();
    }
}
 
Example #26
Source File: WorldGuard7FAWEHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Region getRegion_i(final World world, final String name) {
    RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
    final ProtectedRegion r = manager.getRegion(name);
    if (r != null)
        return new WorldGuardRegion(world, r);
    return null;
}
 
Example #27
Source File: WorldGuardIntegration.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canTradeShopHere(@NotNull Player player, @NotNull Location location) {
    LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
    com.sk89q.worldedit.util.Location wgLoc = BukkitAdapter.adapt(location);
    boolean canBypass =
            WorldGuard.getInstance()
                    .getPlatform()
                    .getSessionManager()
                    .hasBypass(localPlayer, BukkitAdapter.adapt(location.getWorld()));
    if (canBypass) {
        Util.debugLog(
                "Player "
                        + player.getName()
                        + " bypassing the protection checks, because player have bypass permission in WorldGuard");
        return true;
    }
    RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
    RegionQuery query = container.createQuery();
    if (query.getApplicableRegions(wgLoc).getRegions().isEmpty()) {
        return !whiteList;
    }
    for (WorldGuardFlags flag : tradeFlags) {
        switch (flag) {
            case BUILD:
                if (!query.testState(wgLoc, localPlayer, Flags.BUILD)) {
                    return false;
                }

                break;
            case FLAG:
                if (!query.testState(wgLoc, localPlayer, this.tradeFlag)) {
                    return false;
                }
                break;
            case CHEST_ACCESS:
                if (!query.testState(wgLoc, localPlayer, Flags.CHEST_ACCESS)) {
                    return false;
                }
                break;
            case INTERACT:
                if (!query.testState(wgLoc, localPlayer, Flags.INTERACT)) {
                    return false;
                }
                break;
        }
    }
    return true;
}
 
Example #28
Source File: WorldGuardHandler7_beta_1.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
	return Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), flagName);
}
 
Example #29
Source File: WorldGuardHandler7_beta_1.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public RegionManager getRegionManager(World world) {
	return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
}
 
Example #30
Source File: FastAsyncWorldEditWorldGuardHandler.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
	return Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), flagName);
}