Changing Item Names

Discussion in 'Plugin Development' started by Chibbey, Jan 4, 2014.

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

    Chibbey

    Hello. Ok so I'm making a KitPvP plugin so when people types /kits it opens up a GUI. In the Chest GUI there are items with names of kits. And one of those items are a potion for a toxic kit. How would I change the names of a potion. This is what I thought it was
    Code:java
    1. // Toxic stuff.
    2. Potion toxic = new Potion(PotionType.POISON);
    3. toxic.setSplash(true);
    4. ItemMeta toxicmeta = toxic.toItemStack(1).getItemMeta();
    5. toxicmeta.setDisplayName(ChatColor.DARK_PURPLE + "Toxic");
    6. toxic.toItemStack(1).setItemMeta(toxicmeta);
    7. // Adding Toxic.
    8. kits.addItem(toxic.toItemStack(1));


    kits is the name of the Inventory
     
  2. Offline

    Wizehh

    Does it not work?
     
  3. Offline

    messageofdeath

    That will not work because your creating a new instance of the ItemStack every single time you get it.

    Try this:
    1. // Toxic stuff.
    2. Potion toxic = new Potion(PotionType.POISON);
    3. ItemStack item = toxic.toItemStack(1);
    4. toxic.setSplash(true);
    5. ItemMeta toxicmeta = item.getItemMeta();
    6. toxicmeta.setDisplayName(ChatColor.DARK_PURPLE + "Toxic");
    7. item.setItemMeta(toxicmeta);
    8. // Adding Toxic.
    9. kits.addItem(item);
     
  4. Offline

    Chibbey

    messageofdeath
    Sorry watching movie. Ill try right now!

    messageofdeath
    Ok I tried and it worked! But it didn't turn it into a splash potion. It just made it a normal potion :( . But I fixed it! I had to add toxic.setSplash(true); before creating the turning it into a item stack so instead of line 4 it would be line 3 and turning into itemstack would be line 4. Thanks for helping me :)

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

    messageofdeath

Thread Status:
Not open for further replies.

Share This Page