Weird bug ? Help!

Discussion in 'Plugin Development' started by Weszzz, Oct 6, 2013.

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

    Weszzz

    Hi there guys, so i have made a kit plugin where you can choose kits by clicking on it in an icon menu. But if you havent got the permission to select that kit. It must say: [SurviveIt] Je hebt [KITNAME] niet! It says that, but it says another message to and that is: [SurviveIt] Je hebt switcher niet! So the problem is in the code of switcher [this part of the code]:
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent event) {
    3. Player player = (Player) event.getWhoClicked(); // The player that clicked the item
    4. ItemStack clicked = event.getCurrentItem(); // The item that was clicked
    5. Inventory inventory = event.getInventory(); // The inventory that was clicked in
    6. if (inventory.getName().equals(inv.getName())) { // The inventory is our custom Inventory
    7. if (clicked.getType() == Material.SNOW_BALL) { // The item that the player clicked it
    8. if (player.hasPermission("SurviveItKits.Switcher")) {
    9. event.setCancelled(true); // Make it so the dirt is back in its original spot
    10. player.closeInventory(); // Closes there inventory
    11. player.getInventory().setArmorContents(null);
    12. player.getInventory().clear();
    13. player.getInventory().addItem(new ItemStack(Material.COOKED_BEEF, 64)); // Adds
    14. player.getInventory().addItem(new ItemStack(Material.STONE_SWORD, 1));
    15. player.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
    16. player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS, 1));
    17. ItemStack SnowBall1 = new ItemStack(Material.SNOW_BALL, 64);
    18. ItemMeta SnowBall1Meta = SnowBall1.getItemMeta();
    19. SnowBall1Meta.setLore(Arrays.asList(new String[] { ChatColor.GREEN + "Gebruik: Richt en gooi op een speler." }));
    20. SnowBall1Meta.setDisplayName(ChatColor.WHITE + "Switchers");
    21. SnowBall1.setItemMeta(SnowBall1Meta);
    22. player.getInventory().addItem(SnowBall1);
    23. player.getInventory().addItem(new ItemStack(Material.BOW, 1));
    24. player.getInventory().addItem(new ItemStack(Material.ARROW, 32));
    25. player.teleport(new Location(Bukkit.getWorld("world"),-1955,100,64));
    26. try {
    27. ParticleEffects.ENCHANTMENT_TABLE
    28. .sendToPlayer(player,
    29. player.getLocation(),
    30. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    31. ParticleEffects.ENCHANTMENT_TABLE
    32. .sendToPlayer(player,
    33. player.getLocation(),
    34. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    35. ParticleEffects.ENCHANTMENT_TABLE
    36. .sendToPlayer(player,
    37. player.getLocation(),
    38. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    39. ParticleEffects.PORTAL
    40. .sendToPlayer(player,
    41. player.getLocation(),
    42. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    43. ParticleEffects.PORTAL
    44. .sendToPlayer(player,
    45. player.getLocation(),
    46. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    47. ParticleEffects.PORTAL
    48. .sendToPlayer(player,
    49. player.getLocation(),
    50. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    51. } catch (Exception e1) {
    52. e1.printStackTrace();
    53. Location loc = player.getLocation();
    54. player.playSound(loc, Sound.PORTAL_TRAVEL, 2.0F,
    55. 1.0F);
    56. }
    57. }
    58. } else {
    59. if (inventory.getName().equals(inv.getName()))
    60. if (clicked.getType() == Material.SNOW_BALL)
    61. event.setCancelled(true);
    62. player.closeInventory();
    63. player.sendMessage(ChatColor.GOLD + "[" + ChatColor.DARK_RED + "SurviveIt" + ChatColor.GOLD + "] " + ChatColor.RED + "Je hebt switcher niet!");
    64. return;
    65. }
    66. }
    67. }

    But what is the problem ?
    I hope you guys can help me, and heres the whole code:
    http://dev.bukkit.org/paste/tjb3zwspu7m95yxq/
     
  2. Offline

    3ptO

  3. Offline

    Weszzz

    3ptO Yea but what is the problem ?
     
  4. Offline

    holysteward

    lines 62 and 63 should probably contained within {} along with line 61, not sure of your exact idea on the requirements for it to fire or not so I can't say for sure
     
  5. Offline

    Weszzz

    holysteward Thanks! But now if i select Switcher i can just take the item out of the icon menu and nothing happens. No message etc.
     
  6. Offline

    3ptO

    Weszzz Try this,
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent event) {
    3. Player player = (Player) event.getWhoClicked(); // The player that clicked the item
    4. ItemStack clicked = event.getCurrentItem(); // The item that was clicked
    5. Inventory inventory = event.getInventory(); // The inventory that was clicked in
    6. if (inventory.getName().equals(inv.getName())) { // The inventory is our custom Inventory
    7. if (clicked.getType() == Material.SNOW_BALL) { // The item that the player clicked it
    8. if (player.hasPermission("SurviveItKits.Switcher")) {
    9. event.setCancelled(true); // Make it so the dirt is back in its original spot
    10. player.closeInventory(); // Closes there inventory
    11. player.getInventory().setArmorContents(null);
    12. player.getInventory().clear();
    13. player.getInventory().addItem(new ItemStack(Material.COOKED_BEEF, 64)); // Adds
    14. player.getInventory().addItem(new ItemStack(Material.STONE_SWORD, 1));
    15. player.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
    16. player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS, 1));
    17. ItemStack SnowBall1 = new ItemStack(Material.SNOW_BALL, 64);
    18. ItemMeta SnowBall1Meta = SnowBall1.getItemMeta();
    19. SnowBall1Meta.setLore(Arrays.asList(new String[] { ChatColor.GREEN + "Gebruik: Richt en gooi op een speler." }));
    20. SnowBall1Meta.setDisplayName(ChatColor.WHITE + "Switchers");
    21. SnowBall1.setItemMeta(SnowBall1Meta);
    22. player.getInventory().addItem(SnowBall1);
    23. player.getInventory().addItem(new ItemStack(Material.BOW, 1));
    24. player.getInventory().addItem(new ItemStack(Material.ARROW, 32));
    25. player.teleport(new Location(Bukkit.getWorld("world"),-1955,100,64));
    26. try {
    27. ParticleEffects.ENCHANTMENT_TABLE
    28. .sendToPlayer(player,
    29. player.getLocation(),
    30. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    31. ParticleEffects.ENCHANTMENT_TABLE
    32. .sendToPlayer(player,
    33. player.getLocation(),
    34. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    35. ParticleEffects.ENCHANTMENT_TABLE
    36. .sendToPlayer(player,
    37. player.getLocation(),
    38. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    39. ParticleEffects.PORTAL
    40. .sendToPlayer(player,
    41. player.getLocation(),
    42. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    43. ParticleEffects.PORTAL
    44. .sendToPlayer(player,
    45. player.getLocation(),
    46. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    47. ParticleEffects.PORTAL
    48. .sendToPlayer(player,
    49. player.getLocation(),
    50. 1.0F, 1.0F, 1.0F, 1.0F, 60);
    51. } catch (Exception e1) {
    52. e1.printStackTrace();
    53. Location loc = player.getLocation();
    54. player.playSound(loc, Sound.PORTAL_TRAVEL, 2.0F,
    55. 1.0F);
    56. }
    57. } else {
    58. event.setCancelled(true);
    59. player.closeInventory();
    60. player.sendMessage(ChatColor.GOLD + "[" + ChatColor.DARK_RED + "SurviveIt" + ChatColor.GOLD + "] " + ChatColor.RED + "Je hebt switcher niet!");
    61. return;
    62. }
    63. }
    64. }
    65. }
     
  7. Offline

    Weszzz

    3ptO Thanks! That works!
     
  8. Offline

    3ptO

    Weszzz Welcome, did you recognize what the mistake was?
     
Thread Status:
Not open for further replies.

Share This Page