diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java index 162f3cb..061f636 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java @@ -106,15 +106,23 @@ public static Color createNamedColor(String name, int value) { //region Parsers - public static Color parse(String color) { - if (colorsWithNames.containsKey(color.toLowerCase())) + @Nullable + public static Color tryParse(String color) { + if (color.startsWith("0x") || color.startsWith("#") || color.startsWith("0X")) + return new Color(Long.decode(color).intValue()); + else if (colorsWithNames.containsKey(color.toLowerCase())) return colorsWithNames.get(color.toLowerCase()); - return new Color(parseColor(color)); + return null; + } + + public static Color parse(String color) { + Color parsedColor = tryParse(color); + return parsedColor == null ? DEFAULT : parsedColor; } public static int parseColor(String color) { Objects.requireNonNull(color); - if (color.startsWith("0x") || color.startsWith("#")) + if (color.startsWith("0x") || color.startsWith("#") || color.startsWith("0X")) return Long.decode(color).intValue(); else if (colorsWithNames.containsKey(color.toLowerCase())) return colorsWithNames.get(color.toLowerCase()).getValue();