Search in sources :

Example 1 with ItemEquipBlacklistEvent

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

the class BlacklistListener method onInventoryDrag.

@EventHandler(ignoreCancelled = true)
public void onInventoryDrag(InventoryDragEvent event) {
    HumanEntity entity = event.getWhoClicked();
    if (!(entity instanceof Player))
        return;
    if (event.getInventory().getType() != InventoryType.PLAYER && event.getInventory().getType() != InventoryType.CRAFTING)
        return;
    if (event.getRawSlots().stream().anyMatch(i -> i >= 5 && i <= 8)) {
        // dropped on armor slots
        Player player = (Player) entity;
        ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
        WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld()));
        LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
        if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemEquipBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(event.getOldCursor())), false, false)) {
            event.setCancelled(true);
        }
    }
}
Also used : 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) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ItemEquipBlacklistEvent

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

the class BlacklistListener method onUseItem.

@EventHandler(ignoreCancelled = true)
public void onUseItem(UseItemEvent 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);
    ItemStack target = event.getItemStack();
    if (!wcfg.getBlacklist().check(new ItemUseBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(target)), false, false)) {
        event.setCancelled(true);
        return;
    }
    if (Materials.isArmor(target.getType()) && !wcfg.getBlacklist().check(new ItemEquipBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(target)), false, false)) {
        event.setCancelled(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) ItemEquipBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ItemUseBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 3 with ItemEquipBlacklistEvent

use of com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent 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)

Example 4 with ItemEquipBlacklistEvent

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

the class BlacklistListener method onBlockDispenseArmor.

@EventHandler(ignoreCancelled = true)
public void onBlockDispenseArmor(BlockDispenseArmorEvent event) {
    if (!(event.getTargetEntity() instanceof Player))
        return;
    Player player = ((Player) event.getTargetEntity());
    ItemStack stack = event.getItem();
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemEquipBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(stack)), false, true)) {
        event.setCancelled(true);
    }
}
Also used : 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) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

LocalPlayer (com.sk89q.worldguard.LocalPlayer)4 ItemEquipBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent)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 ItemStack (org.bukkit.inventory.ItemStack)3 HumanEntity (org.bukkit.entity.HumanEntity)2 ItemAcquireBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent)1 ItemUseBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent)1 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)1 Inventory (org.bukkit.inventory.Inventory)1 PlayerInventory (org.bukkit.inventory.PlayerInventory)1