From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MrHua269 Date: Sat, 27 Jun 2026 17:39:33 +0800 Subject: [PATCH] Leaf Configurable vanilla username check A part of Leaf(https://github.com/Winds-Studio/Leaf/blob/edb0504069139beaa6f39efa4702370c2576b3fc/leaf-server/paper-patches/features/0061-Configurable-vanilla-username-check.patch) License: https://github.com/Winds-Studio/Leaf/blob/edb0504069139beaa6f39efa4702370c2576b3fc/LICENSE.md diff --git a/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java index ceaf63c76272b2a11b92f877b9828e93ec79d47f..ff9a452d1be441b8199509be9799135923c14446 100644 --- a/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java +++ b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java @@ -67,6 +67,14 @@ public class CraftPlayerProfile implements PlayerProfile, SharedPlayerProfile { copyProfileProperties(resolvableProfile.partialProfile(), this.profile); } + // Leaf start - Configurable vanilla username check + public CraftPlayerProfile(UUID id, String name, boolean useCustomValidation) { + this.profile = createAuthLibProfile(id, name, useCustomValidation); + this.emptyName = name == null; + this.emptyUUID = id == null; + } + // Leaf end - Configurable vanilla username check + @Override public boolean hasProperty(String property) { return profile.properties().containsKey(property); @@ -205,6 +213,14 @@ public class CraftPlayerProfile implements PlayerProfile, SharedPlayerProfile { return clone; } + // Leaf start - Configurable vanilla username check + public CraftPlayerProfile cloneCustom() { + CraftPlayerProfile clone = new CraftPlayerProfile(this.getId(), this.getName(), io.nanachiyo0721.shiroha.config.modules.misc.UsernameCheckConfig.useCustomUsernameRegex()); + clone.setProperties(getProperties()); + return clone; + } + // Leaf end - Configurable vanilla username check + @Override public boolean isComplete() { return this.getId() != null && StringUtils.isNotBlank(this.getName()); @@ -324,9 +340,10 @@ public class CraftPlayerProfile implements PlayerProfile, SharedPlayerProfile { } } - private static GameProfile createAuthLibProfile(UUID uniqueId, String name) { + // Leaf start - Configurable vanilla username check + private static GameProfile createAuthLibProfile(UUID uniqueId, String name, boolean useCustomValidation) { Preconditions.checkArgument(name == null || name.length() <= 16, "Name cannot be longer than 16 characters"); - Preconditions.checkArgument(name == null || StringUtil.isValidPlayerName(name), "The name of the profile contains invalid characters: %s", name); + Preconditions.checkArgument(name == null || (useCustomValidation ? StringUtil.isReasonablePlayerName(name) : StringUtil.isValidPlayerName(name)), "The name of the profile contains invalid characters: %s", name); return new GameProfile( uniqueId != null ? uniqueId : Util.NIL_UUID, name != null ? name : "", @@ -334,6 +351,11 @@ public class CraftPlayerProfile implements PlayerProfile, SharedPlayerProfile { ); } + private static GameProfile createAuthLibProfile(UUID uniqueId, String name) { + return createAuthLibProfile(uniqueId, name, false); + } + // Leaf end - Configurable vanilla username check + private static ProfileProperty toBukkit(Property property) { return new ProfileProperty(property.name(), property.value(), property.signature()); } @@ -346,6 +368,13 @@ public class CraftPlayerProfile implements PlayerProfile, SharedPlayerProfile { return new Property(property.getName(), property.getValue(), property.getSignature()); } + // Leaf start - Configurable vanilla username check + public static GameProfile asAuthlibCopyCustomValidation(PlayerProfile profile) { + CraftPlayerProfile craft = ((CraftPlayerProfile) profile); + return asAuthlibCopy(craft.cloneCustom()); + } + // Leaf end - Configurable vanilla username check + public static GameProfile asAuthlibCopy(PlayerProfile profile) { CraftPlayerProfile craft = ((CraftPlayerProfile) profile); return craft.getGameProfile();