9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00

Fix configurable username regex usage

This commit is contained in:
HaHaWTH
2025-12-19 20:55:11 +08:00
parent 6129df4281
commit 4158435185
2 changed files with 15 additions and 5 deletions

View File

@@ -89,27 +89,26 @@ index 6396083993d248683b887774d2db3f3f03825033..fbf4e548f4377c7155a3a02c3b679a03
this.server.getCustomBossEvents().onPlayerDisconnect(player);
UUID uuid = player.getUUID();
diff --git a/net/minecraft/util/StringUtil.java b/net/minecraft/util/StringUtil.java
index c3a99fe7b49858bc0ca9a7f800b0db40465f6901..2f8a5d0b94b548dfc62f2c40bf10218d34c17574 100644
index c3a99fe7b49858bc0ca9a7f800b0db40465f6901..316c16b2dbf5f9dda2b1be29fbdd4caa6528fb63 100644
--- a/net/minecraft/util/StringUtil.java
+++ b/net/minecraft/util/StringUtil.java
@@ -64,6 +64,16 @@ public class StringUtil {
@@ -64,6 +64,15 @@ public class StringUtil {
}
public static boolean isValidPlayerName(String playerName) {
+ // Leaf start - Remove vanilla username check
+ return isValidPlayerName(playerName, org.dreeam.leaf.config.modules.misc.VanillaUsernameCheck.removeAllCheck);
+ return isValidPlayerName(playerName, org.dreeam.leaf.config.modules.misc.VanillaUsernameCheck.removeAllCheck || org.dreeam.leaf.config.modules.misc.VanillaUsernameCheck.useUsernameRegex);
+ }
+ public static boolean isValidPlayerNameVanilla(String playerName) {
+ return playerName.length() <= 16 && playerName.chars().filter(i -> i <= 32 || i >= 127).findAny().isEmpty();
+ }
+ public static boolean isValidPlayerName(String playerName, boolean bypassCheck) {
+ if (bypassCheck) return playerName.length() <= 16;
+ if (true) return isReasonablePlayerName(playerName); // Leaf - Fix Purpur username validation config
+ // Leaf end - Remove vanilla username check
return playerName.length() <= 16 && playerName.chars().filter(i -> i <= 32 || i >= 127).findAny().isEmpty();
}
@@ -87,7 +97,12 @@ public class StringUtil {
@@ -87,7 +96,12 @@ public class StringUtil {
// Paper start - Username validation
public static boolean isReasonablePlayerName(final String name) {

View File

@@ -13,6 +13,7 @@ public class VanillaUsernameCheck extends ConfigModules {
@Experimental
public static boolean removeAllCheck = false;
public static boolean enforceSkullValidation = true;
public static boolean useUsernameRegex = false;
@Experimental
public static boolean allowOldPlayersJoin = false;
@@ -32,6 +33,16 @@ public class VanillaUsernameCheck extends ConfigModules {
"""
强制启用头颅验证,
避免所有者带有特殊字符的头颅导致客户端掉线."""));
useUsernameRegex = config.getBoolean(getBasePath() + ".use-username-regex", useUsernameRegex, config.pickStringRegionBased("""
Use username regex,
enforcing players to use only allowed characters in their usernames.
This will also prevent players from using special characters in their usernames.
You should configure this in purpur.yml after enabling.""",
"""
使用用户名正则,
要求玩家只能使用允许的字符作为用户名.
这将还防止玩家使用潜在的风险字符作为用户名.
开启后需要在 purpur.yml 中进行配置."""));
allowOldPlayersJoin = config.getBoolean(getBasePath() + ".allow-old-players-join", allowOldPlayersJoin, config.pickStringRegionBased("""
Allow old players to join the server after the username regex is changed,
even if their names don't meet the new requirements.""",