mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 00:21:26 +01:00
Fix/mojang utils long name (#1792)
This commit is contained in:
parent
7b0b314707
commit
067227421f
@ -41,10 +41,15 @@ public final class MojangUtils {
|
|||||||
final String response = URLUtils.getText(url);
|
final String response = URLUtils.getText(url);
|
||||||
// If our response is "", that means the url did not get a proper object from the url
|
// If our response is "", that means the url did not get a proper object from the url
|
||||||
// So the username or UUID was invalid, and therefore we return null
|
// So the username or UUID was invalid, and therefore we return null
|
||||||
if(response.isEmpty()) {
|
if (response.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return JsonParser.parseString(response).getAsJsonObject();
|
|
||||||
|
JsonObject jsonObject = JsonParser.parseString(response).getAsJsonObject();
|
||||||
|
if (jsonObject.has("errorMessage")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return jsonObject;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
MinecraftServer.getExceptionManager().handleException(e);
|
MinecraftServer.getExceptionManager().handleException(e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -18,4 +18,24 @@ public class TestMojangUtils {
|
|||||||
var result = MojangUtils.fromUsername("jfdsa84vvcxadubasdfcvn"); // Longer than 16, always invalid
|
var result = MojangUtils.fromUsername("jfdsa84vvcxadubasdfcvn"); // Longer than 16, always invalid
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidUuidWorks() {
|
||||||
|
var result = MojangUtils.fromUuid("853c80ef3c3749fdaa49938b674adae6");
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals("jeb_", result.get("name").getAsString());
|
||||||
|
assertEquals("853c80ef3c3749fdaa49938b674adae6", result.get("id").getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidUuidReturnsNull() {
|
||||||
|
var result = MojangUtils.fromUuid("853c80ef3c3749fdaa49938b674adae6a"); // Longer than 32, always invalid
|
||||||
|
assertNull(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonExistentUuidReturnsNull() {
|
||||||
|
var result = MojangUtils.fromUuid("00000000-0000-0000-0000-000000000000");
|
||||||
|
assertNull(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user