public void drawWithColorString(String string, int x, int y, int color) {
if(string.contains("§")){
int x2 = x;
int leer = this.getStringWidth(" ");
if(!string.startsWith("§")){
String wordwithout = string.split(" ")[0];
this.drawString(wordwithout, x2, y, color);
x2 += this.getStringWidth(wordwithout) + leer;
String[] colorss = string.split("§");
for(int i = 1; i < colorss.length; i++){
String colorcode = colorss[i].split("")[0];
int colors = ColorUtils.getFromText(colorcode);
String word = colorss[i].substring(1);
this.drawString(word, x2, y, colors);
x2 += this.getStringWidth(word) + leer;
}
}else{
String[] colorss = string.split("§");
for(int i = 1; i < colorss.length; i++){
String colorcode = colorss[i].split("")[0];
int colors = ColorUtils.getFromText(colorcode);
String word = colorss[i].substring(1);
this.drawString(word, x2, y, colors);
x2 += this.getStringWidth(word) + leer;
}
}
}else{
this.drawString(string, x, y, color);
}
}
@Override
public int getStringWidth(String string) {
if(string.contains("§")){
int ret = 0;
if(!string.startsWith("§")){
ret += font.getWidth(string.split(" ")[0] +" ")/2;
}
String[] colorss = string.split("§");
for(int i = 1; i < colorss.length; i++){
ret += font.getWidth(colorss[i].substring(1) +" ")/2;
}
return ret;
}
return font.getWidth(string) / 2;
}