mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-19 05:41:21 +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
|
@Blocking
|
||||||
public static @Nullable PlayerSkin fromUuid(@NotNull String uuid) {
|
public static @Nullable PlayerSkin fromUuid(@NotNull String uuid) {
|
||||||
final JsonObject jsonObject = MojangUtils.fromUuid(uuid);
|
final JsonObject jsonObject = MojangUtils.fromUuid(uuid);
|
||||||
|
if (jsonObject == null) return null;
|
||||||
final JsonArray propertiesArray = jsonObject.get("properties").getAsJsonArray();
|
final JsonArray propertiesArray = jsonObject.get("properties").getAsJsonArray();
|
||||||
for (JsonElement jsonElement : propertiesArray) {
|
for (JsonElement jsonElement : propertiesArray) {
|
||||||
final JsonObject propertyObject = jsonElement.getAsJsonObject();
|
final JsonObject propertyObject = jsonElement.getAsJsonObject();
|
||||||
@ -46,6 +47,7 @@ public record PlayerSkin(String textures, String signature) {
|
|||||||
@Blocking
|
@Blocking
|
||||||
public static @Nullable PlayerSkin fromUsername(@NotNull String username) {
|
public static @Nullable PlayerSkin fromUsername(@NotNull String username) {
|
||||||
final JsonObject jsonObject = MojangUtils.fromUsername(username);
|
final JsonObject jsonObject = MojangUtils.fromUsername(username);
|
||||||
|
if (jsonObject == null) return null;
|
||||||
final String uuid = jsonObject.get("id").getAsString();
|
final String uuid = jsonObject.get("id").getAsString();
|
||||||
// Retrieve the skin data from the mojang uuid
|
// Retrieve the skin data from the mojang uuid
|
||||||
return fromUuid(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
|
@Test
|
||||||
public void testInvalidNameReturnsNull() {
|
public void testInvalidNameReturnsNull() {
|
||||||
var result = MojangUtils.fromUsername("jfdsa84vvcxadubasdfcvn"); // Longer than 16, always invalid
|
var result = MojangUtils.fromUsername("jfdsa84vvcxadubasdfcvn"); // Longer than 16, always invalid
|
||||||
assert result == null;
|
assertNull(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user