66 lines
2.1 KiB
Java
66 lines
2.1 KiB
Java
package net.saltymc.eaa.custom.ping;
|
|
|
|
import net.saltymc.eaa.EaaMod;
|
|
|
|
import java.io.Serializable;
|
|
|
|
public class PingConfig {
|
|
private static final int DEFAULT_PING_TEXT_COLOR = 0xA0A0A0;
|
|
private static final String DEFAULT_PING_TEXT_FORMAT = "%dms";
|
|
|
|
private boolean autoColorPingText;
|
|
private boolean renderPingBars;
|
|
private int textColor = DEFAULT_PING_TEXT_COLOR;
|
|
private String textFormatString = DEFAULT_PING_TEXT_FORMAT;
|
|
|
|
public PingConfig(ConfigData confileFileFormat) {
|
|
if (confileFileFormat.pingTextColor.startsWith("#")) {
|
|
try {
|
|
textColor = Integer.parseInt(confileFileFormat.pingTextColor.substring(1), 16);
|
|
}
|
|
catch (NumberFormatException ex) {
|
|
EaaMod.LOGGER.error("Config option 'pingTextColor' is invalid - it must be a hex color code");
|
|
}
|
|
}
|
|
else {
|
|
EaaMod.LOGGER.error("Config option 'pingTextColor' is invalid - it must be a hex color code");
|
|
}
|
|
|
|
if (confileFileFormat.pingTextFormatString.contains("%d")) {
|
|
textFormatString = confileFileFormat.pingTextFormatString;
|
|
}
|
|
else {
|
|
EaaMod.LOGGER.error("Config option 'pingTextFormatString' is invalid - it needs to contain %d");
|
|
}
|
|
|
|
autoColorPingText = confileFileFormat.autoColorPingText;
|
|
renderPingBars = confileFileFormat.renderPingBars;
|
|
}
|
|
|
|
public PingConfig() {
|
|
this(new ConfigData());
|
|
}
|
|
|
|
public int getTextColor() {
|
|
return this.textColor;
|
|
}
|
|
|
|
public String getTextFormatString() {
|
|
return this.textFormatString;
|
|
}
|
|
|
|
public boolean shouldAutoColorPingText() {
|
|
return this.autoColorPingText;
|
|
}
|
|
|
|
public boolean shouldRenderPingBars() {
|
|
return this.renderPingBars;
|
|
}
|
|
|
|
public static class ConfigData implements Serializable {
|
|
private boolean autoColorPingText = true;
|
|
private boolean renderPingBars = false;
|
|
private String pingTextColor = "#A0A0A0";
|
|
private String pingTextFormatString = "%dms";
|
|
}
|
|
} |