Lore checking from config.

Discussion in 'Plugin Development' started by Bancey, Aug 10, 2013.

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

    Bancey

    So I'm trying to add Lore Checking to my plugin so that if the item has a certain lore they will receive potion effects. So I have tried this:
    Code:java
    1. final ArrayList<String> Lore1 = (ArrayList<String>) this.getConfig().getList("Preset1-Lore");

    Code:java
    1. if (inv.getItemInHand().getTypeId() == Preset1 && inv.getItemInHand().getItemMeta().getLore() == Lore1) {
    2. //Apply potion effects


    My config looks like this:
    Show Spoiler
    Code:text
    1. #Default config file
    2.  
    3. Preset1-Item-ID: 1
    4. Preset1-PotionEffect-1: SPEED
    5. Preset1-PotionEffect-2: REGENERATION
    6. Preset1-PotionEffect-3: JUMP
    7. Preset1-PotionEffect-4: DAMAGE_RESISTANCE
    8. Preset1-PotionEffect-5: FIRE_RESISTANCE
    9. Preset1-PotionPotencey: 1
    10. Preset1-Lore:
    11. - Test
    12.  
    13. Preset2-Item-ID: 2
    14. Preset2-PotionEffect-1: SPEED
    15. Preset2-PotionEffect-2: REGENERATION
    16. Preset2-PotionEffect-3: JUMP
    17. Preset2-PotionEffect-4: DAMAGE_RESISTANCE
    18. Preset2-PotionEffect-5: FIRE_RESISTANCE
    19. Preset2-PotionPotencey: 1
    20. Preset2-Lore:
    21. - Test
    22.  
    23. Preset3-Item-ID: 3
    24. Preset3-PotionEffect-1: SPEED
    25. Preset3-PotionEffect-2: REGENERATION
    26. Preset3-PotionEffect-3: JUMP
    27. Preset3-PotionEffect-4: DAMAGE_RESISTANCE
    28. Preset3-PotionEffect-5: FIRE_RESISTANCE
    29. Preset3-PotionPotencey: 1
    30. Preset3-Lore:
    31. - Test
    32.  
    33. Preset4-Item-ID: 4
    34. Preset4-PotionEffect-1: SPEED
    35. Preset4-PotionEffect-2: REGENERATION
    36. Preset4-PotionEffect-3: JUMP
    37. Preset4-PotionEffect-4: DAMAGE_RESISTANCE
    38. Preset4-PotionEffect-5: FIRE_RESISTANCE
    39. Preset4-PotionPotencey: 1
    40. Preset4-Lore:
    41. - Test
    42.  
    43. Preset5-Item-ID: 5
    44. Preset5-PotionEffect-1: SPEED
    45. Preset5-PotionEffect-2: REGENERATION
    46. Preset5-PotionEffect-3: JUMP
    47. Preset5-PotionEffect-4: DAMAGE_RESISTANCE
    48. Preset5-PotionEffect-5: FIRE_RESISTANCE
    49. Preset5-PotionPotencey: 1
    50. Preset5-Lore:
    51. - Test
    52.  
    53. Preset6-Item-ID: 6
    54. Preset6-PotionEffect-1: SPEED
    55. Preset6-PotionEffect-2: REGENERATION
    56. Preset6-PotionEffect-3: JUMP
    57. Preset6-PotionEffect-4: DAMAGE_RESISTANCE
    58. Preset6-PotionEffect-5: FIRE_RESISTANCE
    59. Preset6-PotionPotencey: 1
    60. Preset6-Lore:
    61. - Test
    62.  


    However with the correct item and with the Lore set to "Test" nothing happens.
    Anyone have any idea's how to fix this?
    Thanks
    -Bancey
     
  2. Offline

    Seadragon91

    Use .equals to compare that.
     
  3. Offline

    CubieX

    Try to use .equals() instead of "==" to compare the lore.
    And better use parenthesis around those statements on the left and right side of your "&&".
     
  4. Offline

    Bancey

    Seadragon91 Thanks but it still does nothing :S

    CubieX Thanks for the tip about the parenthesis but it still doesn't work. Have I setup to the list in the config correctly?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  5. Offline

    CubieX

    Try ".getStringList()" to read the lore from config.
     
  6. Offline

    Bancey

    CubieX Now Im getting a NPE on line 97 which is the if statement above :S
     
  7. Offline

    CubieX

    Can you post some more code around that error?
    The three lines you posted are not enough to see what's going wrong.

    Maybe "inv" is null. Maybe the player has no item in hand, so "getItemInHand()" will return null.
    Maybe the item has no lore, so "getLore()" returns null. (the latter could be checked first with ".hasLore()")
     
  8. Offline

    Bancey

  9. Offline

    CubieX

    Code:
    Player player = online.getPlayer();
                                                            if (player.hasPermission("PT.getpotion")) {
                                                                    // if the player has the permission. Apply the potion effects.
                                                                    if ((inv.getItemInHand().getTypeId() == Preset1) && (inv.getItemInHand().getItemMeta().getLore().equals(Lore1))) {
    - "online" is already a player. So no need to do "online.getPlayer()".
    - You have to check that ".getItemInHand()" is not returning "null" before using ".getItemMeta()" on it.

    By the way, you do not need the inventory here. You can directly do "online.getItemInHand()".

    Command Handler:
    Do "return true;" if the player used a valid command.
     
Thread Status:
Not open for further replies.

Share This Page