PaperMC/paper-server/patches/sources/net/minecraft/util/StringUtil.java.patch
Nassim Jahnke c3d5f253fe
Moar
2024-12-13 20:30:07 +01:00

28 lines
890 B
Diff

--- a/net/minecraft/util/StringUtil.java
+++ b/net/minecraft/util/StringUtil.java
@@ -85,6 +_,25 @@
return stringBuilder.toString();
}
+ // Paper start - Username validation
+ public static boolean isReasonablePlayerName(final String name) {
+ if (name.isEmpty() || name.length() > 16) {
+ return false;
+ }
+
+ for (int i = 0, len = name.length(); i < len; ++i) {
+ final char c = name.charAt(i);
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_' || c == '.')) {
+ continue;
+ }
+
+ return false;
+ }
+
+ return true;
+ }
+ // Paper end - Username validation
+
public static boolean isWhitespace(int character) {
return Character.isWhitespace(character) || Character.isSpaceChar(character);
}