mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-29 13:36:04 +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 org.bukkit.entity.Player;
|
||||||
|
|
||||||
import me.filoghost.chestcommands.bridge.BarAPIBridge;
|
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.parser.NumberParser;
|
||||||
import me.filoghost.chestcommands.util.FormatUtils;
|
import me.filoghost.chestcommands.util.FormatUtils;
|
||||||
import me.filoghost.chestcommands.variable.RelativeString;
|
import me.filoghost.chestcommands.variable.RelativeString;
|
||||||
@ -37,7 +37,7 @@ public class DragonBarAction extends Action {
|
|||||||
try {
|
try {
|
||||||
seconds = NumberParser.getStrictlyPositiveInteger(split[0].trim());
|
seconds = NumberParser.getStrictlyPositiveInteger(split[0].trim());
|
||||||
message = split[1].trim();
|
message = split[1].trim();
|
||||||
} catch (FormatException ex) {
|
} catch (ParseException ex) {
|
||||||
disable(ChatColor.RED + "Invalid dragon bar time: " + split[0]);
|
disable(ChatColor.RED + "Invalid dragon bar time: " + split[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import me.filoghost.chestcommands.parser.FormatException;
|
import me.filoghost.chestcommands.parser.ParseException;
|
||||||
import me.filoghost.chestcommands.parser.ItemStackParser;
|
import me.filoghost.chestcommands.parser.ItemStackParser;
|
||||||
|
|
||||||
public class GiveItemAction extends Action {
|
public class GiveItemAction extends Action {
|
||||||
@ -29,7 +29,7 @@ public class GiveItemAction extends Action {
|
|||||||
try {
|
try {
|
||||||
ItemStackParser reader = new ItemStackParser(serializedAction, true);
|
ItemStackParser reader = new ItemStackParser(serializedAction, true);
|
||||||
itemToGive = reader.createStack();
|
itemToGive = reader.createStack();
|
||||||
} catch (FormatException e) {
|
} catch (ParseException e) {
|
||||||
disable(ChatColor.RED + "Invalid item to give: " + e.getMessage());
|
disable(ChatColor.RED + "Invalid item to give: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import me.filoghost.chestcommands.bridge.EconomyBridge;
|
import me.filoghost.chestcommands.bridge.EconomyBridge;
|
||||||
import me.filoghost.chestcommands.parser.FormatException;
|
import me.filoghost.chestcommands.parser.ParseException;
|
||||||
import me.filoghost.chestcommands.parser.NumberParser;
|
import me.filoghost.chestcommands.parser.NumberParser;
|
||||||
|
|
||||||
public class GiveMoneyAction extends Action {
|
public class GiveMoneyAction extends Action {
|
||||||
@ -28,7 +28,7 @@ public class GiveMoneyAction extends Action {
|
|||||||
public GiveMoneyAction(String action) {
|
public GiveMoneyAction(String action) {
|
||||||
try {
|
try {
|
||||||
moneyToGive = NumberParser.getStrictlyPositiveDouble(action);
|
moneyToGive = NumberParser.getStrictlyPositiveDouble(action);
|
||||||
} catch (FormatException e) {
|
} catch (ParseException e) {
|
||||||
disable(ChatColor.RED + "Invalid money amount: " + action);
|
disable(ChatColor.RED + "Invalid money amount: " + action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ public class IconParser {
|
|||||||
icon.setMaterial(itemReader.getMaterial());
|
icon.setMaterial(itemReader.getMaterial());
|
||||||
icon.setDurability(itemReader.getDurability());
|
icon.setDurability(itemReader.getDurability());
|
||||||
icon.setAmount(itemReader.getAmount());
|
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());
|
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)) {
|
if (section.isSet(Nodes.COLOR)) {
|
||||||
try {
|
try {
|
||||||
icon.setLeatherColor(ItemMetaParser.parseColor(section.getString(Nodes.COLOR)));
|
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());
|
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) {
|
if (bannerColor != null) {
|
||||||
try {
|
try {
|
||||||
icon.setBannerColor(ItemMetaParser.parseDyeColor(bannerColor));
|
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());
|
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)) {
|
if (section.isSet(Nodes.BANNER_PATTERNS)) {
|
||||||
try {
|
try {
|
||||||
icon.setBannerPatterns(ItemMetaParser.parseBannerPatternList(section.getStringList(Nodes.BANNER_PATTERNS)));
|
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());
|
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());
|
requiredItem.setRestrictiveDurability(itemReader.getDurability());
|
||||||
}
|
}
|
||||||
requiredItems.add(requiredItem);
|
requiredItems.add(requiredItem);
|
||||||
} catch (FormatException e) {
|
} catch (ParseException e) {
|
||||||
errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has invalid REQUIRED-ITEMS: " + e.getMessage());
|
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() {}
|
private ItemMetaParser() {}
|
||||||
|
|
||||||
|
|
||||||
public static Color parseColor(String input) throws FormatException {
|
public static Color parseColor(String input) throws ParseException {
|
||||||
String[] split = input.replace(" ", "").split(",");
|
String[] split = input.replace(" ", "").split(",");
|
||||||
|
|
||||||
if (split.length != 3) {
|
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;
|
int red, green, blue;
|
||||||
@ -45,38 +45,38 @@ public final class ItemMetaParser {
|
|||||||
green = Integer.parseInt(split[1]);
|
green = Integer.parseInt(split[1]);
|
||||||
blue = Integer.parseInt(split[2]);
|
blue = Integer.parseInt(split[2]);
|
||||||
} catch (NumberFormatException ex) {
|
} 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) {
|
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);
|
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);
|
DyeColor color = DYE_COLORS_REGISTRY.find(input);
|
||||||
|
|
||||||
if (color == null) {
|
if (color == null) {
|
||||||
throw new FormatException("it must be a valid color.");
|
throw new ParseException("it must be a valid color.");
|
||||||
}
|
}
|
||||||
return 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>();
|
List<Pattern> patterns = new ArrayList<Pattern>();
|
||||||
for (String str : input) {
|
for (String str : input) {
|
||||||
String[] split = str.split(":");
|
String[] split = str.split(":");
|
||||||
if (split.length != 2) {
|
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]);
|
PatternType patternType = PATTERN_TYPES_REGISTRY.find(split[0]);
|
||||||
DyeColor patternColor = parseDyeColor(split[1]);
|
DyeColor patternColor = parseDyeColor(split[1]);
|
||||||
|
|
||||||
if (patternType == null) {
|
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));
|
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.
|
* id can be either the id of the material or its name.
|
||||||
* for example wool:5, 3 is a valid input.
|
* 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");
|
Preconditions.notNull(input, "input");
|
||||||
|
|
||||||
// Remove spaces, they're not needed
|
// Remove spaces, they're not needed
|
||||||
@ -67,7 +67,7 @@ public class ItemStackParser {
|
|||||||
Material material = MaterialsHelper.matchMaterial(input);
|
Material material = MaterialsHelper.matchMaterial(input);
|
||||||
|
|
||||||
if (material == null || MaterialsHelper.isAir(material)) {
|
if (material == null || MaterialsHelper.isAir(material)) {
|
||||||
throw new FormatException("invalid material \"" + input + "\"");
|
throw new ParseException("invalid material \"" + input + "\"");
|
||||||
}
|
}
|
||||||
this.material = material;
|
this.material = material;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ public class MenuParser {
|
|||||||
openTrigger.setRestrictiveDurability(itemReader.getDurability());
|
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());
|
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 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");
|
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);
|
double value = getDouble(input, errorMessage);
|
||||||
check(value > 0.0, errorMessage);
|
check(value > 0.0, errorMessage);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double getDouble(String input, String errorMessage) throws FormatException {
|
private static double getDouble(String input, String errorMessage) throws ParseException {
|
||||||
try {
|
try {
|
||||||
return Double.parseDouble(input);
|
return Double.parseDouble(input);
|
||||||
} catch (NumberFormatException ex) {
|
} 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);
|
short value = getShort(input, errorMessage);
|
||||||
check(value >= 0, errorMessage);
|
check(value >= 0, errorMessage);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short getShort(String input, String errorMessage) throws FormatException {
|
public static short getShort(String input, String errorMessage) throws ParseException {
|
||||||
try {
|
try {
|
||||||
return Short.parseShort(input);
|
return Short.parseShort(input);
|
||||||
} catch (NumberFormatException ex) {
|
} 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");
|
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);
|
int value = getInteger(input, errorMessage);
|
||||||
check(value > 0, errorMessage);
|
check(value > 0, errorMessage);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getInteger(String input, String errorMessage) throws FormatException {
|
public static int getInteger(String input, String errorMessage) throws ParseException {
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(input);
|
return Integer.parseInt(input);
|
||||||
} catch (NumberFormatException ex) {
|
} 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) {
|
if (!expression) {
|
||||||
throw new FormatException(errorMessage);
|
throw new ParseException(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
*/
|
*/
|
||||||
package me.filoghost.chestcommands.parser;
|
package me.filoghost.chestcommands.parser;
|
||||||
|
|
||||||
public class FormatException extends Exception {
|
public class ParseException extends Exception {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public FormatException(String message) {
|
public ParseException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user