Search in sources :

Example 1 with ItemUseBlacklistEvent

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

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

the class BlacklistListener method onSpawnEntity.

@EventHandler(ignoreCancelled = true)
public void onSpawnEntity(SpawnEntityEvent 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);
    Material material = Materials.getRelatedMaterial(event.getEffectiveType());
    if (material != null) {
        if (!wcfg.getBlacklist().check(new ItemUseBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(event.getTarget()), createTarget(material)), 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) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Material(org.bukkit.Material) ItemUseBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

LocalPlayer (com.sk89q.worldguard.LocalPlayer)2 ItemUseBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent)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 ItemEquipBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent)1 Material (org.bukkit.Material)1 ItemStack (org.bukkit.inventory.ItemStack)1