com.sk89q.worldguard.internal.platform.WorldGuardPlatform Java Examples

The following examples show how to use com.sk89q.worldguard.internal.platform.WorldGuardPlatform. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
Source File: Radiation.java    From CraftserveRadiation with Apache License 2.0 4 votes vote down vote up
default RegionContainer getRegionContainer() {
    WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
    return platform != null ? platform.getRegionContainer() : null;
}