Solved Custom item staying as a stick?..

Discussion in 'Plugin Development' started by mrsamcraft, Dec 27, 2013.

Thread Status:
Not open for further replies.
  1. Hello,

    So Im trying to create a custom item and it works but its always spawning as a stick... I dont know why...

    CODE:
    Code:java
    1. package mscBoredAdmin.cmd;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandExecutor;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.inventory.ItemStack;
    12. import org.bukkit.inventory.meta.ItemMeta;
    13.  
    14. public class cmdSnowBallgun implements CommandExecutor {
    15.  
    16. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    17. Player player = (Player) sender;
    18. if(commandLabel.equalsIgnoreCase("snowballgun")){
    19. player.getInventory().addItem(getCustomItem(Items.Snowball_Gun));
    20. }
    21. return false;
    22.  
    23.  
    24. }
    25.  
    26. public enum Items {
    27. Snowball_Gun;
    28. }
    29.  
    30. public ItemStack getCustomItem(Items item) {
    31. ItemStack is = null;
    32. ItemMeta im;
    33. ArrayList<String> lore;
    34. switch (item) {
    35. case Snowball_Gun:
    36. is = new ItemStack (Material.DIAMOND_HOE, 1);
    37. im = is.getItemMeta();
    38. im.setDisplayName(ChatColor.GOLD + "Snowball Gun");
    39. lore = new ArrayList<String>();
    40. lore.add(ChatColor.BLUE + "Shoot Snowballs at players!");
    41. lore.add(ChatColor.RED + "Damage is delt!");
    42. im.setLore(lore);
    43. is.setItemMeta(im);
    44. }
    45. return is;
    46.  
    47.  
    48. }
    49. }


    Sorry if this is a dumb/easy question...

    Thanks,
    ~ Sam
    All the best for 2014!
     
  2. Offline

    ThunderWaffeMC

    You might have to spawn the item first (or not) and then apply the item meta. Then you could update the item meta (something like .update()).

    So try:

    1. updating the item meta

    2. spawning the item first and then applying and updating the item meta

    If this doesn't work then I don't know what to do :(.
     


  3. With my code, it spawns the stick with the names i've set in the code.. So im just stuck on why its always a stick.. ahah
    [​IMG]
     
  4. Offline

    ThunderWaffeMC


    Oh. Not sure then!
     
  5. Okay no worries! Thanks for the help anyways!
     
  6. Offline

    JUSTCAMH

    try this:
    Code:java
    1. package mscBoredAdmin.cmd;
    2.  
    3. public class cmdSnowBallgun implements CommandExecutor {
    4.  
    5. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    6. Player player = (Player) sender;
    7. if(commandLabel.equalsIgnoreCase("snowballgun")){
    8. List<String> ls = new ArrayList<String>();
    9. ls.add(ChatColor.BLUE + "Shoot Snowballs at players!");
    10. ls.add(ChatColor.RED + "Damage is dealt!");
    11. player.getInventory().addItem(reName(new ItemStack(Material.DIAMOND_HOE), "ChatColor.GOLD + Snowball Gun", ls);
    12. }
    13. return false;
    14.  
    15. public ItemStack reName(ItemStack is, String name, List<String> lore) {
    16. ItemMeta im = is.getItemMeta();
    17. if (name != null)
    18. im.setDisplayName(name);
    19. if (lore != null)
    20. im.setLore(lore);
    21. is.setItemMeta(im);
    22. return is;
    23. }
    24.  
    25.  
    26. }
    27. }


    try that ;)
     
Thread Status:
Not open for further replies.

Share This Page