Skip to content

Commit

Permalink
added minimessage integration
Browse files Browse the repository at this point in the history
  • Loading branch information
firef1a committed Jun 3, 2024
1 parent fcc2132 commit c34ed11
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 52 deletions.
67 changes: 44 additions & 23 deletions src/main/java/dev/fire/TextUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package dev.fire;

import dev.fire.config.ChatTag;
import dev.fire.config.MiniMessageChatTag;
import net.minecraft.network.message.SentMessage;
import dev.fire.utils.ChatTag;
import dev.fire.utils.MiniMessageChatTag;
import net.minecraft.text.*;
import dev.fire.config.Config;
import dev.fire.config.DefaultConfig;
Expand Down Expand Up @@ -193,46 +192,68 @@ public static Text replaceTags(Text text, boolean isTabList) {

}
}
/*


// replace profile line and arrow colors
for (String key : DefaultConfig.normalList) {

ChatTag normal = DefaultConfig.newChatTags.get(key);
ChatTag custom = c.chatTags.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();
}

text = replaceTextInternal(text, getProfileLine(normal.TextColor,false), getProfileLine(custom.TextColor,false), false);
text = replaceTextInternal(text, getProfileLine(normal.TextColor, true), getProfileLine(custom.TextColor,true), false);
// replace
text = replaceTextInternal(text, getProfileLine(normal.TextColor,false), getProfileLine(color,false), false);
text = replaceTextInternal(text, getProfileLine(normal.TextColor, true), getProfileLine(color,true), false);

text = replaceTextInternal(text, getProfileArrow(normal.TextColor), getProfileArrow(custom.TextColor), false);
text = replaceTextInternal(text, getProfileArrow(normal.TextColor), getProfileArrow(color), false);

}

// vipenabled / disabled logic
ChatTag custom_vip = c.chatTags.get("vip");
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();
}
if (!c.VipEnabled) {
text = replaceTextInternal(text, VIP_PREFIX, Text.empty(), true);
text = replaceTextInternal(text, VIP_WHOIS, Text.empty(), false);
text = replaceTextInternal(text, FOUNDING_BADGE, Text.empty(), false);
} else {
text = replaceTextInternal(text, VIP_PREFIX, Text.empty()
.append(Text.literal("[").withColor(custom_vip.BracketColor))
.append(Text.literal(custom_vip.Symbol).withColor(custom_vip.SymbolColor))
.append(Text.literal("]").withColor(custom_vip.BracketColor)),
false);
text = replaceTextInternal(text, VIP_WHOIS, Text.empty()
.append(Text.literal("[").withColor(custom_vip.BracketColor))
.append(Text.literal(custom_vip.TextContent).withColor(custom_vip.TextColor))
.append(Text.literal("]").withColor(custom_vip.BracketColor)),
true);
text = replaceTextInternal(text, FOUNDING_BADGE, Text.literal(custom_vip.Symbol+" ")
.styled(style -> style.withColor(custom_vip.SymbolColor)
text = replaceTextInternal(text, VIP_PREFIX, custom_vip.getAsFormatted(), false);
text = replaceTextInternal(text, VIP_WHOIS, custom_vip.getAsShortFormatted(), true);

text = replaceTextInternal(text, FOUNDING_BADGE, Text.literal("⭐ ")
.styled(style -> style.withColor(color)
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
Text.literal("Founding VIP")
.withColor(custom_vip.SymbolColor))))
.withColor(color))))
, false);


}

*/

return text;
}

