Solved PlayerInteractEvent

Discussion in 'Plugin Development' started by MoeMix, Feb 10, 2014.

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

    MoeMix

    Hello guys, so i want the set the player invisible if they right click a feather. However, it can't just be any feather. I want it to check if the feather has a specific itemmeta. If it does then it should give the player invisibility for 500 ticks and then remove the feather.

    This is what I have so far however I don't know what could possible be the problem...
    Thanks for checking it out.

    Code:java
    1. @EventHandler
    2. public void onanvilclick(PlayerInteractEvent e){
    3. ItemStack cloak = new ItemStack(Material.FEATHER);
    4. ItemMeta cloakim = cloak.getItemMeta();
    5. cloakim.setDisplayName(ChatColor.GOLD + "Invisibility Cloak");
    6. List<String> lore = new ArrayList<String>();
    7. lore.add(ChatColor.GREEN + "Right Click to put on your Invisible cloak!");
    8. cloakim.setLore(lore);
    9. cloak.setItemMeta(cloakim);
    10. if(e.getPlayer().getItemInHand() == cloak){
    11. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    12. e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1, 500));
    13. e.getPlayer().getInventory().remove(cloak);


    does anyone know why the check for itemmeta isn't working?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  2. Offline

    TeeePeee

    MoeMix
    As ItemStack isn't primitive, you shouldn't be comparing it with ==. Instead, you should use ItemStack#equals() or ItemStack#isSimilar().
     
  3. Offline

    MoeMix

    TeeePeee
    So if(e.getItemInHand().equals(cloak))?
     
  4. Offline

    TeeePeee

    MoeMix likes this.
  5. Offline

    MoeMix

Thread Status:
Not open for further replies.

Share This Page