mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-23 09:37:50 +01:00
[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@1212 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
c849bf7fe9
commit
09ab981585
@ -19,9 +19,9 @@ public class Worth implements IConf
|
|||||||
|
|
||||||
public double getPrice(ItemStack itemStack)
|
public double getPrice(ItemStack itemStack)
|
||||||
{
|
{
|
||||||
double result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase()+"."+itemStack.getData().getData(), Double.NaN);
|
double result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase().replace("_", "")+"."+itemStack.getData().getData(), Double.NaN);
|
||||||
if (Double.isNaN(result)) {
|
if (Double.isNaN(result)) {
|
||||||
result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase(), Double.NaN);
|
result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase().replace("_", ""), Double.NaN);
|
||||||
}
|
}
|
||||||
if (Double.isNaN(result)) {
|
if (Double.isNaN(result)) {
|
||||||
result = config.getDouble("worth-"+itemStack.getTypeId(), 0.0);
|
result = config.getDouble("worth-"+itemStack.getTypeId(), 0.0);
|
||||||
@ -32,9 +32,9 @@ public class Worth implements IConf
|
|||||||
public void setPrice(ItemStack itemStack, double price)
|
public void setPrice(ItemStack itemStack, double price)
|
||||||
{
|
{
|
||||||
if (itemStack.getType().getData() == null) {
|
if (itemStack.getType().getData() == null) {
|
||||||
config.setProperty("worth." + itemStack.getType().toString().toLowerCase(), price);
|
config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", ""), price);
|
||||||
} else {
|
} else {
|
||||||
config.setProperty("worth." + itemStack.getType().toString().toLowerCase()+"."+itemStack.getData().getData(), price);
|
config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", "")+"."+itemStack.getData().getData(), price);
|
||||||
}
|
}
|
||||||
config.removeProperty("worth-"+itemStack.getTypeId());
|
config.removeProperty("worth-"+itemStack.getTypeId());
|
||||||
config.save();
|
config.save();
|
||||||
|
@ -18,30 +18,27 @@ public class Commandworth extends EssentialsCommand
|
|||||||
public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
|
public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
|
||||||
{
|
{
|
||||||
ItemStack is = user.getInventory().getItemInHand();
|
ItemStack is = user.getInventory().getItemInHand();
|
||||||
int id = is.getTypeId();
|
|
||||||
int amount = is.getAmount();
|
int amount = is.getAmount();
|
||||||
|
|
||||||
try
|
if (args.length > 0) {
|
||||||
{
|
is = ItemDb.get(args[0]);
|
||||||
if (args.length > 0) id = Integer.parseInt(args[0]);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException ex)
|
|
||||||
{
|
|
||||||
id = ItemDb.get(args[0]).getTypeId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (args.length > 1) amount = Integer.parseInt(args[1]);
|
if (args.length > 1) {
|
||||||
|
amount = Integer.parseInt(args[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
amount = 64;
|
amount = 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is.setAmount(amount);
|
||||||
double worth = Essentials.getWorth().getPrice(is);
|
double worth = Essentials.getWorth().getPrice(is);
|
||||||
|
|
||||||
user.charge(this);
|
user.charge(this);
|
||||||
user.sendMessage("§7Stack of " + id + " worth §c$" + (worth * amount) + "§7 (" + amount + " item(s) at $" + worth + " each)");
|
user.sendMessage("§7Stack of " + is.getType().toString().toLowerCase().replace("_", "") + " worth §c$" + (worth * amount) + "§7 (" + amount + " item(s) at $" + worth + " each)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user