#Is there a non-depreciated way to get an OfflinePlayer by name?
1 messages ยท Page 1 of 1 (latest)
command geek hi lmao
Yep, I'm not depending on this for storage or anything... it's more for command arguments (for example to ban an offline player)
idk u could do smth that stores the name and when he tries to join he cant?
ban by name sounds like a pretty not good idea
if its a premium server there is no problem
why?
I can just rename
oh yeah
It's probably just for the command and then internally it uses the UUID is my guess
I just want to be able to grab an offline player by name (through command arguments) and from there I store the uuid to be banned, not the name
the name is never stored
Just throw the name at the mojang API
I'm just using it to get the player
and grab the profile from there
will look into this, thanks!
Does getOfflinePlayer(String) get it from Mojangs API?
According to the docs it says it can make a web request
but also uses local server cache which is the issue
Yeah true
Using the Mojang API worked! However it has 100-200 milliseconds of delay... is this normal and is there anyway to get around this?
well you are doing a network request
Not sure what that is ๐
A network request ?
you are asking a mojang server
your data has to travel the internet
that takes a bit
Pretty much yes
I would suggest checking if a player with the name is currently online first
e.g. most bans might just be while the target is online
that way you can skip the networking
Yeah ofc, will implement that right away. Should I be worried about lag on the server due to the delay caused by the request?
You want to move that request off the main thread
Cool will do that ๐
btw what lib are you using ? or are you doing a plain http request
I haven't played with spigot API much
so maybe you are using an API I just don't know about yet
here's my code:
public static OfflineUser getOfflineUser(String name) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new URL("https://api.mojang.com/users/profiles/minecraft/" + name).openStream()));
String value = (((JsonObject) JsonParser.parseReader(reader)).get("id")).toString().replaceAll("\"", "");
reader.close();
return getOfflineUser(UUID.fromString(value.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5")));
} catch (Exception e) {
return null;
}
}```