Search in sources :

Example 1 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.

the class BlockedPotionsListener method onItemInteract.

@EventHandler
public void onItemInteract(UseItemEvent event) {
    BukkitWorldConfiguration wcfg = getWorldConfig(event.getWorld());
    ItemStack item = event.getItemStack();
    if (item.getType() != Material.POTION && item.getType() != Material.SPLASH_POTION && item.getType() != Material.LINGERING_POTION) {
        return;
    }
    if (!wcfg.blockPotions.isEmpty()) {
        PotionEffectType blockedEffect = null;
        PotionMeta meta;
        if (item.getItemMeta() instanceof PotionMeta) {
            meta = ((PotionMeta) item.getItemMeta());
        } else {
            // ok...?
            return;
        }
        // Find the first blocked effect
        PotionEffectType baseEffect = meta.getBasePotionData().getType().getEffectType();
        if (wcfg.blockPotions.contains(baseEffect)) {
            blockedEffect = baseEffect;
        }
        if (blockedEffect == null && meta.hasCustomEffects()) {
            for (PotionEffect effect : meta.getCustomEffects()) {
                if (wcfg.blockPotions.contains(effect.getType())) {
                    blockedEffect = effect.getType();
                    break;
                }
            }
        }
        if (blockedEffect != null) {
            Player player = event.getCause().getFirstPlayer();
            if (player != null) {
                if (getPlugin().hasPermission(player, "worldguard.override.potions")) {
                    if (wcfg.blockPotionsAlways && (item.getType() == Material.SPLASH_POTION || item.getType() == Material.LINGERING_POTION)) {
                        player.sendMessage(ChatColor.RED + "Sorry, potions with " + blockedEffect.getName() + " can't be thrown, " + "even if you have a permission to bypass it, " + "due to limitations (and because overly-reliable potion blocking is on).");
                        event.setCancelled(true);
                    }
                } else {
                    player.sendMessage(ChatColor.RED + "Sorry, potions with " + blockedEffect.getName() + " are presently disabled.");
                    event.setCancelled(true);
                }
            } else {
                event.setCancelled(true);
            }
        }
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) PotionMeta(org.bukkit.inventory.meta.PotionMeta) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 2 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.

the class ChestProtectionListener method onUseBlock.

@EventHandler(ignoreCancelled = true)
public void onUseBlock(final UseBlockEvent event) {
    final Player player = event.getCause().getFirstPlayer();
    final BukkitWorldConfiguration wcfg = getWorldConfig(event.getWorld());
    // Early guard
    if (!wcfg.signChestProtection) {
        return;
    }
    if (player != null) {
        final LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
        event.filter(target -> {
            if (wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation()), localPlayer)) {
                sendMessage(event, player, ChatColor.DARK_RED + "This chest is protected.");
                return false;
            }
            return true;
        }, true);
    } else {
        event.filter(target -> !wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation())));
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 3 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration 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)

Example 4 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.

the class Cause method isKnown.

/**
 * Return whether a cause is known. This method will return false if
 * the list of causes is empty or the root cause is really not known
 * (e.g. primed TNT).
 *
 * @return true if known
 */
public boolean isKnown() {
    Object object = getRootCause();
    if (object == null) {
        return false;
    }
    if (object instanceof TNTPrimed || object instanceof Vehicle) {
        if (!PaperLib.isPaper()) {
            return false;
        }
        Entity entity = (Entity) object;
        BukkitWorldConfiguration config = WorldGuardPlugin.inst().getConfigManager().get(entity.getWorld().getName());
        if (!config.usePaperEntityOrigin || entity.getOrigin() == null) {
            return false;
        }
    }
    return true;
}
Also used : Vehicle(org.bukkit.entity.Vehicle) Entity(org.bukkit.entity.Entity) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) TNTPrimed(org.bukkit.entity.TNTPrimed)

Example 5 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardEntityListener method onExplosionPrime.

/*
     * Called on explosion prime
     */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onExplosionPrime(ExplosionPrimeEvent event) {
    ConfigurationManager cfg = getConfig();
    Entity ent = event.getEntity();
    if (cfg.activityHaltToggle) {
        ent.remove();
        event.setCancelled(true);
        return;
    }
    BukkitWorldConfiguration wcfg = getWorldConfig(ent.getWorld());
    if (event.getEntityType() == EntityType.WITHER) {
        if (wcfg.blockWitherExplosions) {
            event.setCancelled(true);
            return;
        }
    } else if (event.getEntityType() == EntityType.WITHER_SKULL) {
        if (wcfg.blockWitherSkullExplosions) {
            event.setCancelled(true);
            return;
        }
    } else if (event.getEntityType() == EntityType.FIREBALL) {
        if (wcfg.blockFireballExplosions) {
            event.setCancelled(true);
            return;
        }
    } else if (event.getEntityType() == EntityType.CREEPER) {
        if (wcfg.blockCreeperExplosions) {
            event.setCancelled(true);
            return;
        }
    } else if (event.getEntityType() == EntityType.PRIMED_TNT || event.getEntityType() == EntityType.MINECART_TNT) {
        if (wcfg.blockTNTExplosions) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)12 EventHandler (org.bukkit.event.EventHandler)9 Player (org.bukkit.entity.Player)7 LocalPlayer (com.sk89q.worldguard.LocalPlayer)5 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)4 Entity (org.bukkit.entity.Entity)4 Block (org.bukkit.block.Block)3 HumanEntity (org.bukkit.entity.HumanEntity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 TNTPrimed (org.bukkit.entity.TNTPrimed)2 PotionEffect (org.bukkit.potion.PotionEffect)2 PotionEffectType (org.bukkit.potion.PotionEffectType)2 BukkitPlayer (com.sk89q.worldguard.bukkit.BukkitPlayer)1 ApplicableRegionSet (com.sk89q.worldguard.protection.ApplicableRegionSet)1 DelayedRegionOverlapAssociation (com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation)1 RegionQuery (com.sk89q.worldguard.protection.regions.RegionQuery)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Arrow (org.bukkit.entity.Arrow)1