Search in sources :

Example 1 with DelayedRegionOverlapAssociation

use of com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation in project WorldGuard by EngineHub.

the class AbstractListener method createRegionAssociable.

protected RegionAssociable createRegionAssociable(Cause cause) {
    Object rootCause = cause.getRootCause();
    if (!cause.isKnown()) {
        return Associables.constant(Association.NON_MEMBER);
    } else if (rootCause instanceof Player) {
        return getPlugin().wrapPlayer((Player) rootCause);
    } else if (rootCause instanceof OfflinePlayer) {
        return getPlugin().wrapOfflinePlayer((OfflinePlayer) rootCause);
    } else if (rootCause instanceof Entity) {
        RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
        final Entity entity = (Entity) rootCause;
        BukkitWorldConfiguration config = getWorldConfig(entity.getWorld());
        Location loc;
        if (PaperLib.isPaper() && config.usePaperEntityOrigin) {
            loc = entity.getOrigin();
            if (loc == null) {
                loc = entity.getLocation();
            }
        } else {
            loc = entity.getLocation();
        }
        return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(loc), config.useMaxPriorityAssociation);
    } else if (rootCause instanceof Block) {
        RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
        Location loc = ((Block) rootCause).getLocation();
        return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(loc), getWorldConfig(loc.getWorld()).useMaxPriorityAssociation);
    } else {
        return Associables.constant(Association.NON_MEMBER);
    }
}
Also used : Entity(org.bukkit.entity.Entity) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) BukkitPlayer(com.sk89q.worldguard.bukkit.BukkitPlayer) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) OfflinePlayer(org.bukkit.OfflinePlayer) Block(org.bukkit.block.Block) DelayedRegionOverlapAssociation(com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation) Location(org.bukkit.Location)

Aggregations

LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 BukkitPlayer (com.sk89q.worldguard.bukkit.BukkitPlayer)1 BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)1 DelayedRegionOverlapAssociation (com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation)1 RegionQuery (com.sk89q.worldguard.protection.regions.RegionQuery)1 Location (org.bukkit.Location)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Block (org.bukkit.block.Block)1 Entity (org.bukkit.entity.Entity)1 Player (org.bukkit.entity.Player)1