It's giving the player 2 items instead of 1.

Discussion in 'Plugin Development' started by ninja2003, Jul 27, 2014.

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

    ninja2003

    I'm making a plugin for my server that gives that player an item a compass in this case and then they right click and select bla bla bla but for reason it gives me 2 items heres the code
    Code:java
    1. @EventHandler(priority=EventPriority.MONITOR)
    2. public void onPlayerJoinEvent(PlayerJoinEvent event)
    3. {
    4. Player p = event.getPlayer();
    5. if (event.getPlayer().getLocation().getWorld().getName().equals("Spawn"))
    6. {
    7. ItemStack spawncompass = new ItemStack(Material.COMPASS, 0);
    8. ItemMeta stackMeta = spawncompass.getItemMeta();
    9. stackMeta.setDisplayName(ChatColor.RED + "Quick Join!");
    10. ArrayList<String> lore = new ArrayList<String>();
    11. lore.add(ChatColor.GRAY + "If you don't feel like ");
    12. lore.add(ChatColor.GRAY + "running and jumping in ");
    13. lore.add(ChatColor.GRAY + "the portals this is the ");
    14. lore.add(ChatColor.GRAY + "perfect thing for you, All ");
    15. lore.add(ChatColor.GRAY + "you got to do is right click ");
    16. lore.add(ChatColor.GRAY + "me and choose the game you");
    17. lore.add(ChatColor.GRAY + "wanna play!");
    18. stackMeta.setLore(lore);
    19. spawncompass.setItemMeta(stackMeta);
    20. p.getInventory().addItem(spawncompass);
    21. }
    22. }
     
  2. Offline

    mythbusterma

    ninja2003

    Check to make sure the code isn't run twice, also use Player#updateInventory() to ensure the inventory is consistent with what the serber recognizes it as, finally make sure to remove the item when the player leaves.
     
  3. Offline

    AlexHH251997

    ninja2003

    I'm not 100% sure on this but you might want to try this:
    Code:java
    1. ItemStack spawncompass = new ItemStack(Material.COMPASS, 1);

    Instead of this:
    Code:java
    1. ItemStack spawncompass = new ItemStack(Material.COMPASS, 0);


    Sometimes the simplest of things can make all the different.

    Regards,
    Alex Harris
     
Thread Status:
Not open for further replies.

Share This Page