Skip to content

Commit

Permalink
Small bugfixes for skins handling
Browse files Browse the repository at this point in the history
  • Loading branch information
libraryaddict committed Feb 10, 2025
1 parent 3569487 commit 9ffb668
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.SkinUtils;
import me.libraryaddict.disguise.utilities.mineskin.models.structures.SkinVariant;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
Expand Down Expand Up @@ -48,7 +49,7 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
}

String[] args = DisguiseUtilities.split(StringUtils.join(strings, " "));
String tName = args.length > 1 ? args[0] : null;
String tempName = args.length > 1 ? args[0] : null;
String skin = args.length > 1 ? args[1] : args[0];

String usable = SkinUtils.getUsableStatus();
Expand All @@ -58,23 +59,32 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
return true;
}

if (tName == null && skin.matches("(.*\\/)?[a-zA-Z0-9_-]{3,20}(\\.png)?")) {
if (tempName == null && skin.matches("(.*/)?[a-zA-Z0-9_-]{3,20}(\\.png)?")) {
int start = skin.lastIndexOf("/") + 1;
int end = skin.length();

if (skin.lastIndexOf(".", start) > start) {
if (skin.indexOf(".", start) > start) {
end = skin.lastIndexOf(".", start);
}

tName = skin.substring(start, end);
tempName = skin.substring(start, end);

if (DisguiseUtilities.hasUserProfile(tName)) {
tName = null;
if (DisguiseUtilities.hasUserProfile(tempName)) {
tempName = null;
}
}

String name =
tName != null && tName.toLowerCase(Locale.ENGLISH).endsWith(":slim") ? tName.substring(0, tName.lastIndexOf(":")) : tName;
// Remove skin:slim :unknown :classic, etc
for (SkinVariant variant : SkinVariant.values()) {
if (tempName == null || tempName.toLowerCase(Locale.ENGLISH).endsWith(":" + variant.name().toLowerCase(Locale.ENGLISH))) {
continue;
}

tempName = tempName.substring(0, tempName.length() - (variant.name().length() + 1));
break;
}

String name = tempName;

if (name != null && name.replaceAll("[_a-zA-Z \\d-@#]", "").length() > 0) {
LibsMsg.SKIN_API_INVALID_NAME.send(sender);
Expand Down Expand Up @@ -108,7 +118,7 @@ public void onSuccess(UserProfile profile) {

String nName = name;

if (nName == null) {
if (StringUtils.isEmpty(nName)) {
int i = 1;

while (DisguiseUtilities.hasUserProfile("skin" + i)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,10 @@ public static void saveSanitySkinCache() {

public static void addUserProfile(String string, UserProfile userProfile) {
try {
if (StringUtils.isEmpty(string)) {
throw new IllegalArgumentException("Provided string is empty");
}

if (userProfile == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static void grabSkin(CommandSender sender, String param, SkinCallback cal
continue;
}

param = param.substring(0, param.length() - variant.name().length() + 1);
param = param.substring(0, param.length() - (variant.name().length() + 1));
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ private void addConnectionHeaders(HttpURLConnection connection) throws IOExcepti
connection.setDoOutput(true);

connection.setRequestProperty("User-Agent", this.userAgent);
connection.setRequestProperty("Accept", "application/json");

String key = getApiKey();

Expand Down

0 comments on commit 9ffb668

Please # to comment.