AsyncPlayerPreLoginEvent not calling?

Discussion in 'Spigot Plugin Development' started by Hex_27, Jun 5, 2017.

  1. Code (Text):
     @EventHandler(priority = EventPriority.LOW)
        public void onPreJoin(AsyncPlayerPreLoginEvent e) {
            UUID uuid = e.getUniqueId();

            KingdomPlayer kp = loadKingdomPlayer(uuid);

            // kp cannot be null but just in case of bug
            if (kp != null){
                userList.put(uuid, kp);
                Kingdoms.logInfo("Loaded info for " + kp.getName());
                if (!Kingdoms.config.defaultMarkersOn) {
                    kp.setMarkDisplaying(false);
                }
            }else{
                Kingdoms.logInfo("Failed to load info for " + e.getName());
                throw new RuntimeException("preload failed for "+e.getName());
            }
         
         
        }
     
        @EventHandler(priority = EventPriority.HIGH)
        public void onJoin(PlayerJoinEvent e) {
            Player player = e.getPlayer();
            UUID uuid = player.getUniqueId();

            KingdomPlayer kp = (KingdomPlayer) userList.get(uuid);
            if(kp == null){
                Kingdoms.logInfo("Info for " + player.getName() + " isn't loaded. Attempting to load");
                //throw new RuntimeException("Something went wrong. Player info is not loaded for "+player.getName());
                asyncLoadPlayer(player);
         
         
            }else{

                kp.setPlayer(player);
            }
            plugin.getServer().getPluginManager().callEvent(new KingdomPlayerLoginEvent(kp));
        }
    Anyway, the main things in the code are "asyncLoadPlayer(player);" and "loadKingdomPlayer(uuid)", which is primarily the same thing, except one is done through an async task. However, the message "Info for player isn't loaded. Attempting to load" sometimes* shows up. Is the prelogin event somehow not working?
     
    #1 Hex_27, Jun 5, 2017
    Last edited: Jun 5, 2017
  2. Maybe debug outside your check ...
     
  3. There are debug messages outside the check. It's the Kingdoms.log messages. Sometimes it just debugs "failed to load" in asyncprelogin, then somehow it just loads the info just fine in playerjoin
     
  4. Remove your Priority. Maybe it should help cuz the Event works fine for me.
     
  5. Event Registered?
     
  6. Correction, it sometimes doesn't debug failed to load, or Loaded info for from the async event. It just goes straight to "Failed to load info" in the playerjoinevent.


    Yes it definitely is. It does work sometimes.

    I could try that, but why would priority affect anything?
     
  7. Because Priorities... What goes first what goes last...
     
  8. Removed priorities, the testers still send the same result.
     
  9. Odd, have you tested outside your statements? So that whenever the event is fired it debugs. The event works fine for me though
     
  10. Race condition between async and sync threads. This is normal for a lot of things. If anything (including other plugins) slows down that async event then it is quite possible for the sync event to fire before it finishes.
     
    #10 BillyGalbreath, Jun 6, 2017
    Last edited: Jun 6, 2017
  11. But it should give the debug statement regardless isn't it? There's an else statement. Or is the database load taking too long?

    Race co ditions?
     
  12. Just debug in and outsite your statements. Because the event works fine for me though.
     
  13. Would be good if bukkit provided async methods like bungee does, i had way too many problems loading/saving stuff asyinc, so i just gave up on it, if anyone does know what would be the best way to fix this it would help a lot.
     
  14. That's correct.
     
  15. So I don't have a choice but to just load all data in player join?
     
  16. You can use PlayerLoginEvent, load the data async and use a callback to set the player from the event.
     
  17. I mean I moved the load to asyncplayerprelogin because the data loading had to be async, and I thought the data had to be loaded before the player entered the server. Wouldn't playerloginevent just be similar to playerjoinevent if I'm just going to make an async task for it? There was also some dumb issue that players could spark an error if their data wasn't loaded in time
     
  18. Yeah that would be kinda the same, but using PlayerLoginEvent you would have the data loaded a bit before, but not much difference, would be cool if they added support for events like bungee does, anyways even if they did i wouldn't update my server version lol.