Search in sources :

Example 1 with ItemDestroyWithBlacklistEvent

use of com.sk89q.worldguard.blacklist.event.ItemDestroyWithBlacklistEvent 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)1 BlockBreakBlacklistEvent (com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent)1 ItemDestroyWithBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemDestroyWithBlacklistEvent)1 BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)1 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1