Checking if a help item has a lore!

Discussion in 'Plugin Development' started by 3ShotGod, Mar 7, 2014.

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

    3ShotGod

    Hi guys! Im having trouble finding an if statement which would mean the follow:

    "if an item does not have a lore on it , do etc."

    Code:
                        if(player.getInventory().getItemInHand().getType().equals(Material.DIAMOND_SWORD)){
                            player.playSound(player.getLocation(), Sound.ANVIL_USE, 2F, 1F);
    Im trying to make it a little something like this but, if the diamond_sword the player is holding has a lore it doesn't run the sound and sends a message.

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

    Wizehh

    3ShotGod
    if (player.getItemInHand() != null) {
    if (player.getItemInHand().getItemMeta() != null) {
    if (player.getItemInHand().getItemMeta().getLore() != null) {
    // do etc
    }
    }
    }
     
  3. Offline

    3ShotGod

    Bump?

    I forgot to mention my current if statements:

    Code:
    if (commandLabel.equalsIgnoreCase("refiner")) {
                player.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.RED
                        + "Refiner" + ChatColor.DARK_RED + "]" + ChatColor.DARK_RED
                        + " Plugin by 3ShotGod for play.gleecraftmc.com");
            } else if (commandLabel.equalsIgnoreCase("refine")) {
                if (player instanceof Player) {
                    if (player.hasPermission("Refiner.use")) {
                    }
                } else {
                    player.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.RED
                            + "Refiner" + ChatColor.DARK_RED + "]"
                            + ChatColor.DARK_RED
                            + " You need the permission refiner.use!");
                }
                if (player.getItemInHand().getDurability() <= 0)
                    if (player.getItemInHand().getEnchantments().size() <= 0)
                        if (player.getInventory().getItemInHand().getType()
                                .equals(Material.DIAMOND_SWORD)) {
                            player.playSound(player.getLocation(), Sound.ANVIL_USE,
                                    2F, 1F);
    How would i format this if statement in?
     
  4. Offline

    3ShotGod

  5. Offline

    TwerkinCraft

    This is a bit off-topic, but it would save you alot of time if you did something like this:
    String prefix = ChatColor.DARK_RED + "[" + ChatColor.RED + "Refiner" + ChatColor.DARK_RED + "]";
    and in your onCommand, just do:
    prefix + " What you want to say"
     
Thread Status:
Not open for further replies.

Share This Page