Skip to content

Commit

Permalink
removed left and right text fields and added profile color field to p…
Browse files Browse the repository at this point in the history
…aid ranks
  • Loading branch information
firef1a committed Jun 3, 2024
1 parent e22f45e commit 41c95a0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 83 deletions.
28 changes: 3 additions & 25 deletions src/main/java/dev/fire/TextUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,7 @@ public static Text replaceTags(Text text, boolean isTabList) {
ChatTag normal = DefaultConfig.newChatTags.get(key);
MiniMessageChatTag custom = c.chatTags.get(key);

int color;
TextColor colorObj = null;

if (!custom.getAsFormatted(custom.mainvalue).getSiblings().isEmpty()) {
colorObj = custom.getAsFormatted(custom.mainvalue).getSiblings().get(0).getStyle().getColor();
}
if (colorObj == null) {
//color = DefaultConfig.newChatTags.get(key).TextColor;
color = 0xffffff;
} else {
color = colorObj.getRgb();
}

int color = custom.ProfileColor;
// replace
text = replaceTextInternal(text, getProfileLine(normal.TextColor,false), getProfileLine(color,false), false);
text = replaceTextInternal(text, getProfileLine(normal.TextColor, true), getProfileLine(color,true), false);
Expand All @@ -223,18 +211,8 @@ public static Text replaceTags(Text text, boolean isTabList) {

// vipenabled / disabled logic
MiniMessageChatTag custom_vip = c.chatTags.get("vip");
int color;
TextColor colorObj = null;

if (!custom_vip.getAsFormatted(custom_vip.mainvalue).getSiblings().isEmpty()) {
colorObj = custom_vip.getAsFormatted(custom_vip.mainvalue).getSiblings().get(0).getStyle().getColor();
}
if (colorObj == null) {
//color = DefaultConfig.newChatTags.get(key).TextColor;
color = 0xffffff;
} else {
color = colorObj.getRgb();
}
int color = custom_vip.ProfileColor;

if (!c.VipEnabled) {
text = replaceTextInternal(text, VIP_PREFIX, Text.empty(), true);
text = replaceTextInternal(text, VIP_WHOIS, Text.empty(), false);
Expand Down
61 changes: 28 additions & 33 deletions src/main/java/dev/fire/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.isxander.yacl3.api.controller.*;
import net.minecraft.text.Text;

import java.awt.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand Down Expand Up @@ -41,9 +42,9 @@ public static Map<String, MiniMessageChatTag> convertToMinimessage(Map<String, C
int bracketColor = DefaultConfig.newChatTags.get("vip").BracketColor;
int symbolColor = DefaultConfig.newChatTags.get("vip").SymbolColor;

mmobj.leftvalue = ChatTag.convertStringWithColorToMiniMessage("[", bracketColor);
mmobj.mainvalue = ChatTag.convertStringWithColorToMiniMessage("⭐", symbolColor);
mmobj.rightvalue = ChatTag.convertStringWithColorToMiniMessage("]", bracketColor);
mmobj.mainvalue = ChatTag.convertStringWithColorToMiniMessage("[", bracketColor) +
ChatTag.convertStringWithColorToMiniMessage("⭐", symbolColor) +
ChatTag.convertStringWithColorToMiniMessage("]", bracketColor);

mmobj.shortvalue =
ChatTag.convertStringWithColorToMiniMessage("[", bracketColor) +
Expand Down Expand Up @@ -150,22 +151,10 @@ public YetAnotherConfigLib getLibConfig() {
}


private OptionGroup groupBuilder(String key, String name) {
private OptionGroup.Builder groupBuilder(String key, String name) {
return OptionGroup.createBuilder()
.name(Text.literal(name))
.description(OptionDescription.of(Text.literal(name + " Chat Tag")))
.option(Option.createBuilder(String.class)
.name(Text.literal("Left Text Value"))
.description(OptionDescription.createBuilder()
.text(Text.literal("Formatted in MiniMessage"))
.build())
.binding(
DefaultConfig.oldChatTags.get(key).toLeftMiniMessage(),
() -> chatTags.get(key).leftvalue,
opt -> chatTags.get(key).leftvalue = opt
)
.controller(StringControllerBuilder::create)
.build())
.option(Option.createBuilder(String.class)
.name(Text.literal("Main Text Value"))
.description(OptionDescription.createBuilder()
Expand All @@ -178,18 +167,6 @@ private OptionGroup groupBuilder(String key, String name) {
)
.controller(StringControllerBuilder::create)
.build())
.option(Option.createBuilder(String.class)
.name(Text.literal("Right Text Value"))
.description(OptionDescription.createBuilder()
.text(Text.literal("Formatted in MiniMessage"))
.build())
.binding(
DefaultConfig.oldChatTags.get(key).toRightMiniMessage(),
() -> chatTags.get(key).rightvalue,
opt -> chatTags.get(key).rightvalue = opt
)
.controller(StringControllerBuilder::create)
.build())
.option(Option.createBuilder(String.class)
.name(Text.literal("Short Tag Value"))
.description(OptionDescription.createBuilder()
Expand All @@ -201,8 +178,8 @@ private OptionGroup groupBuilder(String key, String name) {
opt -> chatTags.get(key).shortvalue = opt
)
.controller(StringControllerBuilder::create)
.build())
.build();
.build());


}

Expand Down Expand Up @@ -277,7 +254,9 @@ private ConfigCategory.Builder staffChatTags() {
if (key == "emeritus") {
name = "Emeritus";
}
configBuilder.group(groupBuilder(key,name));

OptionGroup.Builder builder = groupBuilder(key,name);
configBuilder.group(builder.build());
});

return configBuilder;
Expand All @@ -293,7 +272,21 @@ private ConfigCategory.Builder normalChatTags() {
normalChatTagList.forEach(k -> {
String key = (String) k;
String name = DefaultConfig.newChatTags.get(key).TextContent;
configBuilder.group(groupBuilder(key,name));

OptionGroup.Builder builder = groupBuilder(key,name);
builder.option(Option.createBuilder(Color.class)
.name(Text.literal("/whois Color"))
.description(OptionDescription.createBuilder()
.text(Text.literal("Color of your /whois, dictated by the highest paid rank you have. ie: Overlord, Mythic, Emperor, or Noble. "))
.build())
.binding(
new Color(DefaultConfig.oldChatTags.get(key).TextColor),
() -> new Color(chatTags.get(key).ProfileColor),
opt -> chatTags.get(key).ProfileColor = opt.getRGB()
)
.controller(ColorControllerBuilder::create)
.build());
configBuilder.group(builder.build());
});

return configBuilder;
Expand All @@ -309,7 +302,9 @@ private ConfigCategory.Builder specialChatTags() {
specialChatTagList.forEach(k -> {
String key = (String) k;
String name = DefaultConfig.newChatTags.get(key).TextContent;
configBuilder.group(groupBuilder(key,name));

OptionGroup.Builder builder = groupBuilder(key,name);
configBuilder.group(builder.build());
});

return configBuilder;
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/dev/fire/utils/ChatTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,15 @@ public String toJson(){
return object.toString();
}

public String toLeftMiniMessage() {
public String toMainMiniMessage() {
String minimessage = "";
minimessage = minimessage + convertStringWithColorToMiniMessage("[", BracketColor);
minimessage = minimessage + convertStringWithColorToMiniMessage(Symbol, SymbolColor);
if ( addBoldSpace ) minimessage = minimessage + "<bold>\u200C</bold>";
return minimessage;
}
public String toRightMiniMessage() {
String minimessage = "";
minimessage = minimessage + convertStringWithColorToMiniMessage(TextContent, TextColor);
if ( addBoldSpace ) minimessage = minimessage + "<bold>\u200C</bold>";
minimessage = minimessage + convertStringWithColorToMiniMessage(Symbol, SymbolColor);
minimessage = minimessage + convertStringWithColorToMiniMessage("]", BracketColor);
return minimessage;
}

public String toMainMiniMessage() {
String minimessage = "";
minimessage = minimessage + convertStringWithColorToMiniMessage(TextContent, TextColor);

return minimessage;
}
Expand Down
18 changes: 4 additions & 14 deletions src/main/java/dev/fire/utils/MiniMessageChatTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,17 @@

public class MiniMessageChatTag implements Serializable {
public String mainvalue;
public String leftvalue;
public String rightvalue;
public String shortvalue;

public MiniMessageChatTag(String leftvalue, String mainvalue, String rightvalue, String shortvalue) {
this.leftvalue = leftvalue;
this.mainvalue = mainvalue;
this.rightvalue = rightvalue;
this.shortvalue = shortvalue;
}
public int ProfileColor;

public MiniMessageChatTag(ChatTag chattag) {
this.leftvalue = chattag.toLeftMiniMessage();
this.mainvalue = chattag.toMainMiniMessage();
this.rightvalue = chattag.toRightMiniMessage();
this.shortvalue = chattag.toShortValue();
this.ProfileColor = chattag.TextColor;
}

public Text getAsFormatted() {
return MiniMessage.format(leftvalue +mainvalue+ rightvalue, false);
return MiniMessage.format( mainvalue, false);
}
public Text getAsFormatted(String input) {
return MiniMessage.format(input, false);
Expand All @@ -37,9 +28,8 @@ public Text getAsShortFormatted() {
public String toJson(){
JsonObject object = new JsonObject();
object.addProperty("mainvalue", mainvalue);
object.addProperty("leftvalue", leftvalue);
object.addProperty("rightvalue", rightvalue);
object.addProperty("shortvalue", shortvalue);
object.addProperty("ProfileColor", ProfileColor);
return object.toString();
}
}

0 comments on commit 41c95a0

Please sign in to comment.