TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandworth.java
snowleo c849bf7fe9 [trunk] Worth/Sell: Support for double values as prices and more important: support for data items.
the yaml structure has changed, there is a fallback to the old structure.

This code is untested.

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1211 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-04-16 06:28:56 +00:00

47 lines
1 KiB
Java

package com.earth2me.essentials.commands;
import org.bukkit.Server;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.ItemDb;
import com.earth2me.essentials.User;
import org.bukkit.inventory.ItemStack;
public class Commandworth extends EssentialsCommand
{
public Commandworth()
{
super("worth");
}
@Override
public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
{
ItemStack is = user.getInventory().getItemInHand();
int id = is.getTypeId();
int amount = is.getAmount();
try
{
if (args.length > 0) id = Integer.parseInt(args[0]);
}
catch (NumberFormatException ex)
{
id = ItemDb.get(args[0]).getTypeId();
}
try
{
if (args.length > 1) amount = Integer.parseInt(args[1]);
}
catch (NumberFormatException ex)
{
amount = 64;
}
double worth = Essentials.getWorth().getPrice(is);
user.charge(this);
user.sendMessage("§7Stack of " + id + " worth §c$" + (worth * amount) + "§7 (" + amount + " item(s) at $" + worth + " each)");
}
}