mirror of
https://github.com/NEZNAMY/TAB.git
synced 2026-11-26 10:29:49 -05:00
small cleanup and improvement
This commit is contained in:
1 parent
24a2e36d78
commit
6cac59d41e
2 files changed
+43
-19
No files matched your search
@@ -165,6 +165,11 @@ public class IChatBaseComponent {
|
||||
*/
|
||||
public IChatBaseComponent setColor(TextColor color) {
|
||||
this.color = color;
|
||||
if (color != null) {
|
||||
jsonObject.put("color", color.toString(true));
|
||||
} else {
|
||||
jsonObject.remove("color");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -342,7 +347,7 @@ public class IChatBaseComponent {
|
||||
* @return self
|
||||
*/
|
||||
public IChatBaseComponent onHoverShowText(IChatBaseComponent text) {
|
||||
return onHover(HoverAction.SHOW_TEXT, text.jsonObject);
|
||||
return onHover(HoverAction.SHOW_TEXT, text);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -494,16 +499,7 @@ public class IChatBaseComponent {
|
||||
}
|
||||
}
|
||||
//the core component, fixing all colors
|
||||
if (color != null) {
|
||||
jsonObject.put("color", color.toString(clientVersion.getMinorVersion() >= 16));
|
||||
}
|
||||
if (extra != null) {
|
||||
for (IChatBaseComponent extra : extra) {
|
||||
if (extra.color != null) {
|
||||
extra.jsonObject.put("color", extra.color.toString(clientVersion.getMinorVersion() >= 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (clientVersion.getMinorVersion() < 16) convertColorsToLegacy();
|
||||
return toString();
|
||||
}
|
||||
|
||||
@@ -511,6 +507,20 @@ public class IChatBaseComponent {
|
||||
public String toString() {
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
private void convertColorsToLegacy() {
|
||||
if (color != null) {
|
||||
jsonObject.put("color", color.getLegacyColor().toString().toLowerCase());
|
||||
}
|
||||
if (extra != null) {
|
||||
for (IChatBaseComponent extra : extra) {
|
||||
extra.convertColorsToLegacy();
|
||||
}
|
||||
}
|
||||
if (hoverValue instanceof IChatBaseComponent) {
|
||||
((IChatBaseComponent)hoverValue).convertColorsToLegacy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns organized component from colored text
|
||||
|
||||
@@ -21,9 +21,8 @@ public class TextColor {
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new instance based on hex code as string
|
||||
* Creates a new instance based on hex code as string
|
||||
* @param hexCode - a 6-digit combination of hex numbers
|
||||
* @return TextColor from hex color
|
||||
*/
|
||||
public TextColor(String hexCode) {
|
||||
int hexColor = Integer.parseInt(hexCode, 16);
|
||||
@@ -34,9 +33,8 @@ public class TextColor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance based on legacy color
|
||||
* Creates a new instance with given parameter
|
||||
* @param legacyColor - legacy color
|
||||
* @return TextColor from legacy color
|
||||
*/
|
||||
public TextColor(EnumChatFormat legacyColor) {
|
||||
red = legacyColor.getRed();
|
||||
@@ -46,11 +44,10 @@ public class TextColor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance based on color bytes
|
||||
* Creates a new instance with given parameters
|
||||
* @param red - red value
|
||||
* @param green - green value
|
||||
* @param blue - blue value
|
||||
* @return TextColor from RGB combination
|
||||
*/
|
||||
public TextColor(int red, int green, int blue) {
|
||||
this.red = red;
|
||||
@@ -59,6 +56,23 @@ public class TextColor {
|
||||
loadClosestColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance with given parameters
|
||||
* @param red - red value
|
||||
* @param green - green value
|
||||
* @param blue - blue value
|
||||
* @param legacyColor
|
||||
*/
|
||||
public TextColor(int red, int green, int blue, EnumChatFormat legacyColor) {
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
this.legacyColor = legacyColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads closest legacy color based on current rgb values
|
||||
*/
|
||||
private void loadClosestColor() {
|
||||
double minDist = 9999;
|
||||
double dist;
|
||||
@@ -100,8 +114,8 @@ public class TextColor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the closest legacy color
|
||||
* @return closest legacy color
|
||||
* Returns defined legacy color
|
||||
* @return defined legacy color
|
||||
*/
|
||||
public EnumChatFormat getLegacyColor() {
|
||||
return legacyColor;
|
||||
|
||||
Reference in new issue
Block a user