From edfba6ff4488392cb63c1730a2a4c49f24854fc9 Mon Sep 17 00:00:00 2001 From: AjMaacc Date: Sun, 4 Feb 2024 00:25:48 -0500 Subject: [PATCH] Check for the specific modifier instead of last char in string --- .../earth2me/essentials/commands/Commandpay.java | 15 +++++++++------ .../commands/InvalidModifierException.java | 9 +++++++++ Essentials/src/main/resources/messages.properties | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 Essentials/src/main/java/com/earth2me/essentials/commands/InvalidModifierException.java diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java index 4530c0ee1ea..64fb274ad81 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java @@ -47,25 +47,28 @@ public void run(final Server server, final User user, final String commandLabel, } BigDecimal tempAmount = new BigDecimal(sanitizedString); - switch (Character.toLowerCase(ogStr.charAt(ogStr.length() - 1))) { - case 'k': { + switch (ogStr.replace(sanitizedString, "")) { + case "": { + break; + } + case "k": { tempAmount = tempAmount.multiply(THOUSAND); break; } - case 'm': { + case "m": { tempAmount = tempAmount.multiply(MILLION); break; } - case 'b': { + case "b": { tempAmount = tempAmount.multiply(BILLION); break; } - case 't': { + case "t": { tempAmount = tempAmount.multiply(TRILLION); break; } default: { - break; + throw new InvalidModifierException(); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/InvalidModifierException.java b/Essentials/src/main/java/com/earth2me/essentials/commands/InvalidModifierException.java new file mode 100644 index 00000000000..4cff5d32fc7 --- /dev/null +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/InvalidModifierException.java @@ -0,0 +1,9 @@ +package com.earth2me.essentials.commands; + +import net.ess3.api.TranslatableException; + +public class InvalidModifierException extends TranslatableException { + public InvalidModifierException() { + super("invalidModifier"); + } +} diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 3c448af4170..7082eac9fb1 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -548,6 +548,7 @@ invalidHome=Home {0} doesn''t exist\! invalidHomeName=Invalid home name\! invalidItemFlagMeta=Invalid itemflag meta\: {0}. invalidMob=Invalid mob type. +invalidModifier=Invalid Modifier. invalidNumber=Invalid Number. invalidPotion=Invalid Potion. invalidPotionMeta=Invalid potion meta\: {0}.