mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Throw syntax error instead of "For input string"
This commit is contained in:
parent
a14104c529
commit
29ea24f715
2 changed files with 30 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
|
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -56,7 +57,12 @@ public class Worth implements IConf
|
||||||
|
|
||||||
if (args.length > 1)
|
if (args.length > 1)
|
||||||
{
|
{
|
||||||
amount = Integer.parseInt(args[1].replaceAll("[^0-9]", ""));
|
try {
|
||||||
|
amount = Integer.parseInt(args[1].replaceAll("[^0-9]", ""));
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex) {
|
||||||
|
throw new NotEnoughArgumentsException(ex);
|
||||||
|
}
|
||||||
if (args[1].startsWith("-"))
|
if (args[1].startsWith("-"))
|
||||||
{
|
{
|
||||||
amount = -amount;
|
amount = -amount;
|
||||||
|
|
|
@ -17,18 +17,18 @@ public class Commandworth extends EssentialsCommand
|
||||||
{
|
{
|
||||||
super("worth");
|
super("worth");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
BigDecimal totalWorth = BigDecimal.ZERO;
|
BigDecimal totalWorth = BigDecimal.ZERO;
|
||||||
String type = "";
|
String type = "";
|
||||||
|
|
||||||
List<ItemStack> is = ess.getItemDb().getMatching(user, args);
|
List<ItemStack> is = ess.getItemDb().getMatching(user, args);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
boolean isBulk = is.size() > 1;
|
boolean isBulk = is.size() > 1;
|
||||||
|
|
||||||
for (ItemStack stack : is)
|
for (ItemStack stack : is)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -45,7 +45,7 @@ public class Commandworth extends EssentialsCommand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -67,7 +67,7 @@ public class Commandworth extends EssentialsCommand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
|
@ -76,12 +76,12 @@ public class Commandworth extends EssentialsCommand
|
||||||
{
|
{
|
||||||
throw new NotEnoughArgumentsException();
|
throw new NotEnoughArgumentsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack stack = ess.getItemDb().get(args[0]);
|
ItemStack stack = ess.getItemDb().get(args[0]);
|
||||||
|
|
||||||
itemWorth(sender, null, stack, args);
|
itemWorth(sender, null, stack, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BigDecimal itemWorth(CommandSender sender, User user, ItemStack is, String[] args) throws Exception
|
private BigDecimal itemWorth(CommandSender sender, User user, ItemStack is, String[] args) throws Exception
|
||||||
{
|
{
|
||||||
int amount = 1;
|
int amount = 1;
|
||||||
|
@ -89,23 +89,31 @@ public class Commandworth extends EssentialsCommand
|
||||||
{
|
{
|
||||||
if (args.length > 1)
|
if (args.length > 1)
|
||||||
{
|
{
|
||||||
amount = Integer.parseInt(args[1].replaceAll("[^0-9]", ""));
|
try
|
||||||
|
{
|
||||||
|
amount = Integer.parseInt(args[1].replaceAll("[^0-9]", ""));
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex)
|
||||||
|
{
|
||||||
|
throw new NotEnoughArgumentsException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
amount = ess.getWorth().getAmount(ess, user, is, args, true);
|
amount = ess.getWorth().getAmount(ess, user, is, args, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal worth = ess.getWorth().getPrice(is);
|
BigDecimal worth = ess.getWorth().getPrice(is);
|
||||||
|
|
||||||
if (worth == null)
|
if (worth == null)
|
||||||
{
|
{
|
||||||
throw new Exception(_("itemCannotBeSold"));
|
throw new Exception(_("itemCannotBeSold"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal result = worth.multiply(BigDecimal.valueOf(amount));
|
BigDecimal result = worth.multiply(BigDecimal.valueOf(amount));
|
||||||
|
|
||||||
sender.sendMessage(is.getDurability() != 0
|
sender.sendMessage(is.getDurability() != 0
|
||||||
? _("worthMeta",
|
? _("worthMeta",
|
||||||
is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""),
|
is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""),
|
||||||
|
@ -118,7 +126,7 @@ public class Commandworth extends EssentialsCommand
|
||||||
NumberUtil.displayCurrency(result, ess),
|
NumberUtil.displayCurrency(result, ess),
|
||||||
amount,
|
amount,
|
||||||
NumberUtil.displayCurrency(worth, ess)));
|
NumberUtil.displayCurrency(worth, ess)));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue