1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
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)));
}
}
|