Skip to content
Permalink
Browse files
Fix puuid() returning invalid UUID for invalid name.
Optimize get_offline_players().
  • Loading branch information
PseudoKnight committed Apr 13, 2020
1 parent c86736d commit dd8b5258bbdb808e8b7ffec68e6550233345307f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
@@ -172,7 +172,6 @@ public MCPluginManager getPluginManager() {
}

@Override
@SuppressWarnings("deprecation")
public MCPlayer getPlayerExact(String name) {
Player p = s.getPlayerExact(name);
if(p == null) {
@@ -182,7 +181,6 @@ public MCPlayer getPlayerExact(String name) {
}

@Override
@SuppressWarnings("deprecation")
public MCPlayer getPlayer(String name) {
Player p = s.getPlayer(name);
if(p == null) {
@@ -319,7 +317,13 @@ public MCCommandMap getCommandMap() {

@Override
public MCOfflinePlayer getOfflinePlayer(String player) {
return new BukkitMCOfflinePlayer(s.getOfflinePlayer(player));
OfflinePlayer ofp = s.getOfflinePlayer(player);
if(ofp.getUniqueId().version() != 4) {
// Not an actual MC profile UUID.
// This can happen if the server generates a new UUID when it can't find an account by that name.
return null;
}
return new BukkitMCOfflinePlayer(ofp);
}

@Override
@@ -223,7 +223,9 @@ public Integer[] numArgs() {
public String docs() {
return "string {[player], [dashless]} Returns the UUID of the current player or the specified player."
+ " This will attempt to find an offline player, but if that also fails,"
+ " a PlayerOfflineException will be thrown.";
+ " a PlayerOfflineException will be thrown. ---- It is not recommended to give this user input."
+ " If the player is offline and hasn't visited the server recently (so that they're not in the"
+ " user cache), the server may block the main thread with an HTTP request to Mojang's servers.";
}

@Override
@@ -1085,7 +1087,7 @@ public MSVersion since() {

@Override
public Boolean runAsync() {
return true;
return false;
}

@Override
@@ -1762,7 +1764,7 @@ public MSVersion since() {

@Override
public Boolean runAsync() {
return true;
return false;
}

@Override
@@ -4717,9 +4719,12 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
MCServer s = Static.getServer();
CArray ret = new CArray(t);
// This causes the function to return an empty array for a fake/null server.
if(s != null && s.getOfflinePlayers() != null) {
for(MCOfflinePlayer offp : s.getOfflinePlayers()) {
ret.push(new CString(offp.getName(), t), t);
if(s != null) {
MCOfflinePlayer[] players = s.getOfflinePlayers();
if(players != null) {
for(MCOfflinePlayer offp : players) {
ret.push(new CString(offp.getName(), t), t);
}
}
}
return ret;

0 comments on commit dd8b525

Please sign in to comment.