Why is my ItemStack not working?

Discussion in 'Plugin Development' started by ThatGuyWhoDied13, Nov 4, 2013.

Thread Status:
Not open for further replies.
  1. Hey I was wondering why this isn't working.
    yunowork.png
    any help please??
     
  2. Offline

    GusGold

    KevyPorter
    See all of those red underlines, hover your mouse over them to see the error and how to fix it.

    KevyPorter
    Also, Java naming conventions specifies that variables should start with a lowercase letter, Uppercase is reserved for class names

    KevyPorter
    Finally, hubMeta.setLore() takes a list, so it should look like
    Code:java
    1. hubMeta.setLore(hubArray);


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  3. GusGold Here are the errors
    Code:java
    1. public class PlayerListener implements Listener {
    2.  
    3. Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_PURPLE + "Test");
    4.  
    5. ItemStack hub = new ItemStack(Material.BEACON, 1);
    6. ItemMeta hubmeta = hub.getItemMeta();
    7. ArrayList<String> hubarray = new ArrayList<String>();
    8. hubmeta.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Hub"); //Multiple markers at this line - Syntax error on token "setDisplayName", = expected after this token - Syntax error on token(s), misplaced construct(s)
    9. hubarray.add(ChatColor.DARK_PURPLE + "Teleport to the Hub"); //Syntax error on tokens, delete these tokens
    10. hubmeta.setLore(hubarray); //Syntax error on token "hubarray", VariableDeclaratorId expected after this token
    11. hub.setItemMeta(hubmeta); //Syntax error on token "hubmeta", VariableDeclaratorId expected after this token
     
  4. Offline

    tyler53


    I agree with everything Gus just said, You may want to brush up on some basic java before attempting minecraft plugins, but in all honesty there's no better way to learn than full immersion :) So keep trying just like you are and you'll pick it up real quick.

    Also, you can just paste code using the code button on the text box in this forum, you don't have to do screenshots :)

    As to your question, Gus answered it perfectly, hover over those red squigglies and they will tell you the problem, then if you still can't figure it out, come back to these forums with more detailed info for better help :)


    There are a couple things wrong, but rather than just telling you (in the interest of helping you learn how to debug, I'm going to give you the code that I used for a witherbow plugin to add lore and change all the itemMeta and stuff.

    Compare this to yours and see if you see anything different:
    Code:java
    1. ArrayList<String> lore;
    2. lore = new ArrayList<String>();
    3. lore.add(ChatColor.AQUA + "Shoots wither skulls that explode on impact!");
    4. ItemStack newBow = new ItemStack(Material.BOW);
    5. ItemMeta im = newBow.getItemMeta();
    6. im.setDisplayName(ChatColor.DARK_PURPLE + "Wither Bow");
    7. im.setLore(lore);
    8. newBow.setItemMeta(im);
    9. player.getItemInHand().setItemMeta(im);


    A few other convention things, You named your lore arraylist "hubarray"

    This made it slightly more difficult to tell what was going on (in a simple snippet like this it's not a problem, but in bigger plugins and bigger classes it becomes difficult if you don't name variables with descriptive names that tell what they are).

    EDIT: I honestly don't know why it took me so long to realize what was wrong. You haven't created any methods. You are trying to call setters and getters from nowhere, you have to create methods.

    I would suggest (since it looks like, from the name of your class, it's a player listener), that you use this
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e){
    3. //DO ALL THAT STUFF HERE
    4. }


    For more on Event Listeners and how they work I would recommend this video VoidNationMC has a really good series of tutorials on this stuff for beginners I would suggest watching them all, hope this helped :)

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

    amhokies

    tyler53
    Oh wow, I can't believe that I didn't realize that the code wasn't in a method until you said something.
     
  6. Offline

    tyler53



    Haha yeah, the simplest thing slipped under the radar :p must be that late night coding ;P

    Also, kevy, i gave you an internets :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  7. tyler53 amhokies ah yes the method, how could I forget ;-; also thankyou for the internets :3
     
  8. Offline

    GusGold


    Woah, I didn't see that either... wow.
     
Thread Status:
Not open for further replies.

Share This Page