LibsDisguises/plugin/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoColor.java

72 lines
1.9 KiB
Java
Raw Normal View History

package me.libraryaddict.disguise.utilities.params.types.custom;
2018-09-19 02:26:48 +02:00
import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum;
2018-09-19 02:26:48 +02:00
import org.bukkit.Color;
2022-02-02 08:16:24 +01:00
import java.util.Map;
2018-09-19 02:26:48 +02:00
/**
* Created by libraryaddict on 19/09/2018.
*/
public class ParamInfoColor extends ParamInfoEnum {
private static Map<String, Color> staticColors;
2018-09-23 01:02:53 +02:00
public ParamInfoColor(Class paramClass, String name, String description, Map possibleValues) {
2018-09-19 02:26:48 +02:00
super(paramClass, name, description, possibleValues);
2018-09-23 01:02:53 +02:00
staticColors = (Map<String, Color>) possibleValues;
2018-09-19 02:26:48 +02:00
}
protected Color parseToColor(String string) {
2018-09-23 01:02:53 +02:00
string = string.replace("_", "");
for (Map.Entry<String, Color> entry : staticColors.entrySet()) {
2018-09-23 01:02:53 +02:00
if (!entry.getKey().replace("_", "").equalsIgnoreCase(string)) {
continue;
}
2018-09-19 02:26:48 +02:00
return entry.getValue();
2018-09-19 02:26:48 +02:00
}
String[] split = string.split(",");
if (split.length == 1) {
return Color.fromRGB(Integer.parseInt(split[0]));
} else if (split.length == 3) {
return Color.fromRGB(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
}
return null;
}
2018-09-23 01:02:53 +02:00
@Override
public String toString(Object object) {
Color color = (Color) object;
if (staticColors.containsValue(color)) {
for (String key : staticColors.keySet()) {
if (staticColors.get(key) != color) {
continue;
}
return key;
}
}
return String.format("%s,%s,%s", color.getRed(), color.getGreen(), color.getBlue());
}
2018-09-23 01:02:53 +02:00
@Override
2021-02-26 03:33:11 +01:00
public Object fromString(String string) {
2018-09-23 01:02:53 +02:00
return parseToColor(string);
}
/**
* Is the values it returns all it can do?
*/
@Override
public boolean isCustomValues() {
return true;
}
2018-09-19 02:26:48 +02:00
}