Solved Lore not adding

Discussion in 'Plugin Development' started by q8minecraft, Jan 5, 2015.

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

    q8minecraft

    I'm trying to make it whenever you do /supertools and if you're holding a diamond pickaxe in your inventory it adds a lore Explosion I. but for some reason, its not getting added..
    Code:
    package me.q8minecraft.supertools;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class SuperTools extends JavaPlugin implements Listener {
       
        String enabled = "SuperTools has been enabled!";
        String disabled = "SuperTools has been disabled!";
        String rights = " , coded by q8minecraft";
       
       
        public void onEnable() {
            Bukkit.getServer().getConsoleSender().sendMessage( enabled + rights);
        }
       
        public void onDisable() {
            Bukkit.getServer().getConsoleSender().sendMessage( disabled );
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(sender instanceof Player) {
                Player p = (Player) sender;
                if(cmd.getName().equalsIgnoreCase("supertools")){
                    if(((Player) sender).getInventory().getItemInHand() != null) {
                        ItemStack item = new ItemStack(Material.DIAMOND_PICKAXE);
                        ItemMeta im = item.getItemMeta();
                        ArrayList<String> lore = new ArrayList<String>();
                        lore.add(ChatColor.GRAY + "Explosion I");
                        im.setLore(lore);
                        item.setItemMeta(im);
                        p.sendMessage(ChatColor.RED + "You SuperTool is ready!");
                    }
                }
               
    }
           
           
            return false;
        }
       
       
    }
     
  2. Offline

    ChipDev

    Are there errors/did the item get added?
     
  3. Offline

    mythbusterma

    @q8minecraft

    Well you never checked if the item they're holding is a Diamond Pickaxe, for one.
     
  4. Offline

    zDylann

    Your creating a new item every time the command is executed. You need to get the item in the players hand and edit the ItemMeta accordingly.
     
  5. Offline

    q8minecraft

    @ChipDev There's no errors, and I don't want to add new items. All I want to do is to check if the player is holding a specific item (Diamond pickaxe) in their inventory, if so the lore gets added
     
  6. Offline

    mythbusterma

    @q8minecraft

    I love how you ignored my post. That was nice.
     
    AdamQpzm likes this.
  7. Offline

    crolemol

    this should work
     
  8. Offline

    q8minecraft

    @mythbusterma I didn't ignore your post.. I did what you said, and it worked..
     
  9. Offline

    ChipDev

    So is it solved?
     
  10. @ChipDev Working does usually mean solved.

    Marked as solved.
     
Thread Status:
Not open for further replies.

Share This Page