From 3aa6bcf7c61ae8648988e7e8aeeef8d5bbd2671a Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 14 Jun 2020 21:06:31 +0200 Subject: [PATCH] Rename FormatException to ParseException --- .../chestcommands/action/DragonBarAction.java | 4 +-- .../chestcommands/action/GiveItemAction.java | 4 +-- .../chestcommands/action/GiveMoneyAction.java | 4 +-- .../chestcommands/parser/IconParser.java | 10 +++---- .../chestcommands/parser/ItemMetaParser.java | 18 ++++++------- .../chestcommands/parser/ItemStackParser.java | 4 +-- .../chestcommands/parser/MenuParser.java | 2 +- .../chestcommands/parser/NumberParser.java | 26 +++++++++---------- ...rmatException.java => ParseException.java} | 4 +-- 9 files changed, 38 insertions(+), 38 deletions(-) rename Plugin/src/main/java/me/filoghost/chestcommands/parser/{FormatException.java => ParseException.java} (87%) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java index 866a7b2..921d047 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/DragonBarAction.java @@ -18,7 +18,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.bridge.BarAPIBridge; -import me.filoghost.chestcommands.parser.FormatException; +import me.filoghost.chestcommands.parser.ParseException; import me.filoghost.chestcommands.parser.NumberParser; import me.filoghost.chestcommands.util.FormatUtils; import me.filoghost.chestcommands.variable.RelativeString; @@ -37,7 +37,7 @@ public class DragonBarAction extends Action { try { seconds = NumberParser.getStrictlyPositiveInteger(split[0].trim()); message = split[1].trim(); - } catch (FormatException ex) { + } catch (ParseException ex) { disable(ChatColor.RED + "Invalid dragon bar time: " + split[0]); return; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java index ab8f30f..9dcff14 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveItemAction.java @@ -18,7 +18,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import me.filoghost.chestcommands.parser.FormatException; +import me.filoghost.chestcommands.parser.ParseException; import me.filoghost.chestcommands.parser.ItemStackParser; public class GiveItemAction extends Action { @@ -29,7 +29,7 @@ public class GiveItemAction extends Action { try { ItemStackParser reader = new ItemStackParser(serializedAction, true); itemToGive = reader.createStack(); - } catch (FormatException e) { + } catch (ParseException e) { disable(ChatColor.RED + "Invalid item to give: " + e.getMessage()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java index 2e5c8d7..2dc578f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/action/GiveMoneyAction.java @@ -18,7 +18,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import me.filoghost.chestcommands.bridge.EconomyBridge; -import me.filoghost.chestcommands.parser.FormatException; +import me.filoghost.chestcommands.parser.ParseException; import me.filoghost.chestcommands.parser.NumberParser; public class GiveMoneyAction extends Action { @@ -28,7 +28,7 @@ public class GiveMoneyAction extends Action { public GiveMoneyAction(String action) { try { moneyToGive = NumberParser.getStrictlyPositiveDouble(action); - } catch (FormatException e) { + } catch (ParseException e) { disable(ChatColor.RED + "Invalid money amount: " + action); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java index 9903308..6cbb1f6 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/IconParser.java @@ -102,7 +102,7 @@ public class IconParser { icon.setMaterial(itemReader.getMaterial()); icon.setDurability(itemReader.getDurability()); icon.setAmount(itemReader.getAmount()); - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid MATERIAL: " + e.getMessage()); } } @@ -152,7 +152,7 @@ public class IconParser { if (section.isSet(Nodes.COLOR)) { try { icon.setLeatherColor(ItemMetaParser.parseColor(section.getString(Nodes.COLOR))); - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid COLOR: " + e.getMessage()); } } @@ -163,7 +163,7 @@ public class IconParser { if (bannerColor != null) { try { icon.setBannerColor(ItemMetaParser.parseDyeColor(bannerColor)); - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid BANNER-COLOR: " + e.getMessage()); } } @@ -171,7 +171,7 @@ public class IconParser { if (section.isSet(Nodes.BANNER_PATTERNS)) { try { icon.setBannerPatterns(ItemMetaParser.parseBannerPatternList(section.getStringList(Nodes.BANNER_PATTERNS))); - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid BANNER-PATTERNS: " + e.getMessage()); } } @@ -226,7 +226,7 @@ public class IconParser { requiredItem.setRestrictiveDurability(itemReader.getDurability()); } requiredItems.add(requiredItem); - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has invalid REQUIRED-ITEMS: " + e.getMessage()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java index f22c41d..676ebde 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemMetaParser.java @@ -31,11 +31,11 @@ public final class ItemMetaParser { private ItemMetaParser() {} - public static Color parseColor(String input) throws FormatException { + public static Color parseColor(String input) throws ParseException { String[] split = input.replace(" ", "").split(","); if (split.length != 3) { - throw new FormatException("it must be in the format \"red, green, blue\"."); + throw new ParseException("it must be in the format \"red, green, blue\"."); } int red, green, blue; @@ -45,38 +45,38 @@ public final class ItemMetaParser { green = Integer.parseInt(split[1]); blue = Integer.parseInt(split[2]); } catch (NumberFormatException ex) { - throw new FormatException("it contains invalid numbers."); + throw new ParseException("it contains invalid numbers."); } if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) { - throw new FormatException("it should only contain numbers between 0 and 255."); + throw new ParseException("it should only contain numbers between 0 and 255."); } return Color.fromRGB(red, green, blue); } - public static DyeColor parseDyeColor(String input) throws FormatException { + public static DyeColor parseDyeColor(String input) throws ParseException { DyeColor color = DYE_COLORS_REGISTRY.find(input); if (color == null) { - throw new FormatException("it must be a valid color."); + throw new ParseException("it must be a valid color."); } return color; } - public static List parseBannerPatternList(List input) throws FormatException { + public static List parseBannerPatternList(List input) throws ParseException { List patterns = new ArrayList(); for (String str : input) { String[] split = str.split(":"); if (split.length != 2) { - throw new FormatException("it must be in the format \"pattern:color\"."); + throw new ParseException("it must be in the format \"pattern:color\"."); } PatternType patternType = PATTERN_TYPES_REGISTRY.find(split[0]); DyeColor patternColor = parseDyeColor(split[1]); if (patternType == null) { - throw new FormatException("it must be a valid pattern type."); + throw new ParseException("it must be a valid pattern type."); } patterns.add(new Pattern(patternColor, patternType)); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java index cd69254..d6ee3bd 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ItemStackParser.java @@ -32,7 +32,7 @@ public class ItemStackParser { * id can be either the id of the material or its name. * for example wool:5, 3 is a valid input. */ - public ItemStackParser(String input, boolean parseAmount) throws FormatException { + public ItemStackParser(String input, boolean parseAmount) throws ParseException { Preconditions.notNull(input, "input"); // Remove spaces, they're not needed @@ -67,7 +67,7 @@ public class ItemStackParser { Material material = MaterialsHelper.matchMaterial(input); if (material == null || MaterialsHelper.isAir(material)) { - throw new FormatException("invalid material \"" + input + "\""); + throw new ParseException("invalid material \"" + input + "\""); } this.material = material; } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java index 122cedc..d920f34 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/MenuParser.java @@ -158,7 +158,7 @@ public class MenuParser { openTrigger.setRestrictiveDurability(itemReader.getDurability()); } - } catch (FormatException e) { + } catch (ParseException e) { errorCollector.addError("The item \"" + openItemMaterial + "\" used to open the menu \"" + config.getFileName() + "\" is invalid: " + e.getMessage()); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java index 2e7db8f..b047c0c 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/NumberParser.java @@ -16,59 +16,59 @@ package me.filoghost.chestcommands.parser; public class NumberParser { - public static double getStrictlyPositiveDouble(String input) throws FormatException { + public static double getStrictlyPositiveDouble(String input) throws ParseException { return getStrictlyPositiveDouble(input, "number must be a valid decimal and greater than 0"); } - public static double getStrictlyPositiveDouble(String input, String errorMessage) throws FormatException { + public static double getStrictlyPositiveDouble(String input, String errorMessage) throws ParseException { double value = getDouble(input, errorMessage); check(value > 0.0, errorMessage); return value; } - private static double getDouble(String input, String errorMessage) throws FormatException { + private static double getDouble(String input, String errorMessage) throws ParseException { try { return Double.parseDouble(input); } catch (NumberFormatException ex) { - throw new FormatException(errorMessage); + throw new ParseException(errorMessage); } } - public static short getPositiveShort(String input, String errorMessage) throws FormatException { + public static short getPositiveShort(String input, String errorMessage) throws ParseException { short value = getShort(input, errorMessage); check(value >= 0, errorMessage); return value; } - public static short getShort(String input, String errorMessage) throws FormatException { + public static short getShort(String input, String errorMessage) throws ParseException { try { return Short.parseShort(input); } catch (NumberFormatException ex) { - throw new FormatException(errorMessage); + throw new ParseException(errorMessage); } } - public static int getStrictlyPositiveInteger(String input) throws FormatException { + public static int getStrictlyPositiveInteger(String input) throws ParseException { return getStrictlyPositiveInteger(input, "number must be a valid integer and greater than 0"); } - public static int getStrictlyPositiveInteger(String input, String errorMessage) throws FormatException { + public static int getStrictlyPositiveInteger(String input, String errorMessage) throws ParseException { int value = getInteger(input, errorMessage); check(value > 0, errorMessage); return value; } - public static int getInteger(String input, String errorMessage) throws FormatException { + public static int getInteger(String input, String errorMessage) throws ParseException { try { return Integer.parseInt(input); } catch (NumberFormatException ex) { - throw new FormatException(errorMessage); + throw new ParseException(errorMessage); } } - private static void check(boolean expression, String errorMessage) throws FormatException { + private static void check(boolean expression, String errorMessage) throws ParseException { if (!expression) { - throw new FormatException(errorMessage); + throw new ParseException(errorMessage); } } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parser/FormatException.java b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ParseException.java similarity index 87% rename from Plugin/src/main/java/me/filoghost/chestcommands/parser/FormatException.java rename to Plugin/src/main/java/me/filoghost/chestcommands/parser/ParseException.java index d98eac3..5f62736 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parser/FormatException.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parser/ParseException.java @@ -14,11 +14,11 @@ */ package me.filoghost.chestcommands.parser; -public class FormatException extends Exception { +public class ParseException extends Exception { private static final long serialVersionUID = 1L; - public FormatException(String message) { + public ParseException(String message) { super(message); } }