From dcf90cbf5a890bebb2ab551d04a6a60fe1f7d434 Mon Sep 17 00:00:00 2001 From: Iaccidentally Date: Wed, 31 Oct 2012 16:25:13 -0400 Subject: [PATCH] Make /exp accept L before or after the amount, add extra checks --- .../com/earth2me/essentials/commands/Commandexp.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java index f3dac79e2..08fb61ea1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java @@ -125,11 +125,11 @@ public class Commandexp extends EssentialsCommand sender.sendMessage(_("exp", target.getDisplayName(), SetExpFix.getTotalExperience(target), target.getLevel(), SetExpFix.getExpUntilNextLevel(target))); } - private void setExp(final CommandSender sender, final User target, String strAmount, final boolean give) + private void setExp(final CommandSender sender, final User target, String strAmount, final boolean give) throws NotEnoughArgumentsException { Long amount; strAmount = strAmount.toLowerCase(Locale.ENGLISH); - if (strAmount.startsWith("l")) + if (strAmount.startsWith("l") || strAmount.endsWith("l")) { strAmount = strAmount.substring(1); int neededLevel = Integer.parseInt(strAmount); @@ -141,7 +141,7 @@ public class Commandexp extends EssentialsCommand SetExpFix.setTotalExperience(target, 0); } else { - amount = Long.parseLong(strAmount); + amount = (long)Integer.parseInt(strAmount); } if (give) @@ -152,6 +152,10 @@ public class Commandexp extends EssentialsCommand { amount = (long)Integer.MAX_VALUE; } + if (amount < 0 || amount > Integer.MAX_VALUE) + { + throw new NotEnoughArgumentsException(); + } SetExpFix.setTotalExperience(target, amount.intValue()); sender.sendMessage(_("expSet", target.getDisplayName(), amount)); }