the_big_one/src/main/java/jesse/keeblarcraft/Utils/HelpBuilder.java

115 lines
3.6 KiB
Java
Raw Normal View History

package jesse.keeblarcraft.Utils;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
public class HelpBuilder {
private String COLOR_START = "§";
private String COLOR_END = "§f";
public enum COLOR_CODE {
BLUE,
GRAY,
GOLD,
RED,
GREEN
}
private String getColor(COLOR_CODE code) {
String colorStr = COLOR_START;
switch(code) {
case BLUE:
return colorStr + "9";
case GRAY:
return colorStr + "7";
case GOLD:
return colorStr + "6";
case RED:
return colorStr + "4";
case GREEN:
return colorStr + "2";
}
// If this code is reachable, then someone has not properly handled the above switch-case
return colorStr;
}
public MutableText MakeCopyableTxt(String terminalTxt, String hoverTxt, Integer copyStr) {
return MakeCopyableTxt(terminalTxt, hoverTxt, Integer.toString(copyStr));
}
public MutableText MakeCopyableTxt(String terminalTxt, String hoverTxt, List<String> expandedList) {
String expanded = "[";
int index = 0;
for (String str : expandedList) {
expanded += str;
// Add delimiter if next index is not at size
if (++index < expandedList.size()) {
expanded += ",";
}
}
expanded += "]";
return MakeCopyableTxt(terminalTxt, hoverTxt, expanded);
}
public MutableText MakeCopyableTxt(String terminalTxt, String hoverTxt, String copyStr) {
Text copyableText = Text.of(terminalTxt);
MutableText testTxt = (MutableText) copyableText;
System.out.println("Making hoverable stuff");
testTxt.setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, copyStr))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.of(hoverTxt))));
System.out.println("Done making hoverable stuff");
System.out.println("Value of copyAbleText: " + copyableText.getString());
System.out.println("Value of testTxt: " + testTxt.getString());
return testTxt;
}
public String ColorMsg(Integer msg, COLOR_CODE color) {
return getColor(color) + msg + COLOR_END;
}
public List<String> ColorMsg(List<String> msg, COLOR_CODE color) {
List<String> retList = new ArrayList<String>();
for (String str : msg) {
retList.add(getColor(color) + str + COLOR_END);
}
return retList;
}
public String ColorMsg(String msg, COLOR_CODE color) {
return getColor(color) + msg + COLOR_END;
}
// Parses a help command and color codes it. assume everything up to first '.' is the
// help cmd usage and color it with primaryColor. secondaryColor applied to rest
public String FormatMsg(String helpCmd, COLOR_CODE primaryColor, COLOR_CODE secondaryColor) {
String coloredStr = getColor(primaryColor);
List<String> splitStr = List.of(helpCmd.split("\\."));
Boolean isFirst = true;
for (String str : splitStr) {
if (isFirst) {
coloredStr += str;
isFirst = false;
coloredStr += getColor(secondaryColor);
} else {
coloredStr += str;
}
}
return coloredStr + COLOR_END;
}
}