package nu.nerd.easyrider.commands;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEntityEvent;

import nu.nerd.easyrider.EasyRider;
import nu.nerd.easyrider.IPendingInteraction;
import nu.nerd.easyrider.Util;
import nu.nerd.easyrider.db.SavedHorse;

// ----------------------------------------------------------------------------
/**
 * Handles the /horse-tame command.
 */
public class HorseTameExecutor extends ExecutorBase {
    // ------------------------------------------------------------------------
    /**
     * Default constructor.
     */
    public HorseTameExecutor() {
        super("horse-tame", "help");
    }

    // ------------------------------------------------------------------------
    /**
     * @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender,
     *      org.bukkit.command.Command, java.lang.String, java.lang.String[])
     */
    @Override
    public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(ChatColor.RED + "You must be in game to use this command.");
            return true;
        }

        if (args.length != 1 || (args.length == 1 && args[0].equalsIgnoreCase("help"))) {
            return false;
        }

        OfflinePlayer newOwner = Bukkit.getOfflinePlayer(args[0]);
        if (newOwner == null) {
            sender.sendMessage(ChatColor.RED + args[0] + " is not a valid player name.");
        } else {
            sender.sendMessage(ChatColor.GOLD + "Right click on the horse to tame to " + newOwner.getName());
            Player player = (Player) sender;
            EasyRider.PLUGIN.getState(player).setPendingInteraction(new IPendingInteraction() {
                @Override
                public void onPlayerInteractEntity(PlayerInteractEntityEvent event, SavedHorse savedHorse) {
                    Horse horse = (Horse) event.getRightClicked();
                    horse.setOwner(newOwner);
                    EasyRider.DB.observe(savedHorse, horse);
                    // TODO: Clear access control list.
                    sender.sendMessage(ChatColor.GOLD +
                                       "Horse " + Util.limitString(savedHorse.getUuid().toString(), 20) +
                                       " now belongs to " + newOwner.getName() + ".");
                }
            });
        }

        return true;
    }
} // class HorseTameExecutor
@@ -110,32 +110,57 @@
 .OfflinePlayer;%0A
+import org.bukkit.Sound;%0A
 import org.bukki
@@ -1737,24 +1737,169 @@
 er name.%22);%0A
+        %7D else if (!newOwner.hasPlayedBefore()) %7B%0A            sender.sendMessage(ChatColor.RED + args%5B0%5D + %22 has never played on this server.%22);%0A
         %7D el
@@ -2764,24 +2764,119 @@
 e() + %22.%22);%0A
+                    player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1.0f, 1.0f);%0A
             

Add extra name validity check and confirmation sound.