Skip to content

Commit

Permalink
fix: async UUID grabbing in offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Thatsmusic99 committed Jun 21, 2023
1 parent 6219216 commit 097b26f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Expand Up @@ -51,7 +51,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return true;
}
HeadsPlus hp = HeadsPlus.get();
HPUtils.getOfflinePlayer(args[0]).thenAccept(player -> {
HPUtils.getOfflinePlayer(args[0]).thenAcceptAsync(player -> {
String uuid = player.getUniqueId().toString();
if (!hp.getServer().getOnlineMode()) {
hp.getLogger().warning("Server is in offline mode, player may have an invalid account! Attempting" +
Expand All @@ -61,7 +61,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (AutograbManager.grabProfile(uuid, sender, true)) {
hpc.sendMessage("commands.addhead.head-adding", sender, "{player}", player.getName());
}
});
}, HeadsPlus.async);
return true;
} else {
if (sender.hasPermission("headsplus.addhead.texture")) {
Expand Down
Expand Up @@ -32,8 +32,7 @@ public void onEvent(PlayerJoinEvent e) {
if (!hp.getServer().getOnlineMode()) {
hp.getLogger().warning("Server is in offline mode, player may have an invalid account! Attempting to " +
"grab UUID...");
String uuid = AutograbManager.grabUUID(player.getName(), 3, null);
AutograbManager.grabProfile(uuid);
AutograbManager.grabProfileUUID(player.getName());
} else {
AutograbManager.grabTexture(player, false, null);
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
Expand All @@ -24,6 +25,9 @@
import java.nio.charset.StandardCharsets;
import java.util.*;

/**
* Used to manage the texture autograbber.
*/
public class AutograbManager {

// texture lookups need to be protected from spam
Expand Down Expand Up @@ -89,6 +93,13 @@ public static boolean grabProfile(@Nullable String id, CommandSender callback, b
return true;
}

public static void grabProfileUUID(@NotNull String name) {
Bukkit.getScheduler().runTaskAsynchronously(HeadsPlus.get(), () -> {
String uuid = grabUUID(name, 3, null);
grabProfile(uuid);
});
}

public static void grabProfile(@Nullable String id) {
grabProfile(id, null, false);
}
Expand Down

0 comments on commit 097b26f

Please sign in to comment.