Update from Git Manager GUI

This commit is contained in:
2026-03-24 08:54:30 +01:00
parent 6edf8f9157
commit e4b2ac32ca
18 changed files with 2748 additions and 265 deletions

View File

@@ -4,29 +4,61 @@ import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Utils {
// Matches &#RRGGBB hex color codes
private static final Pattern HEX_PATTERN = Pattern.compile("&#([A-Fa-f0-9]{6})");
public static String formatIsoNow() {
return DateTimeFormatter.ISO_INSTANT
.withZone(ZoneId.systemDefault())
.format(Instant.now());
}
/**
* Formats an ISO timestamp into dd/MM/yyyy format.
*/
public static String prettifyIso(String iso) {
if (iso == null || iso.isEmpty()) return "";
Instant inst = Instant.parse(iso);
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
.withLocale(Locale.getDefault())
.withZone(ZoneId.systemDefault());
return fmt.format(inst);
try {
Instant inst = Instant.parse(iso);
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd/MM/yyyy")
.withLocale(Locale.getDefault())
.withZone(ZoneId.systemDefault());
return fmt.format(inst);
} catch (Exception e) {
return iso; // return as-is if parsing fails
}
}
/**
* Translates & color codes and &#RRGGBB hex codes into Minecraft format codes.
* Hex usage in config: &#FF5500 → §x§F§F§5§5§0§0
*/
public static String color(String s) {
return s == null ? "" : s.replace("&", "§");
if (s == null) return "";
// Process hex colors first: &#RRGGBB → §x§R§R§G§G§B§B
Matcher m = HEX_PATTERN.matcher(s);
StringBuffer sb = new StringBuffer();
while (m.find()) {
StringBuilder repl = new StringBuilder("§x");
for (char c : m.group(1).toCharArray()) {
repl.append('§').append(c);
}
m.appendReplacement(sb, repl.toString());
}
m.appendTail(sb);
// Then translate remaining & codes
return sb.toString().replace("&", "§");
}
// Ersetze Platzhalter %player% %rank% %joindate%
/**
* Replaces placeholder pairs in a template string.
* e.g. replace(template, "%player%", "Steve", "%rank%", "Admin")
*/
public static String replace(String template, String... pairs) {
if (template == null) return "";
String out = template;
@@ -35,4 +67,4 @@ public class Utils {
}
return out;
}
}
}