Help - Check Specific lore

Discussion in 'Plugin Development' started by ImaTimelord7, Mar 5, 2015.

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

    ImaTimelord7

    Code:
    package me.ImaTimelord7.plugin;
    
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.SmallFireball;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    public class Confringo implements Listener {
       
        @EventHandler
        public void confringo(PlayerInteractEvent confringo){
        Player player = confringo.getPlayer();
        if(confringo.getAction().equals(Action.LEFT_CLICK_AIR) && player.getItemInHand().getType() == Material.STICK){
            if(player.getItemInHand().getLore().contains("Confringo"));
                player.sendMessage("Confringo!");
                SmallFireball f = confringo.getPlayer().launchProjectile(SmallFireball.class);
                f.setIsIncendiary(true);
                f.setYield(0);{
            }
        }
        }
    }
    Hello, I need my code to check if the held item, stick has specific lore "Confringo" but I get an error on the line
    Code:
    if(player.getItemInHand().getLore().contains("Confringo"));
    the error is on 'getLore' which I found somewhere on the internet to use to check Lore, however it doesn't work. Does anyone know the correct way to check lore? Thanks in advance.
     
  2. Offline

    Unica

    @ImaTimelord7

    Are you sure the actual LIST has an element called 'Confringo' ? Else, try this.
    Code:
    for(String s : itemstack.getLore()){
         if(ChatColor.stripColor(s).contains("whatever")){
               //fire method
               break;
         }
    }
     
  3. Offline

    Code0

    Also, be sure to check if the item actually has a lore. Another important thing: It'll actually have to be one line of the lore. It can't be: "Special: Confringo"
     
  4. Offline

    ImaTimelord7

    First, what do you mean by 'List?' if you mean my item that I am checking lore for, then yes the item's first line of lore is 'Confringo'. Also, I tried the code you suggested, it gives two errors, one on
    Code:
    for(String s : itemstack.getLore()){
    the error is on 'itemstack'
    the secound error is in
    Code:
    if(ChatColor.stripColor(s).contains("Confringo")){
    the error for that one is on 'ChatColor'

    Both errors are 'cannot be resolved' and wanting variables or classes.

    And Code0, I am checking for the whole line of my Lore btw, ;)
    Here's my lore:
    Code:
    lore.add(ChatColor.DARK_PURPLE + "Confringo");
     
  5. @ImaTimelord7
    You're probably getting an error on 'itemstack' because you haven't initialized the variable. You can either make the variable or change it to 'player.getItemInHand()'
    The error on ChatColor is probably because you haven't imported the class. If you hover 'ChatColor' it shows a couple of quick fixes, select the 'import org.bukkit.ChatColor'.
     
Thread Status:
Not open for further replies.

Share This Page