Read any player tag and apply a player their file in real time while the player is on.

Discussion in 'Plugin Development' started by Mr. Sandwich, Apr 5, 2018.

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

    Mr. Sandwich

    Hey, so whenever a player joins the server loads their player file from the playerdata folder and applies it to them, the file saves when the player quits the server so any changes made to the file while the player is on will not be saved. I want to get custom tags in real time while the player is on(incase their tags changed since they logged in), for example imagine that like the attribute tag "flySpeed" there's another attribute tag "sandwich" from a different a plugin and this one is obviously custom and not supported by Bukkit, so how I can I get it in real time? Because if I try to get it through the file it won't get updated live value. Also because this tag isn't supported by Bukkit I can't set it in real time either just to get the one from the file, I think the way is making the server save the player file and reload it while the player is on but I can't figure out how to do it. I tried to call a PlayerQuitEvent and a PlayerJoinEvent but it didn't work. Thanks in advance.
     
    Last edited: Apr 5, 2018
  2. Offline

    CommonSenze

    @Mr. Sandwich
    Firstly, I need you to elaborate what you mean by tags. Do you mean name tags for the player to call themselves in game? Or are you referring to something else? If so, please specify what they are.

    Now if I'm thinking what you're thinking, you want to get everything from a file and save them in variables so you can change them while the player is on and set them back in the file when the player leaves. What I recommend you do is the following:
    (1) Make a Class named User with a constructor that takes in the player.
    (2) In join event have a hashmap of UUID's and users and save the players uuid and their user to this hashmap
    (3) In the users constructor, get the values specified from the files and set them to variables
    (4) Make getters and setters for those variables so you can change them while the player is on
    (5) Make a static getter that returns the players user in the join event class like so
    Code:java
    1. public static User getUser(Player player){
    2. return USERS.get(player.getUniqueId());
    3. }

    (6) When you would like to change the users variable, get the user from the player and set the variable to the new desired value.

    I do hope this helped a little. If not, elaborate exactly want you want so I can help you.
     
  3. Offline

    Mr. Sandwich

    That's actually what I already did anyway, it doesn't solve it because my problem is that the tags I need(which are like you assumed are NBT tags in the playerfile in the playerdata folder in the world folder) are from a different plugin and the only way to access those variables are getting them through the player file as NBT tags, the problem is that I want to get the live real time variables and the plugin saves them for the player when they log out or when the server auto-saves(or when /save-all is used).

    EDIT: I forgot to say that like I said using save-all does save the variables to the file and that way I can get it when I want, but I want it so frequently I think that would take too much on the server. If I do it every 5 seconds and then update like 10 variables for around 100 players makes it 1000 variables plus the action of the server saving and overwriting previous player files, would that take too much power and lag the server or is it fine? If it is fine what do you think it's limit, if it's not what do you think I can do? Thanks in advance.
    @CommonSenze
     
    Last edited: Apr 7, 2018
  4. Offline

    DutchJellyV2

    I think you should try to use events because it's ugly to just save every 5 seconds. I think that for instance saving player data in onDisable() would be a better option.
     
  5. Offline

    Mr. Sandwich

    @DutchJellyV2 I'm not sure I understand what you mean. Use events how? saving player data only onDisable won't help me at all.
     
  6. Offline

    MightyOne

    When do you want to use these tags and how? Based on what you wrote it seems you'd like to have an event that fires when a tag gets added/changed/whatever... I don't know yet why you cant just get a tag when its needed like when another event fires.
    What is the purpose of these tags?
     
  7. Offline

    DutchJellyV2

    What I meant is that you could store everything in the server memory until the server gets stopped.
     
Thread Status:
Not open for further replies.

Share This Page