Solved Problem with testing Item in players hand

Discussion in 'Plugin Development' started by Digbywood, Jan 15, 2015.

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

    Digbywood

    Hey I'm having a problem with my code. I want to make sure that the player is holding a certain item when they place a block to replace it. But its not working. Here is what I have:
    Code:
    @SuppressWarnings("deprecation")
        @EventHandler
        public void blockPlace(BlockPlaceEvent event){
            if(event.getItemInHand() == BuildingTools.oakLog){
                event.getBlockPlaced().setTypeIdAndData(17, (byte) 12, true);
            }
        }
    BuildingTools.oakLog equals Utils.setItemName(Material.LOG, (short) 0, "§r6 Sided Oak Wood");

    which I define here:
    Code:
    public static ItemStack setItemName(Material m, short data, String name){
            ItemStack is = new ItemStack(m, 1, data);
            ItemMeta im = is.getItemMeta();
            im.setDisplayName(name);
            is.setItemMeta(im);
            return is;
        }
    I need some help please
     
  2. Offline

    Konato_K

    @Digbywood I'm not sure what behavior you actually want, but you're comparing objects with ==, you should be using equals
     
  3. Offline

    xize

    @Digbywood

    mind sending where you call BuildingTools.oakLog ? also if you compair a ItemStack you should use .equals() as == is only a type check which does not checks the contents of the other ItemStack you are compairing it to.
     
  4. Offline

    Digbywood

Thread Status:
Not open for further replies.

Share This Page