Prevent player from doing anything while data loads.

Discussion in 'Plugin Development' started by Noahz123, Jul 23, 2014.

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

    Noahz123

    I don't have a lot of time so I am going to make this short. I have the basics of loading data from mysql etc. But to make my idea work I need to make it so that the player cannot interact with the server in any way until they are given access. I can't let them launch events that use this data to prevent any problems that might arise. Pretty much, I want the server to ignore any packets sent by the player until a condition is met (Or some equivalent). Thanks in advance.
     
  2. Offline

    jimbo8

    Put the players in a hashset while the data loads. Check if the players are in the hashset, if they are, freeze their movement ;)
     
  3. Offline

    Noahz123

    Let me be more specific.

    I need to prevent the player from doing ANYTHING. I need their attempts to do anything be ignored, and prevent any code that could run as a result.

    My favorable idea is to ignore any packets they send so they dont launch any events.

    Another thing that could work is prevent players from joining the server until they have their data loaded.

    So, players attempts to join server

    Plugin loads data from mysql database, when the data is loaded, call a sync event that allows them to join the server and start sending information.
     
  4. Offline

    ImDeJay

    mysql works pretty fast so you shouldnt really have an trouble just loading the data when they join, it will be almost instant.

    any other way would be to just interupt all the events, playermove, playerinteract,inventoryopen etc and just cancel them all if they are in the hashset like said above.
     
  5. Offline

    Noahz123

    That could work, but would be tediously annoying. The problem is while the server is reloading players may launch an event and it would cause an issue. Let me make my question clear.

    Is It possible to ignore all packets sent by a player for a certain period of time?
     
  6. Offline

    xTigerRebornx

    Noahz123 Could use ProtocolLib to intercept incoming packets.
     
  7. Offline

    Noahz123

    I don't want to use a huge library to do one small task, and the job is fairly broad and general, is there any way using nms code to block all packets sent by a client?

    bump

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

    DannyDog

    Well...
    Don't let them on the server while the sql loads?
    hue
     
  9. Offline

    Noahz123

    I don't want to load all the data at the same time. lets put it this way.

    Player tries to join.

    Server noticies that the player is going to join, so it loads the data.

    Server lets the player join the server.

    The question is, how to I delay them from joining it? You know, put the on "hold".
     
  10. Offline

    jimbo8

    But he won't be able to join before all the data has loaded? :p

    If you have different MySQL-checks on joinevent, they will all be done before he has logged in completely. You don't have to put them on "hold".
     
    AoH_Ruthless likes this.
  11. Offline

    Deleted user


    I'd suggest taking the long approach and just cancelling each affected aspect.
    When the data begins to load put the player's UUID in a List

    then listen to viable events, and if the Player associated with the fired event is loading data aka their UUID is in the List: then...
    (I may be missing an event or so.. )
    However for when a player moves I'd suggest using a timer to loop through all player's and then storing their location in a HashMap<UUID, Location>(). If the already stored Location for the player is different than the player's current then teleport them to the stored Location thus "freezing them". This is more efficient then using the PlayerMoveEvent().
    And cancel the event accordingly, remember the remove the player from the List after data is done loading (and remove the player if they quit or are kicked while data is loading)
     
    Noahz123 likes this.
  12. Offline

    EcMiner

    Mysql is pretty fast, it will max take like 1 or 2 seconds if you're doing it efficiently, so putting them on a hold isn't really necessary as the data is probably loaded before he is actually connected
     
  13. Offline

    _Filip

    Use PlayerLoginEvent instead of PlayerJoinEvent.
     
    EcMiner likes this.
  14. Offline

    Noahz123

    would asyncplayerpreloginevent be better for this situation?
     
  15. Offline

    EcMiner

    I don't think it matters which one you use, correct me if I'm wrong :)
     
  16. Offline

    Noahz123

    One last question, it seems that in the playerpreloginevent (Which I want to do because it it is ran first and is async by default, making life easier), it only gives the player name, is this later going to be transferred to the new UUID system?
     
  17. Offline

    Deleted user

    worst case scenario; when players join save their UUID and name in a HashMap to reference later.
     
  18. Offline

    Garris0n

    Update your server and Bukkit, it was updated to include UUID support a while ago.

    The event occurs before the player joins and there is no Player object (it does not exist at that time). Before they added the UUID to the event, it was impossible to get it until later, which sucks for what OP is doing.
     
Thread Status:
Not open for further replies.

Share This Page