Fix possible race condition

This commit is contained in:
Luck 2016-07-23 22:34:42 +01:00
parent d32d6b5474
commit df209f6515
2 changed files with 7 additions and 2 deletions

View File

@ -1,6 +1,5 @@
package me.lucko.luckperms.api; package me.lucko.luckperms.api;
import me.lucko.luckperms.api.data.Callback; import me.lucko.luckperms.api.data.Callback;
import java.util.UUID; import java.util.UUID;

View File

@ -3,7 +3,9 @@ package me.lucko.luckperms.users;
import me.lucko.luckperms.LPBukkitPlugin; import me.lucko.luckperms.LPBukkitPlugin;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
public class BukkitUserManager extends UserManager { public class BukkitUserManager extends UserManager {
private final LPBukkitPlugin plugin; private final LPBukkitPlugin plugin;
@ -53,6 +55,10 @@ public class BukkitUserManager extends UserManager {
@Override @Override
public void updateAllUsers() { public void updateAllUsers() {
plugin.getServer().getOnlinePlayers().stream().map(Player::getUniqueId).forEach(u -> plugin.getDatastore().loadUser(u)); // Sometimes called async, so we need to get the players on the Bukkit thread.
plugin.doSync(() -> {
Set<UUID> players = plugin.getServer().getOnlinePlayers().stream().map(Player::getUniqueId).collect(Collectors.toSet());
plugin.doAsync(() -> players.forEach(u -> plugin.getDatastore().loadUser(u)));
});
} }
} }