mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-14 19:32:17 +01:00
Fix invalid username/uuid in static PlayerSkin methods
This commit is contained in:
parent
7d752bce88
commit
be100fa5b8
@ -25,6 +25,7 @@ public record PlayerSkin(String textures, String signature) {
|
||||
@Blocking
|
||||
public static @Nullable PlayerSkin fromUuid(@NotNull String uuid) {
|
||||
final JsonObject jsonObject = MojangUtils.fromUuid(uuid);
|
||||
if (jsonObject == null) return null;
|
||||
final JsonArray propertiesArray = jsonObject.get("properties").getAsJsonArray();
|
||||
for (JsonElement jsonElement : propertiesArray) {
|
||||
final JsonObject propertyObject = jsonElement.getAsJsonObject();
|
||||
@ -46,6 +47,7 @@ public record PlayerSkin(String textures, String signature) {
|
||||
@Blocking
|
||||
public static @Nullable PlayerSkin fromUsername(@NotNull String username) {
|
||||
final JsonObject jsonObject = MojangUtils.fromUsername(username);
|
||||
if (jsonObject == null) return null;
|
||||
final String uuid = jsonObject.get("id").getAsString();
|
||||
// Retrieve the skin data from the mojang uuid
|
||||
return fromUuid(uuid);
|
||||
|
21
src/test/java/net/minestom/server/entity/PlayerSkinTest.java
Normal file
21
src/test/java/net/minestom/server/entity/PlayerSkinTest.java
Normal file
@ -0,0 +1,21 @@
|
||||
package net.minestom.server.entity;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class PlayerSkinTest {
|
||||
|
||||
@Test
|
||||
public void validName() {
|
||||
var skin = PlayerSkin.fromUsername("jeb_");
|
||||
assertNotNull(skin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidName() {
|
||||
var skin = PlayerSkin.fromUsername("jfdsa84vvcxadubasdfcvn");
|
||||
assertNull(skin);
|
||||
}
|
||||
}
|
@ -16,6 +16,6 @@ public class TestMojangUtils {
|
||||
@Test
|
||||
public void testInvalidNameReturnsNull() {
|
||||
var result = MojangUtils.fromUsername("jfdsa84vvcxadubasdfcvn"); // Longer than 16, always invalid
|
||||
assert result == null;
|
||||
assertNull(result);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user