Solved Why is this happening when i join i get 2 items instead of 1?

Discussion in 'Plugin Development' started by McKiller5252, Feb 11, 2014.

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

    McKiller5252

    When i join the server i get my custom item in slot 0 and 8 but i specifficly made it for slot 8
    It's like when ever i logged out of the server and log back in the item spawns in the slot that i selected before i logged out
    [​IMG]

    Code:java
    1. @EventHandler
    2. public void join(PlayerJoinEvent e){
    3. Player player = e.getPlayer();
    4. if (!player.getInventory().contains(Material.COMPASS))
    5. {
    6. player.setItemInHand(new ItemStack(Material.COMPASS, 1));
    7. ItemStack spawnItem = player.getItemInHand();
    8. ItemMeta im = spawnItem.getItemMeta();
    9. im.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Lobby Selector");
    10. im.setLore(Arrays.asList(ChatColor.AQUA + "Right click to open Lobby Selector", ChatColor.GRAY + "If you lose the Lobby Selector ", ChatColor.GRAY + "Type /ls "));
    11. spawnItem.setItemMeta(im);
    12. player.getInventory().setItem(8, spawnItem);
    13. }
    14. }


    And i don't know what i am doing wrong to create this mistake.
     
  2. Offline

    _Filip

    Look through your code looking SPECIFICALLY at code that says the word 'set'.
    I could tell you the problem , but then you wouldn't learn from your mistakes.
     
  3. Offline

    McKiller5252

    I looked over the code and i still don't see what my mistake was lol :p
     
  4. Offline

    xTigerRebornx

  5. Offline

    McKiller5252

    I still don't get it lol :p I checked everything that has "Hand" and i don't see the mistake
    Code:java
    1. player.setItemInHand(new ItemStack(Material.COMPASS));


    i removed the 1
     
  6. Offline

    xTigerRebornx

    McKiller5252 Okay, let me make it clearer....You are calling setItemInHand(), which will set the Item into whatever slot they've selected, and since you have your 1st selected, its adding the compass
     
    McKiller5252 likes this.
  7. Offline

    L33m4n123


    Look at your code again, You setItemInHand to compass AND you set the Item in slot 8 to an compass.
     
    McKiller5252 likes this.
  8. Offline

    McKiller5252

    Gee Gee Killer you big derp :p How did i not see that LOLOL
     
  9. Offline

    xMrPoi

    Instead of setting the item in hand to a compass and then using that to get the compass, make a new itemstack and just use that.
    Code:java
    1. ItemStack item = new ItemStack(Material.COMPASS);
    2. //do all your other fancy stuff here
    3. player.getInventory().setItem(8, item);
     
Thread Status:
Not open for further replies.

Share This Page