Custom Item Name & Lore On Command

Discussion in 'Plugin Development' started by kipperfeever, Aug 20, 2014.

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

    kipperfeever

    I am trying to give a player a "Pizza" when they type /pizza and have the name of the item be "Pizza" With a custom lore like "Mhmm ... Pizza" " So Tasty!" This is my code so far, I am just stumped on the rest.
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (label.equalsIgnoreCase("item")) {
    Player player = (Player) sender;
    ItemStack IS = new ItemStack(Material.DIRT, 1);
    PlayerInventory inventory = player.getInventory();
    inventory.addItem(IS);
    return true;
    }
    return false;
    }
    }
     
  2. Offline

    mythbusterma

    kipperfeever

    You need to retrieve the ItemMeta from the ItemStack, set the name and lore of the meta, and then add the meta back to the ItemStack.

    Look at the relevant JavaDocs for the methods you'll need.

    P.S. a long running bug means that you will have to call Player#updateInventory() after you're finished.
     
  3. Offline

    kipperfeever

    Thanks mythbusterma
    HTML:
    <a href="http://topg.org/Minecraft"><img src="http://topg.org/image/340814/36442.jpg banner maker" alt="Minecraft"></a>
     
  4. Offline

    unon1100


    Huh?
     
  5. Offline

    mythbusterma

    unon1100

    When adding or removing items from a player's inventory, you must call Player#updateInventory() because of a bug that they have not yet fixed.
     
  6. Offline

    unon1100

    How long running? It works fine in the version that I'm using.
     
Thread Status:
Not open for further replies.

Share This Page