Search in sources :

Example 1 with BlockBreakBlacklistEvent

use of com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent in project WorldGuard by EngineHub.

the class BlacklistListener method onDestroyEntity.

@EventHandler(ignoreCancelled = true)
public void onDestroyEntity(DestroyEntityEvent event) {
    final WorldConfiguration wcfg = getWorldConfig(event.getWorld());
    // Blacklist guard
    if (wcfg.getBlacklist() == null) {
        return;
    }
    Player player = event.getCause().getFirstPlayer();
    if (player == null) {
        return;
    }
    final LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    Entity target = event.getEntity();
    if (target instanceof Item) {
        Item item = (Item) target;
        if (!wcfg.getBlacklist().check(new ItemAcquireBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target.getLocation()), createTarget(item.getItemStack())), false, true)) {
            event.setCancelled(true);
            return;
        }
    }
    Material material = Materials.getRelatedMaterial(target.getType());
    if (material != null) {
        // Not really a block but we only have one on-break blacklist event
        if (!wcfg.getBlacklist().check(new BlockBreakBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(event.getTarget()), createTarget(material)), false, false)) {
            event.setCancelled(true);
        }
    }
}
Also used : ItemAcquireBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent) HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) Item(org.bukkit.entity.Item) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Material(org.bukkit.Material) BlockBreakBlacklistEvent(com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent) EventHandler(org.bukkit.event.EventHandler)

Example 2 with BlockBreakBlacklistEvent

use of com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent in project WorldGuard by EngineHub.

the class BlacklistListener method onBreakBlock.

@EventHandler(ignoreCancelled = true)
public void onBreakBlock(final BreakBlockEvent event) {
    final WorldConfiguration wcfg = getWorldConfig(event.getWorld());
    // Blacklist guard
    if (wcfg.getBlacklist() == null) {
        return;
    }
    Player player = event.getCause().getFirstPlayer();
    if (player == null) {
        return;
    }
    final LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    event.filter(target -> {
        if (!wcfg.getBlacklist().check(new BlockBreakBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false)) {
            return false;
        } else if (!wcfg.getBlacklist().check(new ItemDestroyWithBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target), createTarget(player.getInventory().getItemInMainHand())), false, false)) {
            return false;
        }
        return true;
    });
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BlockBreakBlacklistEvent(com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent) ItemDestroyWithBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemDestroyWithBlacklistEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

LocalPlayer (com.sk89q.worldguard.LocalPlayer)2 BlockBreakBlacklistEvent (com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent)2 BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)2 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 ItemAcquireBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent)1 ItemDestroyWithBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemDestroyWithBlacklistEvent)1 Material (org.bukkit.Material)1 Entity (org.bukkit.entity.Entity)1 HumanEntity (org.bukkit.entity.HumanEntity)1 Item (org.bukkit.entity.Item)1