mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-25 19:45:44 +01:00
Rename FormatException to ParseException
This commit is contained in:
parent
99665821ec
commit
3aa6bcf7c6
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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<Pattern> parseBannerPatternList(List<String> input) throws FormatException {
|
||||
public static List<Pattern> parseBannerPatternList(List<String> input) throws ParseException {
|
||||
List<Pattern> patterns = new ArrayList<Pattern>();
|
||||
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));
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user