Removing and Replacing items in a player's hand.

Discussion in 'Plugin Development' started by Eliteninja42, Jul 23, 2013.

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

    Eliteninja42

    Hello, I was wondering if anyone could help me. I want to know how i can make my plugin remove an item from a player's hand and replace it with another item of the same amount on a command. For example if they had 13 iron ore I want the player to be able to type /smelt and the iron ore will be removed and replaced with 13 iron ingots. Any help would be appreciated.

    Thank you.
     
  2. Offline

    Jalau

    Use:
    Code:
                    if(player.getItemInHand().getType() == Material.IRON_ORE) {
    ItemStack iron = player.getInventory().getItemInHand();
                //or this for a special slot (1 is the slot)
                //ItemStack iron = player.getInventory().getItem(1);
                int amount = iron.getAmount();
                ItemStack smelt = new ItemStack(Material.IRON_INGOT, amount);
                player.getInventory().setItemInHand(smelt);
                //or slot again (1 is slot) 0 is the first slot in his inventory if closed
                //player.getInventory().setItem(1, smelt);
    }
    
     
  3. Offline

    Eliteninja42

    Since I'm going to make it work for all ores and food would I create multiple if statements or could I use a switch statement?
     
Thread Status:
Not open for further replies.

Share This Page