mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-22 08:25:12 +00:00

Found using PMD and FindBugs. git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1553 e251c2fe-e539-e718-e476-b85c1f46cddb
61 lines
1.4 KiB
Java
61 lines
1.4 KiB
Java
package com.earth2me.essentials.commands;
|
|
|
|
import org.bukkit.Server;
|
|
import com.earth2me.essentials.ItemDb;
|
|
import com.earth2me.essentials.User;
|
|
import com.earth2me.essentials.Util;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
public class Commandworth extends EssentialsCommand
|
|
{
|
|
public Commandworth()
|
|
{
|
|
super("worth");
|
|
}
|
|
|
|
@Override
|
|
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
|
{
|
|
ItemStack is = user.getInventory().getItemInHand();
|
|
int amount = is.getAmount();
|
|
|
|
if (args.length > 0)
|
|
{
|
|
is = ItemDb.get(args[0]);
|
|
}
|
|
|
|
try
|
|
{
|
|
if (args.length > 1)
|
|
{
|
|
amount = Integer.parseInt(args[1]);
|
|
}
|
|
}
|
|
catch (NumberFormatException ex)
|
|
{
|
|
amount = 64;
|
|
}
|
|
|
|
is.setAmount(amount);
|
|
double worth = ess.getWorth().getPrice(is);
|
|
if (Double.isNaN(worth))
|
|
{
|
|
throw new Exception(Util.i18n("itemCannotBeSold"));
|
|
}
|
|
|
|
charge(user);
|
|
user.sendMessage(is.getDurability() != 0
|
|
? Util.format("worthMeta",
|
|
is.getType().toString().toLowerCase().replace("_", ""),
|
|
is.getDurability(),
|
|
Util.formatCurrency(worth * amount),
|
|
amount,
|
|
Util.formatCurrency(worth))
|
|
: Util.format("worth",
|
|
is.getType().toString().toLowerCase().replace("_", ""),
|
|
Util.formatCurrency(worth * amount),
|
|
amount,
|
|
Util.formatCurrency(worth)));
|
|
}
|
|
}
|