org.bukkit.OfflinePlayer.setWhitelisted() isn't persistent

Discussion in 'Spigot Plugin Development' started by Skillere_V2, Oct 3, 2019.

  1. ```
    setWhitelisted(true)
    ```

    doesn't survive a server restart.

    I suspect this has nothing to do with whitelisted and that any action on OfflinePlayer will not survive a restart. Or maybe even any action on server will not survive a restart.

    to get the player I do getServer().getOfflinePlayer(<some uuid>).setWhitelisted(true)
     
  2. uuid problem? check if it's in the file
     
  3. It is not a UUID problem from what I can tell because before a restart the whitelist works as expected.

    The correct uuid gets saved to whitelist.json in the following format

    [ { "uuid": "xxx-xxx-xx-xxx-xxxx" } ]

    the uuid corresponding to the uuid Is whitelisted (just in the file) not another one.

    It is as if spigot didn't check for whitelist.json
     
  4. After more troubleshooting I think part of the problem is that setWhitelisted(true) only puts the uuid inside whitelist.json and not the name (like /whitelist add would do)
     
  5. OK so I think this is a bug in spigot where it requires a name in whitelist.json (not just a uuid) for the whitelist to work. Otherwise on startup 1. whitelist doesn't work 2. I get an error about malformed JSON and missing name (only sometimes for the latter)

    Where should I report this?

    Should I report this to Mojang since they seem to be using whitelist.json as well?
     
  6. Yep. The whole whitelist thing is a Minecraft feature, not Bukkit/Spigot related :)
     
    • Like Like x 2
  7. Ok so here is my conclusion:

    1. whitelist.json requires the "name" field
    2. the server doesn't even care about the "name" field as it can be erroneous and still work

    This applies to every Minecraft server based on the official one (including the official one).
     
  8. This still seems to be an error in spigot as when `/whitelist add x` is used, both `name` and `uuid` are populated whereas `getServer().getOfflinePlayer(<some_uuid>).setWhitelisted(true)` only sets `uuid`
     
  9. Please look at my previous comment and why this can still be fixed in spigot.
     
  10. Gadse

    Gadse Previously GummiBoat

    I'm pretty sure you need to use Server#reloadWhitelist (Bukkit#reloadWhitelist does the same if you're too lazy to grab your server) after setting a player as whitelisted via API.
     
  11. What I refer to as "effective whitelist" is the in-memory whitelist that the minecraft server checks against when a player joins.

    This doesn't work at all.

    When Server#reloadWhitelist is called what happens is that the whitelist.json file is read and its parsed content is set as the effective whitelist

    So here is the list of stuff that happens when whitelisting a player (using getServer().getOfflinePlayer(<some_uuid>).setWhitelisted(true) and then calling reloadWhitelist):

    1. The server adds the player to the effective whitelist
    2. The server write to whitelist.json (w/ only the "uuid" not the "name")
    3. reloadWhitelist is called
    4. The server reads whitelist.json from disk.
    5. Because this file has been wrongly set by getServer().getOfflinePlayer(<some_uuid>).setWhitelisted(true), whitelist.json is wrongly parsed resulting in the effective whitelist being empty
    6. No one can connect

    Source: I tried each step seperatly

    This shows that there are 2 bugs as I have said earlier:

    1. The bug where getServer().getOfflinePlayer(<some_uuid>).setWhitelisted(true) set the effective whitelist correctly but whitelist.json incorrectly
    2. The bug where reloadWhitelist cannot parse a wrong whitelist.json because the "name" field is missing even though the "name" field is actually ignored anyway

    The second bug belongs to Mojang and has been reported. However, the first bug can still be fixed.

    Where should I report the first bug?

    Also please keep in mind that these are "cyclical bugs": if bug 1 is fixed, there is no need to fix bug 2. And if bug 2 is fixed, there is no need to fix bug 1. Though in my opinion they should both be fixed because they both produce unwanted behaviour, especially the second one.

    Conclusion:

    Before running the server I run the following script:

    https://github.com/NilsIrl/DynaWhite/blob/5fc40ad1e37b1815b9a520b2e853e3dc1b6ff28b/fix_whitelist.sh

    which sets a random name to the "name" field in whitelist.json
     
    #11 Skillere_V2, Oct 12, 2019
    Last edited: Oct 12, 2019
  12. As I said, the whielist is Mojangs doing, so the bugs are on their side.
    I could see some weird excuse such as "we don't add the name since it could be changed on next login"
     
  13. The thing is that the name is irrelevant. `server.jar` ignores it. The other thing is that w/o the name what is the point of this even existing? The is no reason setWhitelisted(true) should change whitelist.json if it sets wrong values that are unusable.