Change users being updated async and refactor update task

This commit is contained in:
Luck 2016-06-17 23:23:28 +01:00
parent 00c3a8b415
commit 484bc44288
9 changed files with 51 additions and 54 deletions

View File

@ -55,12 +55,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
groupManager = new GroupManager(this);
// Run update task to refresh any online users
new UpdateTask(this).run();
runUpdateTask();
int mins = getConfiguration().getSyncTime();
if (mins > 0) {
long ticks = mins * 60 * 20;
new UpdateTask(this).runTaskTimer(this, ticks, ticks);
getServer().getScheduler().runTaskTimerAsynchronously(this, new UpdateTask(this), ticks, ticks);
}
// Provide vault support
@ -111,6 +111,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
@Override
public void runUpdateTask() {
new UpdateTask(this).runTask(this);
getServer().getScheduler().runTaskAsynchronously(this, new UpdateTask(this));
}
}

View File

@ -1,25 +0,0 @@
package me.lucko.luckperms.runnables;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.LPBukkitPlugin;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@AllArgsConstructor
public class UpdateTask extends BukkitRunnable {
private final LPBukkitPlugin plugin;
@Override
public void run() {
plugin.getLogger().info("Running update task.");
// Re-load all of the groups
plugin.getGroupManager().loadAllGroups();
// Refresh all online users.
for (Player p : Bukkit.getOnlinePlayers()) {
plugin.getDatastore().loadUser(p.getUniqueId(), success -> {});
}
}
}

View File

@ -50,4 +50,11 @@ public class BukkitUserManager extends UserManager {
public User makeUser(UUID uuid, String username) {
return new BukkitUser(uuid, username, plugin);
}
@Override
public void updateAllUsers() {
for (Player p : plugin.getServer().getOnlinePlayers()) {
plugin.getDatastore().loadUser(p.getUniqueId());
}
}
}

View File

@ -75,7 +75,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
@Override
public void runUpdateTask() {
new UpdateTask(this).run();
doAsync(new UpdateTask(this));
}
@Override

View File

@ -1,23 +0,0 @@
package me.lucko.luckperms.runnables;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.LPBungeePlugin;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@AllArgsConstructor
public class UpdateTask implements Runnable {
private final LPBungeePlugin plugin;
@Override
public void run() {
plugin.getLogger().info("Running update task.");
// Re-load all of the groups
plugin.getGroupManager().loadAllGroups();
// Refresh all online users.
for (ProxiedPlayer p : plugin.getProxy().getPlayers()) {
plugin.getDatastore().loadUser(p.getUniqueId(), success -> {});
}
}
}

View File

@ -41,4 +41,11 @@ public class BungeeUserManager extends UserManager {
public User makeUser(UUID uuid, String username) {
return new BungeeUser(uuid, username, plugin);
}
@Override
public void updateAllUsers() {
for (ProxiedPlayer p : plugin.getProxy().getPlayers()) {
plugin.getDatastore().loadUser(p.getUniqueId());
}
}
}

View File

@ -135,7 +135,8 @@ public class HikariDatastore extends Datastore {
return false;
});
if (success) plugin.getUserManager().updateOrSetUser(user);
// User updating and loading should be done sync as permission attachments are updated
if (success) plugin.doSync(() -> plugin.getUserManager().updateOrSetUser(user));
return success;
}
@ -171,7 +172,8 @@ public class HikariDatastore extends Datastore {
return true;
});
if (success) plugin.getUserManager().updateOrSetUser(user);
// User updating and loading should be done sync as permission attachments are updated
if (success) plugin.doSync(() -> plugin.getUserManager().updateOrSetUser(user));
return success;
}

View File

@ -0,0 +1,24 @@
package me.lucko.luckperms.runnables;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.LuckPermsPlugin;
@AllArgsConstructor
public class UpdateTask implements Runnable {
private final LuckPermsPlugin plugin;
@Override
public void run() {
plugin.getLogger().info("Running update task.");
// Reload all of the groups
plugin.getDatastore().loadAllGroups();
String defaultGroup = plugin.getConfiguration().getDefaultGroupName();
if (!plugin.getGroupManager().isLoaded(defaultGroup)) {
plugin.getDatastore().createAndLoadGroup(defaultGroup);
}
// Refresh all online users.
plugin.getUserManager().updateAllUsers();
}
}

View File

@ -117,4 +117,9 @@ public abstract class UserManager {
* @return a new {@link User} object
*/
public abstract User makeUser(UUID uuid, String username);
/**
* Reloads the data of all online users
*/
public abstract void updateAllUsers();
}