/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.new_liberty.itemconomy.commands;

import com.google.common.base.Joiner;
import net.new_liberty.itemconomy.ICInventory;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
 *
 * @author simplyianm
 */
public class ICSignBuy implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!sender.hasPermission("itemconomy.console")) {
            sender.sendMessage(ChatColor.RED + "Not allowed...");
            return true;
        }

        if (args.length < 3) {
            sender.sendMessage(ChatColor.RED + "Usage: /icsignbuy <player> <price> <cmd>");
            return true;
        }

        Player p = Bukkit.getPlayerExact(args[0]);
        if (p == null) {
            sender.sendMessage(ChatColor.RED + "No such player '" + args[0] + "'!");
            return true;
        }

        int price = 0;
        try {
            price = Integer.parseInt(args[1]);
        } catch (NumberFormatException e) {
            sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a valid integer price!");
            return true;
        }


        ICInventory i = new ICInventory(p);
        int balance = i.balance();
        if (balance < price) {
            p.sendMessage(ChatColor.RED + "You don't have enough currency to buy this! (Requires " + price + "; you only have " + balance + ")");
            return true;
        }

        int of = i.remove(price);
        if (of != 0) {
            p.sendMessage(ChatColor.RED + "You don't have enough emeralds to buy this! Turn your emerald blocks into emeralds and try again. (Need " + of + " more emeralds)");
            return true;
        }

        String[] cmdArray = new String[args.length - 2];
        System.arraycopy(args, 2, cmdArray, 0, cmdArray.length);
        String cmd = Joiner.on(' ').join(cmdArray);

        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);

        return true;
    }

}

@@ -822,9 +822,9 @@
 h %3C 
-3
+4
 ) %7B%0A
@@ -905,16 +905,23 @@
  %3Cprice%3E
+ %3Cname%3E
  %3Ccmd%3E%22)
@@ -1418,16 +1418,68 @@
      %7D%0A%0A
+        String name = args%5B2%5D.replaceAll(%22_%22, %22 %22);%0A
 %0A       
@@ -2268,24 +2268,126 @@
 r(), cmd);%0A%0A
+        p.sendMessage(ChatColor.YELLOW + %22You have bought %22 + name + %22 for %22 + price + %22 emeralds.%22);%0A
         retu

Add item name to purchase message.