Expand Down
26 changes: 22 additions & 4 deletions src/main/java/dev/fire/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import com.google.gson.*;
import dev.fire.DFrevert;
import dev.fire.FileManager;
import dev.fire.utils.ChatTag;
import dev.fire.utils.DfrevertException;
import dev.fire.utils.MiniMessageChatTag;
import dev.isxander.yacl3.api.*;
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;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class Config {
private static Config instance;
Expand All @@ -32,7 +35,22 @@ public static Map<String, MiniMessageChatTag> convertToMinimessage(Map<String, C
for (Map.Entry<String, ChatTag> entry : map.entrySet()) {
String key = entry.getKey();
ChatTag value = entry.getValue();
new_map.put(key, value.toMiniMessageClass());

MiniMessageChatTag mmobj = value.toMiniMessageClass();
if (Objects.equals(key, "vip")) {
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.shortvalue =
ChatTag.convertStringWithColorToMiniMessage("[", bracketColor) +
ChatTag.convertStringWithColorToMiniMessage("VIP", symbolColor) +
ChatTag.convertStringWithColorToMiniMessage("]", bracketColor);
}
new_map.put(key, mmobj);
}
return new_map;
}
Expand Down Expand Up @@ -181,8 +199,8 @@ private OptionGroup groupBuilder(String key, String name) {
.build())
.binding(
DefaultConfig.oldChatTags.get(key).toShortValue(),
() -> chatTags.get(key).shortValue,
opt -> chatTags.get(key).shortValue = opt
() -> chatTags.get(key).shortvalue,
opt -> chatTags.get(key).shortvalue = opt
)
.controller(StringControllerBuilder::create)
.build())
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/fire/config/DefaultConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.fire.config;

import net.minecraft.text.Text;
import dev.fire.utils.ChatTag;

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package dev.fire.config;
package dev.fire.utils;

import com.google.gson.JsonObject;
import net.minecraft.network.message.SentMessage;
import net.minecraft.text.Text;

import java.awt.*;
import java.io.Serializable;
import java.util.Map;

public class ChatTag implements Serializable {
public int BracketColor;
Expand Down Expand Up @@ -69,19 +66,16 @@ public String toShortValue() {
}

public MiniMessageChatTag toMiniMessageClass() {
String minimessage = "";

return new MiniMessageChatTag(this);
}

private String convertStringWithColorToMiniMessage(String string, int color){
public static String convertStringWithColorToMiniMessage(String string, int color){
Color c = new Color(color);
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
String hex = String.format("#%02x%02x%02x", r, g, b);
String minimessage = "<" + hex + ">" + string + "</" + hex + ">";
return minimessage;
return "<" + hex + ">" + string + "</" + hex + ">";
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.fire.config;
package dev.fire.utils;

public class DfrevertException extends Exception {
public DfrevertException(String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package dev.fire.config;
package dev.fire.utils;

import dev.fire.DFrevert;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.minecraft.text.*;

import java.awt.*;
import java.util.ArrayList;

public class MiniMessage {
public static Text format(String input, boolean keep_minimessage_tags) {
Expand Down Expand Up @@ -135,7 +131,7 @@ public static Text format(String input, boolean keep_minimessage_tags) {
public static int parseIntFromHex(String hexString) {
return Integer.parseInt(hexString, 16);
}
public String parseHexFromInt(String string, int color){
public static String parseHexFromInt(String string, int color){
Color c = new Color(color);
int r = c.getRed();
int g = c.getGreen();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.fire.config;
package dev.fire.utils;

import com.google.gson.JsonObject;
import net.minecraft.text.*;
Expand All @@ -7,34 +7,37 @@ public class MiniMessageChatTag {
public String mainvalue;
public String leftvalue;
public String rightvalue;
public String shortValue;
public String shortvalue;

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

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

public Text getAsFormatted() {
return MiniMessage.format(leftvalue +mainvalue+ rightvalue, false);
}
public Text getAsFormatted(String input) {
return MiniMessage.format(input, false);
}
public Text getAsShortFormatted() {
return MiniMessage.format(shortValue, false);
return MiniMessage.format(shortvalue, false);
}
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("shortvalue", shortvalue);
return object.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.fire.config;
package dev.fire.utils;

import java.util.ArrayList;

Expand Down

0 comments on commit c34ed11

Please sign in to comment.