Search in sources :

Example 1 with ItemAcquireBlacklistEvent

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

the class BlacklistListener method onInventoryCreative.

@EventHandler(ignoreCancelled = true)
public void onInventoryCreative(InventoryCreativeEvent event) {
    HumanEntity entity = event.getWhoClicked();
    ItemStack item = event.getCursor();
    if (item.getType() != Material.AIR && entity instanceof Player) {
        Player player = (Player) entity;
        WorldConfiguration wcfg = getWorldConfig(player.getWorld());
        LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
        if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemAcquireBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(entity.getLocation()), createTarget(item)), false, false)) {
            event.setCancelled(true);
        }
    }
}
Also used : ItemAcquireBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ItemAcquireBlacklistEvent

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

the class BlacklistListener method onPlayerItemHeld.

@EventHandler(ignoreCancelled = true)
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
    Player player = event.getPlayer();
    Inventory inventory = player.getInventory();
    ItemStack item = inventory.getItem(event.getNewSlot());
    if (item != null) {
        WorldConfiguration wcfg = getWorldConfig(player.getWorld());
        LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
        if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemAcquireBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(item)), false, false)) {
            inventory.setItem(event.getNewSlot(), null);
        }
    }
}
Also used : ItemAcquireBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) EventHandler(org.bukkit.event.EventHandler)

Example 3 with ItemAcquireBlacklistEvent

use of com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent 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 4 with ItemAcquireBlacklistEvent

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

the class BlacklistListener method onInventoryClick.

@EventHandler(ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
    HumanEntity entity = event.getWhoClicked();
    if (!(entity instanceof Player))
        return;
    Inventory inventory = event.getInventory();
    ItemStack item = event.getCurrentItem();
    if (item != null && inventory.getHolder() != null) {
        Player player = (Player) entity;
        WorldConfiguration wcfg = getWorldConfig(player.getWorld());
        LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
        if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemAcquireBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(entity.getLocation()), createTarget(item)), false, false)) {
            event.setCancelled(true);
            if (inventory.getHolder().equals(player)) {
                event.setCurrentItem(null);
            }
        }
        ItemStack equipped = checkEquipped(event);
        if (equipped != null) {
            if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemEquipBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(equipped)), false, false)) {
                event.setCancelled(true);
            }
        }
    }
}
Also used : ItemAcquireBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ItemEquipBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent) LocalPlayer(com.sk89q.worldguard.LocalPlayer) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

LocalPlayer (com.sk89q.worldguard.LocalPlayer)4 ItemAcquireBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent)4 BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)4 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)4 Player (org.bukkit.entity.Player)4 EventHandler (org.bukkit.event.EventHandler)4 HumanEntity (org.bukkit.entity.HumanEntity)3 ItemStack (org.bukkit.inventory.ItemStack)3 Inventory (org.bukkit.inventory.Inventory)2 PlayerInventory (org.bukkit.inventory.PlayerInventory)2 BlockBreakBlacklistEvent (com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent)1 ItemEquipBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent)1 Material (org.bukkit.Material)1 Entity (org.bukkit.entity.Entity)1 Item (org.bukkit.entity.Item)1