Util Offline Player Data Loader [1.4.7 to 1.8]

Discussion in 'Resources' started by Techcable, Feb 9, 2015.

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

    Techcable

    Have you ever wanted to load the data of a player that is offline, and needed to stay compatible with multiple versions?

    I did too, so i created a class to load player data from a file called Offline Player Loader.

    Source Code

    Usage:
    Call OfflinePlayerLoader.loadPlayer to load an offline player

    Examples:
    To get an offline player's health:
    Code:
    public static double getHealth(UUID playerId)
      Player loaded = OfflinePlayerLoader.loadPlayer(playerId);
      return loaded.getHealth();
    }
    Projects Using
    Warning:
    This plugin access server internals through reflection, so although it doesn't usually break between versions, it may. Please tell me if it doesn't work.
     
    Last edited: Feb 11, 2015
  2. Offline

    ProStriker123

    ChipDev likes this.
  3. Offline

    viper_monster

    @Techcable Would it cause a memory leak if it's not unloaded later?
     
  4. Offline

    Techcable

    No.
    Normally the server stores a reference to the player object and unloads it when the player logs off unless you also have a reference to the player. Here only you have a reference so the java GC will reclaim the memory after you are done.
    If you find one, please let me know.
     
  5. Offline

    GriffinPvP

    This is awesome! Should people run the loadPlayer() method in another thread though?
     
  6. Offline

    teej107

    @Techcable Is this so you can get the player's information from their dat file?
     
  7. Offline

    GriffinPvP

    It gets a Player instance from a UUID or String, and yes, it loads it from the .dat file afaik.
     
  8. Offline

    teej107

    @GriffinPvP I wanted to know the purpose though. Creating a Player is a bit unnecessary if you only need access to the information in their dat file.
     
  9. Offline

    GriffinPvP

    Well it's easier to have a wrapper for all the data instead of having to get them directly from the .dat.
     
  10. Offline

    RawCode

    i have only one question, why all this BS "coding" instead of simple and effective NBT stream reader baked by two layer hashmap?
     
  11. Offline

    Techcable

    I don't think it's thread safe.
    This works on all versions from 1.4.7 to 1.8 without relying on obfuscated code, and reading the nbt data from file is hard and error prone.

    What is "BS" about reflection?
    Reading the data from an nbt file is hard to implement if you need to preserve all the data (enchantments, lore, skul properties, map data, etc.) in an itemstack.
     
    Last edited by a moderator: Feb 12, 2015
  12. Offline

    RawCode

    NBT is open format, you can grab all required code from mojang's github without obfuscation and ever with comments and IO such files without any knowledge about how they works.

    as for 3rd party implementation - reading NBT is not any harder then theading plain text.
     
    xTrollxDudex likes this.
  13. Offline

    _Filip

    @Techcable Or just look at how minecraft does it.....
     
    xTrollxDudex likes this.
  14. Offline

    NonameSL

    This seems nice, but just out of curiosity, I have a question:
    What happens if I try to, lets say, teleport a player / give him an item / set his health / etc.? Will it happen but just when the players log back again (he will log in where I teleported him / with the item I gave him / with the health I gave him when he was out)?

    Can someone please test this?
     
  15. Offline

    Techcable

    Teleporting players is untested, but setting health and items is tested by my plugin, CombatTagReloaded. Once he logs back in, he will get his stuff.
     
Thread Status:
Not open for further replies.

Share This Page