Unbanning all players

Discussion in 'Plugin Development' started by Chaoscrasher, Jun 4, 2014.

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

    Chaoscrasher

    So I have a plugin that successfully deletes the banned-players.json file in the main directory.
    Unfortunately this does not seem to unban all players as I would have hoped.
    I think this is a result of the server essentially reading off a copy in the memory and resaving it to disk.

    So does anyone know how I can unban all banned users otherwise?

    Would be really appreciated :)
     
  2. Chaoscrasher
    Code:java
    1. for(OfflinePlayer player : Bukkit.getOfflinePlayers()) {
    2. player.setBanned(false);
    3. }
     
  3. Offline

    Chaoscrasher

    Thanks, that is a good idea. I thought this method did not exist :)
    Edit: Just realized that p.setBanned(boolean) is deprecated.

    1. Why? ):
    2. What is the "better" way? Has it something to do with the recen UUID change?
     
  4. Offline

    adam753

    You're correct, banned-players.json is only read once at startup. Instead you could juts use getBannedPlayers() and unban all of them.
    Code:
    for(OfflinePlayer player: getServer().getBannedPlayers()) {
        player.setBanned(false);
    }
    
    Edit: beaten with the exact same code. Actually no, mine is better.
     
  5. Offline

    WinX64

    You can also use the new ban api. Retrieve a set of BanEntry by calling Server#getBanList(BanList.Type)#getBanEntries(), then just iterare through it, get the name/ip and call BanList#pardon to unban the target.
     
  6. Offline

    thecrystalflame

    You can also iterate through

    Code:java
    1.  
    2. Bukkit.getServer().getBannedPlayers();
    3.  
     
  7. Offline

    Chaoscrasher

    Thanks for the clarification but you both use Player.setBanned() with is deprecated in 1.7.9 :/

    Edit: @ thecrystalflame Or would: BanList.pardon(p.getName()) actually work? It should, shouldn't it?

    Tried WinX64's way currently (thanks!), even though the implementation needs some really confusing mechanics.
    Gonna report what is working :)
     
Thread Status:
Not open for further replies.

Share This Page