Get UUID without freezing main thread?

Discussion in 'Plugin Development' started by Bammerbom, Apr 3, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Bammerbom

    How to get an UUID without freezing the main Bukkit thread?
     
  2. Jhtzb If you're "feezing the main Bukkit thread" then you're not just getting a UUID, you're doing something else as well because you can get the UUID of an online player really easily. Either way, run it on another thread? What is it exactly that you're trying to do?
     
  3. Offline

    Bammerbom

    AdamQpzm Sorry Im not explaining it right. I am getting the UUID of an offline player using an API (Connecting to the Mojang servers), but it takes some seconds to connect.
     
  4. Offline

    SuperOmegaCow

    Jhtzb
    Then use a separate thread.
     
  5. Offline

    Bammerbom

  6. Offline

    RawCode

    google + java + separate thread
     
    Garris0n likes this.
  7. Offline

    lDucks

    Bukkit has a scheduler which allows for threading. Call an asynchronous task.
     
  8. Offline

    xize

    Jhtzb
    just do something along the lines of:

    Code:
    public class MojangLookup implements Callable<String> {
     private String name;
     private String uuid;
     
     public MojangLookup(String name) {
      this.name = name;
      try {
       this.uuid = call();
      } catch (Exception e) {
       System.out.print("no connection with mojang site");
      } 
     }
     
     public String getUniqueId() {
      return uuid;
     }
     
     public String getName() {
      return name;
     }
     
     @Override
     public String call() throws Exception {
      //do your parse things from the authclient
      String exampleUUID = "blah";
      return exampleUUID;
     }
    }
    
    I never heard about Callable but this thing actually rocks, a runnable is not good at all because you can't depend on slow IOExceptions so you actually want something smilliar as Runnable but which returns the String instead of a void and else throw faster a exception an Callable can do this while a Runnable cannot unless the thread is frozen to long.

    note ive wrote this code myself but about the Callable ive found here: http://forums.bukkit.org/threads/player-name-uuid-fetcher.250926/ most of this I got from here since I runned myself into multiple issues using a Runnable so credits to evilmidget38 i've learned something new:)
     
Thread Status:
Not open for further replies.

Share This Page