// This class was created by JaTiTV.
package net.t2code.t2codelib.util;
import lombok.Getter;
import net.kyori.adventure.text.minimessage.MiniMessage;
public class T2C_GenerateFrame {
@Getter
private static final String BOTTOM_BORDER = "╚═══════════════════════════════════════════════════════════════════════════╝";
@Getter
private static final String STROKE = "╠═══════════════════════════════════════════════════════════════════════════╣";
private static final int FIXED_WIDTH = BOTTOM_BORDER.length() - 2; // Länge ohne die Randzeichen
@Getter
private static final String COLOR_CODE = "§e";
private static final String BORDER_CHAR = "═";
private static final String TOP_LEFT = "╔";
private static final String TOP_RIGHT = "╗";
private static final String BOTTOM_LEFT = "╚";
private static final String BOTTOM_RIGHT = "╝";
private static final String SIDE_BORDER = "║";
public static String setCenterAligned(String prefix, String text) {
String colorCode = COLOR_CODE;
if (T2C_PlatformDetector.detectPlatform == T2C_PlatformDetector.PlatformType.VELOCITY) {
colorCode = "";
}
// Entfernen von Farbcodes aus der Berechnungslänge
String textWithoutColor = removeColorCodes(text);
int textLengthWithoutColor = textWithoutColor.length();
int totalPaddingSize = FIXED_WIDTH - textLengthWithoutColor;
// Sicherstellen, dass das Padding nicht negativ wird
if (totalPaddingSize < 0) totalPaddingSize = 0;
// Berechnung des Abstands vor und nach dem Text
int paddingLeft = totalPaddingSize / 2;
int paddingRight = totalPaddingSize - paddingLeft;
// Formatierung der Zeile: Text zentrieren
String formattedValue = colorCode + "║" + " ".repeat(paddingLeft) + text + " ".repeat(paddingRight) + colorCode + "║";
//T2Csend.console(prefix + " " + formattedValue);
if (T2C_PlatformDetector.detectPlatform == T2C_PlatformDetector.PlatformType.VELOCITY) {
return removeColorCodes(formattedValue);
} else return prefix + " " + formattedValue;
}
public static String setLeftAligned(String prefix, String text) {
String colorCode = COLOR_CODE;
if (T2C_PlatformDetector.detectPlatform == T2C_PlatformDetector.PlatformType.VELOCITY) {
colorCode = "";
}
// Entfernen von Farbcodes aus der Berechnungslänge
String textWithoutColor = removeColorCodes(text);
int textLengthWithoutColor = textWithoutColor.length();
int totalPaddingSize = FIXED_WIDTH - textLengthWithoutColor;
// Sicherstellen, dass das Padding nicht negativ wird
if (totalPaddingSize < 0) totalPaddingSize = 0;
// Berechnung des Abstands nach dem Text und vor dem Rand
int paddingRight = totalPaddingSize; // Alles Padding geht nach rechts
// Formatierung der Zeile: Text am Anfang und dynamischer Abstand zum Ende
String formattedValue = colorCode + "║ " + text + " ".repeat((paddingRight - 1)) + colorCode + "║";
if (T2C_PlatformDetector.detectPlatform == T2C_PlatformDetector.PlatformType.VELOCITY) {
return removeColorCodes(formattedValue);
} else return prefix + " " + formattedValue;
}
// Methode für mehrere Zeilen Text mit dynamischem Rahmen
public static String getFrameLeft(String prefix, boolean console, String... lines) {
// Entfernen von Farbcodes und Berechnung der maximalen Länge
String colorCode = COLOR_CODE;
String nextLine = "
";
if (console && T2C_PlatformDetector.detectPlatform == T2C_PlatformDetector.PlatformType.VELOCITY) {
colorCode = "";
nextLine = "\n";
}
int maxLength = 0;
for (String line : lines) {
String lineWithoutColor = removeColorCodes(line);
maxLength = Math.max(maxLength, lineWithoutColor.length());
}
// Berechnung der Rahmenbreite
int frameWidth = maxLength + 2; // +2 für die Ränder '║'
String topBorder = colorCode + TOP_LEFT + BORDER_CHAR.repeat(frameWidth) + colorCode + TOP_RIGHT;
String bottomBorder = colorCode + BOTTOM_LEFT + BORDER_CHAR.repeat(frameWidth) + colorCode + BOTTOM_RIGHT;
// Gehe durch jede Zeile und formatiere sie
StringBuilder builder = new StringBuilder();
// Ausgabe der oberen Linie
if (console) builder.append(nextLine);
builder.append(prefix).append(" ").append(topBorder).append(nextLine);
for (String line : lines) {
// Entfernen von Farbcodes aus der Berechnungslänge
String lineWithoutColor = removeColorCodes(line);
int lineLengthWithoutColor = lineWithoutColor.length();
int totalPaddingSize = frameWidth - lineLengthWithoutColor; // -2 für die Ränder '║'
// Sicherstellen, dass das Padding nicht negativ wird
if (totalPaddingSize < 0) totalPaddingSize = 0;
// Berechnung des Abstands nach dem Text und vor dem Rand
int paddingLeft = 0; // Kein zusätzlicher Abstand vor dem Text
int paddingRight = totalPaddingSize; // Alles Padding geht nach rechts
// Formatierung der Zeile: Text am Anfang und dynamischer Abstand zum Ende
String formattedValue = colorCode + SIDE_BORDER + line + " ".repeat(paddingRight) + colorCode + SIDE_BORDER;
builder.append(prefix).append(" ").append(formattedValue).append(nextLine);
}
// Ausgabe der unteren Linie
builder.append(prefix).append(" ").append(bottomBorder);
// T2Csend.console(builder.toString());
if (console && T2C_PlatformDetector.detectPlatform == T2C_PlatformDetector.PlatformType.VELOCITY) {
return removeColorCodes(builder.toString());
} else return builder.toString();
}
public static String getFrameCenter(String prefix, boolean console, String... lines) {
String colorCode = COLOR_CODE;
String nextLine = "
";
if (console && T2C_PlatformDetector.detectPlatform == T2C_PlatformDetector.PlatformType.VELOCITY) {
colorCode = "";
nextLine = "\n";
}
// Entfernen von Farbcodes und Berechnung der maximalen Länge
int maxLength = 0;
for (String line : lines) {
String lineWithoutColor = removeColorCodes(line);
maxLength = Math.max(maxLength, lineWithoutColor.length());
}
// Berechnung der Rahmenbreite
int frameWidth = maxLength + 2; // +2 für die Ränder '║'
String topBorder = colorCode + TOP_LEFT + BORDER_CHAR.repeat(frameWidth) + colorCode + TOP_RIGHT;
String bottomBorder = colorCode + BOTTOM_LEFT + BORDER_CHAR.repeat(frameWidth) + colorCode + BOTTOM_RIGHT;
// Gehe durch jede Zeile und formatiere sie
StringBuilder builder = new StringBuilder();
// Ausgabe der oberen Linie
if (console) builder.append(nextLine);
builder.append(prefix).append(" ").append(topBorder).append(nextLine);
for (String line : lines) {
// Entfernen von Farbcodes aus der Berechnungslänge
String lineWithoutColor = removeColorCodes(line);
int lineLengthWithoutColor = lineWithoutColor.length();
int totalPaddingSize = frameWidth - lineLengthWithoutColor; // -2 für die Ränder '║'
// Sicherstellen, dass das Padding nicht negativ wird
if (totalPaddingSize < 0) totalPaddingSize = 0;
// Berechnung des Abstands vor und nach dem Text
int paddingLeft = totalPaddingSize / 2;
int paddingRight = totalPaddingSize - paddingLeft;
// Formatierung der Zeile: Text zentrieren
String formattedValue = colorCode + SIDE_BORDER + " ".repeat(paddingLeft) + line + " ".repeat(paddingRight) + colorCode + SIDE_BORDER;
builder.append(prefix).append(" ").append(formattedValue).append(nextLine);
}
// Ausgabe der unteren Linie
builder.append(prefix).append(" ").append(bottomBorder);
// T2Csend.console(builder.toString());
if (console && T2C_PlatformDetector.detectPlatform == T2C_PlatformDetector.PlatformType.VELOCITY) {
return removeColorCodes(builder.toString());
} else return builder.toString();
}
// Methode zum Entfernen von Farbcodes und MiniMessage-Farbcodes aus dem Text, außer
public static String removeColorCodes(String text) {
// Regex für alle Farbcodes und MiniMessage-Codes außer
// String miniMessageRegex = "<(?!br)(color:#([A-Fa-f0-9]{6})|[a-zA-Z_]+)(:[a-zA-Z0-9_]+)?>|[a-zA-Z_]+>";
// return text.replaceAll("§[a-f0-9k-oK-O]", "").replaceAll(miniMessageRegex, "");
String s = MiniMessage.miniMessage().stripTags(text).replaceAll("§[a-f0-9k-oK-O]", "");
return s;
}
}