Cancel Empty Map item on player right click

Discussion in 'Plugin Development' started by ShaneCraftDev, Feb 22, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    ShaneCraftDev

    Please correct me if this written in the wrong format, first post.

    I want to cancel an action made when the player uses right click on a certain item, in this case an empty map.

    Browsing through the bukkit source, I can only find one event that suits my problem.
    The PlayerInteractEvent, however there is a slight bug when canceling this event.

    Whenever I right click with an empty map, I cancel the event immediately and it does get canceled. But the empty map item still creates a new map item. However this map item seems to be glitched as it does not populate the map and when right clicked again, it returns the original empty map. This 'glitched' map item does stay as map item when you open any inventory, reconnect to the server or throw it on the ground and pick it up again.

    My question is, is my eventhandler incorrect or does the interaction from right clicking an empty map item occur before the event can cancel it?

    used code:
    Code:
      @EventHandler(priority = EventPriority.HIGH)
       public void onPlayerInteractEvent(PlayerInteractEvent event) {
         if (event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
           // method below checks for nbt, but ItemStack#getType() == Material.EMPTY_MAP works as well..
           if (Scroll.isScroll(event.getPlayer().getItemInHand())) {
             event.setCancelled(true);
           }
         }
       }
    
     
    Last edited: Feb 22, 2016
  2. Offline

    SkyleTyler1337

  3. Offline

    ShaneCraftDev

    @SkyleTyler1337

    Thanks for your response, but like I have posted in the snippet, replacing this condition with what's written in the comment should work as well.

    Anyhow, here is the Scroll class in it's entirety:
    http://pastebin.com/tuffjvga

    I don't think posting this class will help you nor anyone else assist me to solve the issue, but here are the additional condititions and statements that occur in this class:
    It checks if the material of the item is an instance of Material#EMPTY_MAP, next it checks if the itemstack has the following NBTTags 'he_level' and 'he_name'. If both tags are present, it will create a new instance of ScrollData. The ScrollData class is a workaround to the ItemMeta interface as you can not create custom ItemMeta classes, bukkit throws an error saying it is not a bukkit-ItemMeta object.

    Where NBTTagCompoundUtil converts the bukkit itemstack to a minecraft itemstack and back to a bukkit itemstack to set the NBTTags 'he_level' and 'he_name' (ensures the scrolls of having an enchantment) and HorseEnchantment is just a custom enchantment system using lores.
     
    Last edited: Feb 22, 2016
Thread Status:
Not open for further replies.

Share This Page