From acaf715482afd96eb37d09a5c6a659478e4ab3ae Mon Sep 17 00:00:00 2001 From: CodexAdrian <83074853+CodexAdrian@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:14:01 -0400 Subject: [PATCH 1/2] Add try parse function --- .../resourcefullib/common/color/Color.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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..513d3ac 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,22 @@ public static Color createNamedColor(String name, int value) { //region Parsers - public static Color parse(String color) { - if (colorsWithNames.containsKey(color.toLowerCase())) + 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(); From fca6d6897745a635b899c352c832d28ab2509cb9 Mon Sep 17 00:00:00 2001 From: CodexAdrian <83074853+CodexAdrian@users.noreply.github.com> Date: Tue, 10 Sep 2024 20:37:34 -0400 Subject: [PATCH 2/2] Update Color.java --- .../com/teamresourceful/resourcefullib/common/color/Color.java | 1 + 1 file changed, 1 insertion(+) 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 513d3ac..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,6 +106,7 @@ public static Color createNamedColor(String name, int value) { //region Parsers + @Nullable public static Color tryParse(String color) { if (color.startsWith("0x") || color.startsWith("#") || color.startsWith("0X")) return new Color(Long.decode(color).intValue());