[HELP!] Item Right Click Event

Discussion in 'Plugin Development' started by LordManegane, Jun 30, 2013.

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

    LordManegane

    Well, the thing i wanna achieve its make an item on right click do something
    I have 2 items of the same kind

    Code:java
    1. ItemStack test1 = new ItemStack(Material.FEATHER, 1);
    2. ItemStack test2 = new ItemStack(Material.FEATHER, 1);


    And the meta
    Code:java
    1. test1m.setDisplayName(ChatColor.GOLD +"Test Thing 1");
    2. test1.setItemMeta(test1m);


    Code:java
    1. test2m.setDisplayName(ChatColor.GOLD +"Test Thing 2");
    2. test2.setItemMeta(test2m);



    I want make the 2 feathers do something diferent.


    I want a way to get witch feather its right clicked, because i have this code

    Code:java
    1. @EventHandler(priority=EventPriority.HIGH)
    2. public void onPlayerUse(PlayerInteractEvent event){
    3. Player p = event.getPlayer();
    4.  
    5. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
    6. if(p.getItemInHand().getType() == Material.FEATHER && p.getInventory().contains(this.test1)){
    7. p.sendMessage("TEST WORKING");
    8.  
    9. }
    10.  

    Thanks
     
    Shzylo likes this.
  2. Offline

    Shzylo

    try
    if(p.getItemInHand().getItemMeta() == this.test1)

    Not sure if it works. You may not need 'this' in 'this.test1' also.
     
  3. Offline

    creatorfromhell

    Try this:
    Code:
    @EventHandler(priority=EventPriority.HIGH)
        public void onPlayerUse(PlayerInteractEvent event){
            Player p = event.getPlayer();
     
            if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
                if(event.getItemInHand().getType().equals(Material.FEATHER) && p.getInventory().contains(this.test1)){
                    p.sendMessage("TEST WORKING");
     
                }
     
  4. Offline

    CubixCoders

    You should do if(event.getItemInHand().hasMetadata())
    To make sure it's a renamed item and such, then just get the display name and compare
     
  5. Offline

    LordManegane

Thread Status:
Not open for further replies.

Share This Page