UUIDFetcher causing lag

Discussion in 'Plugin Development' started by iBecameALoaf, Jun 8, 2014.

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

    iBecameALoaf

    So with the new update, minecraft is using UUID's. This screwed up (or would've) a plugin I was working on because I was doing a lot of things that use player names. I already posted a thread for help, and I finally got that working, but I noticed that it has been causing giant lag spikes whenever I use it to get a UUID. I think the problem is that it's being called in the current thread, which evilmidget said not to do. If that's the case, does anyone know how to use a different thread for getting UUID's?
    Thanks!

    Code:

    Methods I created:

    Code:
        public UUID getUUID(String name) {
         
            UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
         
            Map<String, UUID> uuidmap = null;
            try {
            uuidmap = fetcher.call();
            } catch (Exception e) {
            this.getLogger().warning("Exception while running UUIDFetcher");
            e.printStackTrace();
            }
            String uuid = uuidmap.toString();
         
            System.out.println(uuid);
         
            uuid = uuid.split("=")[1];
            uuid = uuid.replace("}", "");
         
            UUID finalUUID = UUID.fromString(uuid);
            return finalUUID;
        }
     
        public Player getPlayer(UUID uuid){
            Player player = Bukkit.getPlayer(uuid);
            return player;
        }
    Line I'm calling them:

    Code:
    Player player = plugin.getPlayer(plugin.getUUID(args[0]));
     
  2. Offline

    xTrollxDudex

  3. Offline

    iBecameALoaf

    What? Why? :p
     
  4. Offline

    1Rogue


    Because methods are blocking and you cannot do anything else until the method returns unless you do it from another thread.
     
  5. Offline

    iBecameALoaf

    *feels like idiot*... I thought he meant create another thread on this forum. (ultimate facedesk). Anyway, how do I create another thread and do other things on it... i'm guessing it's not Thread thread = new Thread(), cause that's for plain java, or am I wrong...

    1Rogue
    would this do the trick?

    new BukkitRunnable() {
    @Override
    public void run() {
    }
    }.runTaskAsynchronously(plugin);
    StringBuilder sb = new StringBuilder(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  6. Offline

    teej107

    iBecameALoaf Thread thread = new Thread() would work. or using what Bukkit provides will also work. They are both creating separate threads.
     
  7. Offline

    iBecameALoaf

    hmm... I'm using what bukkit is providing and there is a delay between when the player enters the command and the time the command executes when using BukkitRunnable...

    Maybe it's just my server lagging... it's been acting up all day. (i'm running it localhost)
     
  8. Offline

    teej107

    iBecameALoaf Is that what you are referring to the lag spikes? If the server lags when you use the method in the main thread, then it will takes some time as well in another thread.
     
  9. Offline

    1Rogue


    You would need your logic inside of the run() method.
     
  10. Offline

    iBecameALoaf

    That's what I'm doing ;/
     
Thread Status:
Not open for further replies.

Share This Page