fix command and refactoring config

This commit is contained in:
loki5512344 2026-03-10 16:58:10 +01:00
parent b922f588d0
commit fe64b3d51f
109 changed files with 4103 additions and 5403 deletions

View file

@ -40,24 +40,24 @@ public final class ChatFormatter {
private static String convertLegacyFormats(String message) {
if (message == null) return "";
// Конвертируем &#RRGGBB в <#RRGGBB>
// Конвертируем &#RRGGBB в <color:#RRGGBB>
java.util.regex.Pattern pattern1 = java.util.regex.Pattern.compile("&#([0-9a-fA-F]{6})");
java.util.regex.Matcher matcher1 = pattern1.matcher(message);
StringBuffer sb1 = new StringBuffer();
while (matcher1.find()) {
String hex = matcher1.group(1).toLowerCase();
matcher1.appendReplacement(sb1, "<#" + hex + ">");
matcher1.appendReplacement(sb1, "<color:#" + hex + ">");
}
matcher1.appendTail(sb1);
message = sb1.toString();
// Конвертируем #RRGGBB в <#RRGGBB> (только если не внутри тегов)
// Конвертируем #RRGGBB в <color:#RRGGBB> (только если не внутри тегов)
java.util.regex.Pattern pattern2 = java.util.regex.Pattern.compile("(?<!<)#([0-9a-fA-F]{6})(?![^<]*>)");
java.util.regex.Matcher matcher2 = pattern2.matcher(message);
StringBuffer sb2 = new StringBuffer();
while (matcher2.find()) {
String hex = matcher2.group(1).toLowerCase();
matcher2.appendReplacement(sb2, "<#" + hex + ">");
matcher2.appendReplacement(sb2, "<color:#" + hex + ">");
}
matcher2.appendTail(sb2);
message = sb2.toString();

View file

@ -17,20 +17,32 @@ public final class PlayerUtil {
/**
* Safely parses a sound name from config.
* Uses deprecated Sound.valueOf() for backward compatibility with string-based config values.
* Uses Registry API for modern sound parsing with fallback to reflection.
*
* @param soundName the sound name to parse
* @param defaultSound the default sound to return if parsing fails
* @return the parsed Sound or the default if invalid
*/
@SuppressWarnings("deprecation")
public static Sound parseSound(String soundName, Sound defaultSound) {
if (soundName == null || soundName.isEmpty()) {
return defaultSound;
}
try {
return Sound.valueOf(soundName.toUpperCase());
} catch (IllegalArgumentException e) {
// Try to get sound by key using Registry (modern way)
Sound sound = org.bukkit.Registry.SOUNDS.match(soundName);
if (sound != null) {
return sound;
}
} catch (Exception e) {
// Registry failed, try fallback
}
// Fallback: try direct field access via reflection
try {
java.lang.reflect.Field field = Sound.class.getField(soundName.toUpperCase().trim());
return (Sound) field.get(null);
} catch (Exception ex) {
return defaultSound;
}
}

View file

@ -6,9 +6,13 @@ public final class TimeFormatter {
}
public static String format(long millis) {
if (millis <= 0) {
if (millis < 0) {
return "0с";
}
if (millis == 0) {
return "навсегда";
}
long seconds = millis / 1000;
long minutes = seconds / 60;
@ -16,18 +20,21 @@ public final class TimeFormatter {
long days = hours / 24;
if (days > 0) {
return days + "д " + (hours % 24) + "ч";
long remainingHours = hours % 24;
return remainingHours > 0 ? days + "д " + remainingHours + "ч" : days + "д";
} else if (hours > 0) {
return hours + "ч " + (minutes % 60) + "м";
long remainingMinutes = minutes % 60;
return remainingMinutes > 0 ? hours + "ч " + remainingMinutes + "м" : hours + "ч";
} else if (minutes > 0) {
return minutes + "м " + (seconds % 60) + "с";
long remainingSeconds = seconds % 60;
return remainingSeconds > 0 ? minutes + "м " + remainingSeconds + "с" : minutes + "м";
} else {
return seconds + "с";
}
}
public static long parse(String timeStr) {
if (timeStr == null || timeStr.isEmpty()) {
if (timeStr == null || timeStr.trim().isEmpty()) {
return 0;
}
@ -38,8 +45,12 @@ public final class TimeFormatter {
if (Character.isDigit(c)) {
number.append(c);
} else if (number.length() > 0) {
long value = Long.parseLong(number.toString());
totalMillis += getMillisForUnit(c, value);
try {
long value = Long.parseLong(number.toString());
totalMillis += getMillisForUnit(c, value);
} catch (NumberFormatException e) {
// Skip invalid numbers
}
number.setLength(0);
}
}