From df209f65157cc2af9f1f1a7cf9bb454e0c3e082c Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 23 Jul 2016 22:34:42 +0100 Subject: [PATCH] Fix possible race condition --- api/src/main/java/me/lucko/luckperms/api/Datastore.java | 1 - .../java/me/lucko/luckperms/users/BukkitUserManager.java | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/me/lucko/luckperms/api/Datastore.java b/api/src/main/java/me/lucko/luckperms/api/Datastore.java index 5e21198d5..ed13bfbbd 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Datastore.java +++ b/api/src/main/java/me/lucko/luckperms/api/Datastore.java @@ -1,6 +1,5 @@ package me.lucko.luckperms.api; - import me.lucko.luckperms.api.data.Callback; import java.util.UUID; diff --git a/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUserManager.java b/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUserManager.java index 08b14e071..e7ad491ff 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUserManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUserManager.java @@ -3,7 +3,9 @@ package me.lucko.luckperms.users; import me.lucko.luckperms.LPBukkitPlugin; import org.bukkit.entity.Player; +import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; public class BukkitUserManager extends UserManager { private final LPBukkitPlugin plugin; @@ -53,6 +55,10 @@ public class BukkitUserManager extends UserManager { @Override 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 players = plugin.getServer().getOnlinePlayers().stream().map(Player::getUniqueId).collect(Collectors.toSet()); + plugin.doAsync(() -> players.forEach(u -> plugin.getDatastore().loadUser(u))); + }); } }