Code Won't Work For Some Reason

Discussion in 'Spigot Plugin Development' started by ItsWill, Jun 7, 2015.

  1. Hey!
    For some odd reason this code doesn't work. It has no errors in Eclipse, but when I do /enderpearl (it gives me a bow but not the display name).
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (cmd.getName().equalsIgnoreCase("enderpearl")) {
            Player player = (Player) sender;
            ItemStack bow = new ItemStack(Material.BOW);
            ItemMeta bowmeta = bow.getItemMeta();
            bowmeta.setDisplayName(ChatColor.GREEN + "Poison Bow");
            player.getInventory().setItem(4, bow);
            return true;
    Thanks. If you could help it would mean a lot.
  2. You set the meta to the bow after you add it to the player's inventory. Either update the inventory with player.updateInventory() or set the meta first.
    Also, don't cast sender to a Player without checking that it is one first.
    • Like Like x 1
  3. Set the item meta before giving the item to player.
    • Like Like x 1
  4. Thanks A Lot Guys.