9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-06 15:51:31 +00:00
Files
Leaf/leaf-server/paper-patches/features/0061-Configurable-vanilla-username-check.patch
Creeam 8fda84ea96 Fix configurable username check bugs (#572)
* Fix configurable username check bugs

* Format

* cleanup config load logic
2025-12-30 08:41:38 -05:00

79 lines
3.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Wed, 12 Oct 2022 14:36:58 -0400
Subject: [PATCH] Configurable vanilla username check
diff --git a/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java
index db43329d57144471d0c9ce0eed92d2f1bd05f120..d65bde85ecae29104c5c34380f164252df9e4515 100644
--- a/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java
+++ b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java
@@ -62,6 +62,14 @@ public class CraftPlayerProfile implements PlayerProfile, SharedPlayerProfile {
copyProfileProperties(resolvableProfile.gameProfile(), 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.getProperties().containsKey(property);
@@ -195,6 +203,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(), true);
+ clone.setProperties(getProperties());
+ return clone;
+ }
+ // Leaf end - Configurable vanilla username check
+
@Override
public boolean isComplete() {
return this.getId() != null && StringUtils.isNotBlank(this.getName());
@@ -369,15 +385,21 @@ 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 : ""
);
}
+ 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());
}
@@ -401,6 +423,13 @@ public class CraftPlayerProfile implements PlayerProfile, SharedPlayerProfile {
return asAuthlib(craft.clone());
}
+ // Leaf start - Configurable vanilla username check
+ public static GameProfile asAuthlibCopyCustomValidation(PlayerProfile profile) {
+ CraftPlayerProfile craft = ((CraftPlayerProfile) profile);
+ return asAuthlib(craft.cloneCustom());
+ }
+ // Leaf end - Configurable vanilla username check
+
public static GameProfile asAuthlib(PlayerProfile profile) {
CraftPlayerProfile craft = ((CraftPlayerProfile) profile);
return craft.getGameProfile();