Some bugs I need help with.

Discussion in 'Plugin Development' started by nentendomitchell, Sep 24, 2014.

Thread Status:
Not open for further replies.
  1. Well, I've been making my plugin more and more and nearly completed with some things. One of two is the Hero's Bow quest.

    Here's the bug I'm getting; When I've finished the Master Sword quest and right clicked on the sign that says "[Master Sword]." it will do as it does, gives me the master sword and then tells me I've gotten a point. But then right under where it says "congratulations, you've got 1 dungeon point." It shows up with "you've already completed this dungeon!" message even though that was supposed to pop up if I've clicked it once again. Then when I do click on it again (keep in mind I've already gotten the dungeon point) it pops up with two messages with "you've already completed this dungeon." Even though the code says to do it once if they've completed the dungeon. Then when I click on the hero's bow sign, it doesn't show up with a message saying "you've a;ready completed this dungeon." It does what it's supposed to. But, when you click it once more, it too pops up with two messages saying "you've already completed this dungeon." Even though the code says to only do it once.

    Can someone help me out here? Here's my code...

    Code:java
    1. // Master Sword Code
    2. @SuppressWarnings("deprecation")
    3. @EventHandler
    4. public boolean onBlockClick1(PlayerInteractEvent event) {
    5. Player p = event.getPlayer();
    6. PlayerInventory inventory = p.getInventory();
    7. if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
    8. return false;
    9. }
    10. Block block = event.getClickedBlock();
    11. if ((block.getType() == Material.SIGN) || (block.getType() == Material.SIGN_POST)
    12. || (block.getType() == Material.WALL_SIGN)) {
    13. Sign sign = (Sign) block.getState();
    14. if ((sign.getLine(0).equalsIgnoreCase("[Master Sword]"))
    15. && (!isPlayerHaveMs(event.getPlayer().getName(), sign.getLine(0)))) {
    16.  
    17. event.getPlayer().sendMessage(
    18. ChatColor.BOLD + "[ZwRPG] " + ChatColor.GOLD
    19. + "You've polled the Master Sword, you are now 7 years older!");
    20. event.getPlayer().sendMessage(
    21. ChatColor.BOLD + "[ZwRPG] " + ChatColor.GOLD + "Congratulations, you got " + ChatColor.RED
    22. + "1" + ChatColor.GOLD + " dungeon point!");
    23. String MasterSword = ChatColor.GOLD + "" + ChatColor.BOLD + "Master Sword";
    24. lores.add(ChatColor.RED + "No evil shall touch this blade!");
    25. ItemStack MS = new ItemStack(Material.DIAMOND_SWORD, 1);
    26. MS.addEnchantment(Enchantment.DAMAGE_ALL, 5);
    27. MS.addEnchantment(Enchantment.FIRE_ASPECT, 2);
    28. MS.addEnchantment(Enchantment.KNOCKBACK, 2);
    29. MS.addEnchantment(Enchantment.DAMAGE_UNDEAD, 5);
    30. MS.addEnchantment(Enchantment.LOOT_BONUS_MOBS, 3);
    31. MS.addEnchantment(Enchantment.DAMAGE_ARTHROPODS, 5);
    32. MS.addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    33. ItemMeta im = MS.getItemMeta();
    34. im.setDisplayName(MasterSword);
    35. im.setLore(lores);
    36. MS.setItemMeta(im);
    37. inventory.addItem(MS);
    38. event.getPlayer().updateInventory();
    39. addMs(event.getPlayer().getName(), sign.getLine(0));
    40. } else {
    41. if (isPlayerHaveMs(event.getPlayer().getName(), sign.getLine(0))) {
    42. event.getPlayer().sendMessage(
    43. ChatColor.BOLD + "[ZwRPG] " + ChatColor.RED + "You've already finished this dungeon!");
    44. }
    45. }
    46. }
    47. return false;
    48. }
    49.  
    50. // Hero's Bow Code
    51. @SuppressWarnings("deprecation")
    52. @EventHandler
    53. public boolean onBlockClick2(PlayerInteractEvent event) {
    54. Player p = event.getPlayer();
    55. PlayerInventory inventory = p.getInventory();
    56. if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
    57. return false;
    58. }
    59. Block block = event.getClickedBlock();
    60. if ((block.getType() == Material.SIGN) || (block.getType() == Material.SIGN_POST)
    61. || (block.getType() == Material.WALL_SIGN)) {
    62. Sign sign = (Sign) block.getState();
    63. if ((sign.getLine(0).equalsIgnoreCase("[Hero's Bow]"))
    64. && (!isPlayerHaveHb(event.getPlayer().getName(), sign.getLine(0)))) {
    65.  
    66. event.getPlayer().sendMessage(
    67. ChatColor.BOLD + "[ZwRPG] " + ChatColor.GOLD + "You now have the Hero's Bow!");
    68. event.getPlayer().sendMessage(
    69. ChatColor.BOLD + "[ZwRPG] " + ChatColor.GOLD + "Congratulations, you got " + ChatColor.RED
    70. + "1" + ChatColor.GOLD + " dungeon point!");
    71. String HerosBow = ChatColor.GOLD + "" + ChatColor.BOLD + "Hero's Bow";
    72. ItemStack HB = new ItemStack(Material.BOW, 1);
    73. ItemMeta im = HB.getItemMeta();
    74. im.setDisplayName(HerosBow);
    75. HB.setItemMeta(im);
    76. inventory.addItem(HB);
    77. event.getPlayer().updateInventory();
    78. addHb(event.getPlayer().getName(), sign.getLine(0));
    79. } else {
    80. if (isPlayerHaveHb(event.getPlayer().getName(), sign.getLine(0))) {
    81. event.getPlayer().sendMessage(
    82. ChatColor.BOLD + "[ZwRPG] " + ChatColor.RED + "You've already finished this dungeon!");
    83. }
    84. }
    85. }
    86. return false;
    87. }
    88.  
    89.  
    90. // Master Sword Code
    91. public void addMs(String playername, String msname) {
    92.  
    93. List<String> currentstringlist = getConfig().getStringList(playername);
    94. currentstringlist.add(msname);
    95. getConfig().set(playername, currentstringlist);
    96. File file = new File("plugins/ZeldaWorld/config.yml");
    97. try {
    98. getConfig().save(file);
    99. } catch (IOException e) {
    100. this.logger.severe("Error saving ZeldaWorld file!");
    101. e.printStackTrace();
    102. }
    103. }
    104.  
    105. // Master Sword Code
    106. public boolean isPlayerHaveMs(String playername, String msname) {
    107.  
    108. File file = new File("plugins/ZeldaWorld/config.yml");
    109. try {
    110. getConfig().load(file);
    111. } catch (FileNotFoundException e) {
    112. e.printStackTrace();
    113. } catch (IOException e) {
    114. e.printStackTrace();
    115. } catch (InvalidConfigurationException e) {
    116. e.printStackTrace();
    117. }
    118. List<String> ms = getConfig().getStringList(playername);
    119. Iterator<String> iter = ms.iterator();
    120. while (iter.hasNext()) {
    121. if (((String) iter.next()).equals(msname)) {
    122. return true;
    123. }
    124. }
    125. return false;
    126. }
    127.  
    128. // Hero's Bow Sword Code
    129. public void addHb(String playername, String hbname) {
    130.  
    131. List<String> currentstringlist = getConfig().getStringList(playername);
    132. currentstringlist.add(hbname);
    133. getConfig().set(playername, currentstringlist);
    134. File file = new File("plugins/ZeldaWorld/config.yml");
    135. try {
    136. getConfig().save(file);
    137. } catch (IOException e) {
    138. this.logger.severe("Error saving ZeldaWorld file!");
    139. e.printStackTrace();
    140. }
    141. }
    142.  
    143. // Hero's Bow Sword Code
    144. public boolean isPlayerHaveHb(String playername, String hbname) {
    145.  
    146. File file = new File("plugins/ZeldaWorld/config.yml");
    147. try {
    148. getConfig().load(file);
    149. } catch (FileNotFoundException e) {
    150. e.printStackTrace();
    151. } catch (IOException e) {
    152. e.printStackTrace();
    153. } catch (InvalidConfigurationException e) {
    154. e.printStackTrace();
    155. }
    156. List<String> hb = getConfig().getStringList(playername);
    157. Iterator<String> iter = hb.iterator();
    158. while (iter.hasNext()) {
    159. if (((String) iter.next()).equals(hbname)) {
    160. return true;
    161. }
    162. }
    163. return false;
    164. }
     
  2. Offline

    Jimfutsu

    What does
    &&(!isPlayerHaveMs(event.getPlayer().getName(), sign.getLine(0)))){
    do? also you realize that if the sign doesn't have [Mastersword] on it it will also send that message?
     
  3. Jimfutsu
    That's to check of they have it.
    And... no, sorry I've already looked to see if that were to happen a long time ago and it never did. So, no, I don't realize that.
     
  4. Offline

    Jimfutsu

    May I see you isPlayerHaveMs Method?
     
  5. Jimfutsu
    Code:java
    1. // Master Sword Code
    2. public boolean isPlayerHaveMs(String playername, String msname) {
    3.  
    4. File file = new File("plugins/ZeldaWorld/config.yml");
    5. try {
    6. getConfig().load(file);
    7. } catch (FileNotFoundException e) {
    8. e.printStackTrace();
    9. } catch (IOException e) {
    10. e.printStackTrace();
    11. } catch (InvalidConfigurationException e) {
    12. e.printStackTrace();
    13. }
    14. List<String> ms = getConfig().getStringList(playername);
    15. Iterator<String> iter = ms.iterator();
    16. while (iter.hasNext()) {
    17. if (((String) iter.next()).equals(msname)) {
    18. return true;
    19. }
    20. }
    21. return false;
    22. }
    23.  
     
  6. Offline

    Jimfutsu

    nentendomitchell
    I recommend you don't get the file itself, but instead use bukkits built in config methods.
    Also, why dont you just give them a permission or something, instead of using such a complex method
     
  7. Jimfutsu
    That's just for error debugs. The File file =newFile("plugins/ZeldaWorld/config.yml"); is just letting the debug see if it's there or not. I keep it because it might come in handy.
    I don't know what you mean? Use permissions for them go gain a Dungeon point? That seems a little but to much work and kinda unnecessary.
    Still doesn't solve my problem. Although, I think it might have to do with the Hero's Bow code and the Master Sword code getting mixed up.
     
  8. Bumping this.
    It seems to be getting both the Master Sword and the Hero's bow code mixed up. I changed the name of the Hero's bow code, but to no use. It still pops up with two messages.
     
Thread Status:
Not open for further replies.

Share This Page