@EventHandler(priority = EventPriority.HIGH) public void removeItemFromFrame(EntityDamageByEntityEvent event) { Entity victim = event.getEntity(); if (!victim.getType().equals(EntityType.ITEM_FRAME)) { return; } Player p; Entity attacker = event.getDamager(); // System.out.println("Attacker: "+attacker.getType().toString()); if (attacker.getType().toString().equals("PLAYER")) { p = (Player) attacker; OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation()); if (land == null) { return; } if (!land.hasPermTo(p, this)) { p.sendMessage( ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveWithMelee")); event.setCancelled(true); } } else if (attacker.getType().toString().equals("ARROW")) { Arrow a = (Arrow) attacker; if (a.getShooter() instanceof Player) { p = (Player) a.getShooter(); } else { return; } OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation()); if (land == null) { return; } if (!land.hasPermTo(p, this)) { p.sendMessage( ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveWithArrow")); event.setCancelled(true); } } }
@EventHandler(priority = EventPriority.HIGH) public void destroyArmorStand(EntityDamageByEntityEvent event) { Entity victim = event.getEntity(); // System.out.println("Victim: "+victim); if (!victim.getType().equals(EntityType.ARMOR_STAND)) { return; } OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation()); if (land == null) { return; } if (event.getDamager().getType().equals(EntityType.PLAYER)) { Player attacker = (Player) event.getDamager(); // System.out.println(attacker.getName()); if (!land.hasPermTo(attacker, this)) { attacker.sendMessage( ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.breakArmorStandWithMelee")); event.setCancelled(true); } } if (event.getDamager().getType().equals(EntityType.ARROW)) { Arrow projectile = (Arrow) event.getDamager(); if (projectile.getShooter() instanceof Player) { Player attacker = (Player) projectile.getShooter(); if (!land.hasPermTo(attacker, this)) { attacker.sendMessage( ChatColor.RED + getPlugin() .getMessageConfig() .getString("event.build.breakArmorStandWithArrow")); event.setCancelled(true); } } } // System.out.println(event.getDamager().getType()); }