[X] I'm using the latest version of Lunar Client. (Relaunched in the last hour)
[X] I'm running Apollo on ONLY the backend server OR the proxy. (YOU CANNOT RUN IT ON BOTH)
[X] I do NOT have both Apollo and the LEGACY API installed on the same server. (YOU CANNOT RUN BOTH AT THE SAME TIME)
[X] I've gathered all screenshots, logs and appropriate information related to creating a bug report.
Issue Description
I'm encountering a ClassCastException when attempting to use Java's Color class within the configuration system provided by Apollo. The error occurs specifically when trying to serialize and deserialize Color objects.
When you try to use any rgba colors like this:
background-color: "#FFFFCC99"
border-color: "#FF99FFFF"
Reproduction steps
Steps to Reproduce:
Configure an option to use java.awt.Color in the Apollo configuration.
Attempt to serialize or deserialize this configuration.
Expected Behavior:
Color objects should be serialized to a String format (e.g., "#AARRGGBB") and deserialized back to a Color object without issues.
Actual Behavior:
A ClassCastException is thrown with the following stack trace:
java.lang.ClassCastException: class java.awt.Color cannot be cast to class java.lang.String (java.awt.Color is in module java.desktop of loader 'bootstrap'; java.lang.String is in module java.base of loader 'bootstrap')
at com.lunarclient.apollo.option.OptionsImpl.wrapValue(OptionsImpl.java:276)
at com.lunarclient.apollo.option.OptionsImpl.postPacket(OptionsImpl.java:342)
...
Details:
The issue seems to stem from the OptionsImpl class's wrapValue method, where Color objects are being cast incorrectly to String. The relevant part of the code is:
else if (Color.class.isAssignableFrom(clazz)) {
return valueBuilder.setStringValue((String) current).build(); // This causes ClassCastException
}
Suggested Fix:
Modify the wrapValue and unwrapValue methods to correctly handle Color serialization and deserialization by converting Color to and from its string representation using the format #AARRGGBB.
Code Example:
else if (Color.class.isAssignableFrom(clazz)) {
String colorString = String.format("#%08X", ((Color) current).getRGB());
return valueBuilder.setStringValue(colorString).build();
}
and similarly for unwrapValue:
else if (Color.class.isAssignableFrom(clazz) && wrapper.hasStringValue()) {
String colorString = wrapper.getStringValue();
// Logic to convert the string to Color
}
Checklist before creating an issue:
Issue Description
I'm encountering a ClassCastException when attempting to use Java's Color class within the configuration system provided by Apollo. The error occurs specifically when trying to serialize and deserialize Color objects.
When you try to use any rgba colors like this: background-color: "#FFFFCC99" border-color: "#FF99FFFF"
Reproduction steps
Code Snippet (If applicable, if not write N/A)
N/A
Versions
1.8
Platforms
BungeeCord
Server Version
1.8
Modules
Optifine
Screenshots
Contact Information
Additional Context (Examples, Links, ETC)
No response