Skip to content

Instantly share code, notes, and snippets.

@Magnum97
Created March 27, 2021 05:11
Show Gist options
  • Save Magnum97/9b4e3f9ba89a6d3575143b4cbe7d1158 to your computer and use it in GitHub Desktop.
Save Magnum97/9b4e3f9ba89a6d3575143b4cbe7d1158 to your computer and use it in GitHub Desktop.
Minecraft UUID fetcher
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import java.util.Optional;
import java.util.UUID;
public class FetchUUID {
public FetchUUID() {
}
public static Optional<UUID> getID(String user) {
OfflinePlayer p = Bukkit.getOfflinePlayer(user);
return Optional.of(p.getUniqueId());
}
}
@Magnum97
Copy link
Author

Magnum97 commented Mar 27, 2021

A safe UUID fetcher - it will never return null but it might be empty. My typical use is:

        if (!Bukkit.getPlayer(String.valueOf(FetchUUID.getID(buyer))).hasPlayedBefore()) {
            if (!seller.hasPlayedBefore()) {
                sender.sendMessage("Player not found on this server");
                return;

            }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment