Solved Giving players items glitch (with signs)

Discussion in 'Plugin Development' started by RizzelDazz, Jan 20, 2014.

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

    RizzelDazz

    Hello, I am trying to give players items according to what class they are on, this is EXTREMELY buggy. For some reason when you click the sign, you get tp'd but about 70% of the time you see a blank inventory once you are tp'dand you have to click one of the armor slots for the inventory to update itself, I have absolutely no idea what is causing this and I have spent a large amount of time trying to figure it out.


    I have possibly found the cause. When I have the 1st selected inventory slot, it gives the items, but any other, it gives the items but does not update the inventory!

    Code:java
    1. @EventHandler
    2. private void onPlayerInteract(PlayerInteractEvent e) {
    3. Location lobby = new Location(Bukkit.getWorld("world"), 349, 67, 228);
    4. Player player = e.getPlayer();
    5. PlayerInventory pi = player.getInventory();
    6. if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    7. if (e.getClickedBlock().getState() instanceof Sign) {
    8. Sign s = (Sign) e.getClickedBlock().getState();
    9. if (s.getLine(0).equalsIgnoreCase("§1[Knight]")) {
    10. pi.clear();
    11. player.sendMessage(ChatColor.GREEN + "You have been given the kit of an Knight");
    12. player.sendMessage(ChatColor.GREEN + "You have been teleported to the lobby area!");
    13. player.teleport(lobby);
    14. pi.addItem(KSword);
    15. if(Main.blue.contains(player)){
    16. pi.setHelmet(creeperHelmet);
    17. pi.setChestplate(BChest);
    18. pi.setLeggings(BLeggings);
    19. pi.setBoots(BBoots);
    20. }else{
    21. pi.setHelmet(Rhelm);
    22. pi.setChestplate(RChest);
    23. pi.setLeggings(RLeggings);
    24. pi.setBoots(RBoots);
    25. }
    26. }
    27. if (s.getLine(0).equalsIgnoreCase("§1[Archer]")) {
    28. pi.clear();
    29. player.sendMessage(ChatColor.GREEN + "You have been given the kit of an Archer!");
    30. player.sendMessage(ChatColor.GREEN + "You have been teleported to the lobby area!");
    31. player.teleport(lobby);
    32. pi.addItem(ABow);
    33. if(Main.blue.contains(player)){
    34. pi.setHelmet(creeperHelmet);
    35. pi.setChestplate(BChest);
    36. pi.setLeggings(BLeggings);
    37. pi.setBoots(BBoots);
    38. }else{
    39. pi.setHelmet(Rhelm);
    40. pi.setChestplate(RChest);
    41. pi.setLeggings(RLeggings);
    42. pi.setBoots(RBoots);
    43. }
    44. }
    45. }
    46. }


    There are no errors at all, like I said, sometimes you have to click for it to update, sometimes you don't.
     
  2. Offline

    Warreo

    RizzelDazz You need to update the player's inventory. :)
    Code:java
    1. player.updateInventory();
     
  3. Offline

    DoctorDark

    RizzelDazz Try setting the Interact event to cancelled before giving the players the items.
     
  4. Offline

    RizzelDazz

    Yea figured that out, thanks.
     
  5. Offline

    CrazyGuy3000

    *** OFF TOPIC ***
    You can type (CTRL + SHIFT + F) whilst having all you code selected to clean it up and make it look nicer ;)
     
  6. Offline

    RizzelDazz

    The only thing I don't like about that is the way it formats messages :p
     
  7. Offline

    Afridge1O1

    You can also use CTRL + a to highlight everything then CTRL + i to format i
    keeps the message one line
     
  8. Offline

    RizzelDazz

    Thanks, learning new things everyday.
     
  9. Offline

    Afridge1O1

    Happy to help
     
  10. Offline

    CrazyGuy3000

    Anytime :)
     
Thread Status:
Not open for further replies.

Share This Page