@EventHandler
 void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
   if (event.getPlayer().hasMetadata("give-pet")) {
     if (event.getRightClicked() instanceof Tameable) {
       Tameable pet = (Tameable) event.getRightClicked();
       if (pet.isTamed() && pet.getOwner() instanceof Player) {
         Player player = (Player) pet.getOwner();
         if (player.equals(event.getPlayer())
             || event.getPlayer().hasPermission("omneity3.give-pet.override")) {
           OfflinePlayer reciever =
               plugin
                   .getServer()
                   .getOfflinePlayer(
                       (String) event.getPlayer().getMetadata("give-pet").get(0).value());
           pet.setOwner(reciever);
           event.getPlayer().removeMetadata("give-pet", plugin);
         } else {
           event.getPlayer().sendMessage("This pet is not yours to give");
           event.getPlayer().removeMetadata("give-pet", plugin);
         }
       } else {
         event.getPlayer().sendMessage("This pet is not tamed");
         event.getPlayer().removeMetadata("give-pet", plugin);
       }
     } else {
       event.getPlayer().sendMessage("That entity can not be a pet");
       event.getPlayer().removeMetadata("give-pet", plugin);
     }
   }
 }
Exemple #2
0
 @EventHandler(priority = EventPriority.HIGH)
 public void removeItemFromFrame(PlayerInteractEntityEvent event) {
   Entity entity = event.getRightClicked();
   Player p = event.getPlayer();
   if (!entity.getType().equals(EntityType.ITEM_FRAME)) {
     return;
   }
   ItemFrame iFrame = (ItemFrame) entity;
   if (iFrame.getItem() != null && !iFrame.getItem().getType().equals(Material.AIR)) return;
   OwnedLand land = OwnedLand.getApplicableLand(entity.getLocation());
   if (land == null) {
     return;
   }
   if (!land.hasPermTo(p, this)) {
     p.sendMessage(
         ChatColor.RED
             + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveDirectly"));
     event.setCancelled(true);
   }
 }