Solved getLore()

Discussion in 'Plugin Development' started by Mjhurtado1, Oct 1, 2014.

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

    Mjhurtado1

    I'm having some trouble with trying to get the lore of an item, then checking if its the same as "Wither".
    If the lore is "Wither", then do something to the victim, kind of like custom enchantments.

    Code:java
    1. @EventHandler
    2. public void onAttack(EntityDamageByEntityEvent e){
    3. if(e.getDamager() instanceof Player){
    4. Player attacker = (Player) e.getDamager();
    5. if(e.getEntity() instanceof Player){
    6. Player victim = (Player) e.getEntity();
    7.  
    8. if(attacker.getInventory().getItemInHand().hasItemMeta()){
    9. if(attacker.getInventory().getItemInHand().getItemMeta().hasLore()){
    10. if(attacker.getInventory().getItemInHand().getItemMeta().getLore().equals("Wither")){
    11. //do stuff to the "victim"
    12. }
    13. }
    14. }
    15.  
    16. }
    17. }
    18. }


    I also tried getLore().contains("Wither"), but no luck with that either.

    I registered the events.

    There are no errors in the console.

    The plugin.yml is working.

    And the item I'm using has the lore "Wither" on it.

    Any help with this would be greatly appreciated!
     
  2. Offline

    Jimfutsu

    Thats not how a lore works, a lore is stored as an array list
     
  3. Offline

    Mjhurtado1

    How would I check if "Wither" is in the lore?
     
  4. Offline

    fireblast709

    Mjhurtado1 your contains("Wither") check should already do that. Post the code that creates the ItemStack.
     
  5. Offline

    Mjhurtado1

    The item is the item that is in the players hand.
     
  6. Offline

    teej107

    You have to set the lore of the ItemStack. Post the code that adds "Wither" to the lore.
     
  7. Offline

    Mjhurtado1

    Here it is:

    Code:java
    1. if(command.getName().equalsIgnoreCase("wither")){
    2. Player p = (Player) sender;
    3. ItemStack item = p.getInventory().getItemInHand();
    4. ItemMeta itemmeta = item.getItemMeta();
    5. ArrayList<String> lore = new ArrayList<String>();
    6. lore.add("Wither");
    7. itemmeta.setLore(lore);
    8. item.setItemMeta(itemmeta);
    9. }



    That works. and it shows up on the item. (Its just used for testing)
     
  8. Offline

    teej107

  9. Offline

    Mjhurtado1

  10. Offline

    fireblast709

    He also stated that he tried contains("Wither")
     
  11. Offline

    teej107

    fireblast709
    Code:java
    1. "pics or it didn't happen".replace("pics", "code");
     
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page