diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index 1a87ad00..d9922ea5 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -142,7 +142,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { } final LPBukkitPlugin i = this; - updateTaskBuffer = new BufferedRequest(5000L, this::doAsync) { + updateTaskBuffer = new BufferedRequest(6000L, this::doAsync) { @Override protected Void perform() { getServer().getScheduler().runTaskAsynchronously(i, new UpdateTask(i)); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java index 6efb27c9..59fdda03 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java @@ -130,12 +130,13 @@ public class VaultPermissionHook extends Permission { */ void save(PermissionHolder holder) { if (holder instanceof User) { - ((User) holder).refreshPermissions(); - plugin.getDatastore().saveUser(((User) holder)); + + plugin.getDatastore().saveUser(((User) holder), b -> { + ((User) holder).getRefreshBuffer().request(); + }); } if (holder instanceof Group) { - plugin.getDatastore().saveGroup(((Group) holder)); - plugin.runUpdateTask(); + plugin.getDatastore().saveGroup(((Group) holder), b -> plugin.getUpdateTaskBuffer().request()); } } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java index 181fe957..41e07102 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java @@ -102,7 +102,7 @@ public class BungeeListener extends AbstractListener implements Listener { // No previous data for this player plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(c.getUniqueId(), c.getName())); cache.addToCache(c.getUniqueId(), c.getUniqueId()); - plugin.getDatastore().saveUUIDData(c.getName(), c.getUniqueId()); + plugin.getDatastore().force().saveUUIDData(c.getName(), c.getUniqueId()).getOrDefault(false); } } else { UUID uuid = plugin.getDatastore().getUUID(c.getName()).getOrDefault(null); @@ -111,12 +111,12 @@ public class BungeeListener extends AbstractListener implements Listener { } // Online mode, no cache needed. This is just for name -> uuid lookup. - plugin.getDatastore().saveUUIDData(c.getName(), c.getUniqueId()); + plugin.getDatastore().force().saveUUIDData(c.getName(), c.getUniqueId()).getOrDefault(false); } // We have to make a new user on this thread whilst the connection is being held, or we get concurrency issues as the Bukkit server // and the BungeeCord server try to make a new user at the same time. - plugin.getDatastore().loadUser(cache.getUUID(c.getUniqueId()), c.getName()); + plugin.getDatastore().force().loadUser(cache.getUUID(c.getUniqueId()), c.getName()).getOrDefault(false); User user = plugin.getUserManager().get(cache.getUUID(c.getUniqueId())); if (user == null) { plugin.getLog().warn("Failed to load user: " + c.getName()); diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index 0fdfca83..f0a3a2a5 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -46,6 +46,7 @@ import me.lucko.luckperms.common.storage.Datastore; import me.lucko.luckperms.common.storage.StorageFactory; import me.lucko.luckperms.common.tracks.TrackManager; import me.lucko.luckperms.common.users.UserManager; +import me.lucko.luckperms.common.utils.BufferedRequest; import me.lucko.luckperms.common.utils.LocaleManager; import me.lucko.luckperms.common.utils.LogFactory; import net.md_5.bungee.api.config.ServerInfo; @@ -74,6 +75,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { private LocaleManager localeManager; private ContextManager contextManager; private CalculatorFactory calculatorFactory; + private BufferedRequest updateTaskBuffer; @Override public void onEnable() { @@ -121,6 +123,15 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { contextManager.registerCalculator(serverCalculator); contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer())); + final LPBungeePlugin i = this; + updateTaskBuffer = new BufferedRequest(6000L, this::doAsync) { + @Override + protected Void perform() { + doAsync(new UpdateTask(i)); + return null; + } + }; + int mins = getConfiguration().getSyncTime(); if (mins > 0) { getProxy().getScheduler().schedule(this, new UpdateTask(this), mins, mins, TimeUnit.MINUTES); @@ -254,11 +265,6 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { .isPresent(); } - @Override - public void runUpdateTask() { - doAsync(new UpdateTask(this)); - } - @Override public void doAsync(Runnable r) { getProxy().getScheduler().runAsync(this, r); diff --git a/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java b/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java index 8deedfa0..659fa0d6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java @@ -64,7 +64,7 @@ public class ApiProvider implements LuckPermsApi { @Override public void runUpdateTask() { - plugin.runUpdateTask(); + plugin.getUpdateTaskBuffer().request(); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/UserLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/UserLink.java index c81ea224..31beb3bc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/UserLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/UserLink.java @@ -79,7 +79,7 @@ public class UserLink extends PermissionHolderLink implements User { @Override public void refreshPermissions() { - master.refreshPermissions(); + master.getRefreshBuffer().requestDirectly(); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java index d2a12eff..ab085a30 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java @@ -168,7 +168,7 @@ public abstract class SubCommand { Message.USER_SAVE_ERROR.send(sender); } - user.refreshPermissions(); + user.getRefreshBuffer().request().getOrDefault(null); } public static void save(Group group, Sender sender, LuckPermsPlugin plugin) { @@ -178,7 +178,7 @@ public abstract class SubCommand { Message.GROUP_SAVE_ERROR.send(sender); } - plugin.runUpdateTask(); + plugin.getUpdateTaskBuffer().request(); } public static void save(Track track, Sender sender, LuckPermsPlugin plugin) { @@ -188,6 +188,6 @@ public abstract class SubCommand { Message.TRACK_SAVE_ERROR.send(sender); } - plugin.runUpdateTask(); + plugin.getUpdateTaskBuffer().request(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java index e1bdb33b..a6b2330e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/CreateGroup.java @@ -63,7 +63,6 @@ public class CreateGroup extends SingleMainCommand { Message.CREATE_SUCCESS.send(sender, groupName); LogEntry.build().actor(sender).actedName(groupName).type('G').action("create").build().submit(plugin, sender); - plugin.runUpdateTask(); return CommandResult.SUCCESS; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java index b049c245..a712b239 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java @@ -73,7 +73,7 @@ public class DeleteGroup extends SingleMainCommand { Message.DELETE_SUCCESS.send(sender, group.getDisplayName()); LogEntry.build().actor(sender).actedName(groupName).type('G').action("delete").build().submit(plugin, sender); - plugin.runUpdateTask(); + plugin.getUpdateTaskBuffer().request(); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java index 2e0ddff6..d439ffaf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBPermissions.java @@ -121,7 +121,7 @@ public class MigrationBPermissions extends SubCommand { } // Make a LuckPerms group for the one being migrated. - plugin.getDatastore().createAndLoadGroup(groupName); + plugin.getDatastore().createAndLoadGroup(groupName).getOrDefault(false); me.lucko.luckperms.common.groups.Group lpGroup = plugin.getGroupManager().get(groupName); try { LogEntry.build() @@ -133,7 +133,7 @@ public class MigrationBPermissions extends SubCommand { } migrateHolder(plugin, world, group, lpGroup); - plugin.getDatastore().saveGroup(lpGroup); + plugin.getDatastore().saveGroup(lpGroup).getOrDefault(false); } log.info("bPermissions Migration: Migrated " + groupCount + " groups in world " + world.getName() + "."); @@ -157,12 +157,12 @@ public class MigrationBPermissions extends SubCommand { } // Make a LuckPerms user for the one being migrated. - plugin.getDatastore().loadUser(uuid, "null"); + plugin.getDatastore().loadUser(uuid, "null").getOrDefault(false); me.lucko.luckperms.common.users.User lpUser = plugin.getUserManager().get(uuid); migrateHolder(plugin, world, user, lpUser); - plugin.getDatastore().saveUser(lpUser); + plugin.getDatastore().saveUser(lpUser).getOrDefault(false); plugin.getUserManager().cleanup(lpUser); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java index f91d47ef..22b6eb9d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationBungeePerms.java @@ -63,7 +63,7 @@ public class MigrationBungeePerms extends SubCommand { groupCount ++; // Make a LuckPerms group for the one being migrated - plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()); + plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()).getOrDefault(false); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase()); try { LogEntry.build() @@ -173,7 +173,7 @@ public class MigrationBungeePerms extends SubCommand { } } - plugin.getDatastore().saveGroup(group); + plugin.getDatastore().saveGroup(group).getOrDefault(false); } log.info("BungeePerms Migration: Migrated " + groupCount + " groups"); @@ -187,7 +187,7 @@ public class MigrationBungeePerms extends SubCommand { userCount++; // Make a LuckPerms user for the one being migrated. - plugin.getDatastore().loadUser(u.getUUID(), "null"); + plugin.getDatastore().loadUser(u.getUUID(), "null").getOrDefault(false); me.lucko.luckperms.common.users.User user = plugin.getUserManager().get(u.getUUID()); // Migrate global perms @@ -288,7 +288,7 @@ public class MigrationBungeePerms extends SubCommand { } } - plugin.getDatastore().saveUser(user); + plugin.getDatastore().saveUser(user).getOrDefault(false); plugin.getUserManager().cleanup(user); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationGroupManager.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationGroupManager.java index c52073e9..e5e84a32 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationGroupManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationGroupManager.java @@ -73,7 +73,7 @@ public class MigrationGroupManager extends SubCommand { } for (Group g : gg.getGroupList()) { - plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()); + plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()).getOrDefault(false); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase()); try { LogEntry.build() @@ -121,7 +121,7 @@ public class MigrationGroupManager extends SubCommand { } } - plugin.getDatastore().saveGroup(group); + plugin.getDatastore().saveGroup(group).getOrDefault(false); } Map, Boolean>> users = new HashMap<>(); @@ -202,7 +202,7 @@ public class MigrationGroupManager extends SubCommand { log.info("GroupManager Migration: Found a total of " + users.size() + " users and " + groups.size() + " groups."); for (Map.Entry, Boolean>> e : groups.entrySet()) { - plugin.getDatastore().createAndLoadGroup(e.getKey()); + plugin.getDatastore().createAndLoadGroup(e.getKey()).getOrDefault(false); me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(e.getKey()); try { LogEntry.build() @@ -241,11 +241,11 @@ public class MigrationGroupManager extends SubCommand { } } - plugin.getDatastore().saveGroup(group); + plugin.getDatastore().saveGroup(group).getOrDefault(false); } for (Map.Entry, Boolean>> e : users.entrySet()) { - plugin.getDatastore().loadUser(e.getKey(), "null"); + plugin.getDatastore().loadUser(e.getKey(), "null").getOrDefault(false); me.lucko.luckperms.common.users.User user = plugin.getUserManager().get(e.getKey()); for (Map.Entry, Boolean> n : e.getValue().entrySet()) { @@ -275,7 +275,7 @@ public class MigrationGroupManager extends SubCommand { } } - plugin.getDatastore().saveUser(user); + plugin.getDatastore().saveUser(user).getOrDefault(false); plugin.getUserManager().cleanup(user); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java index b954f26c..5a9cb5cd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPermissionsEx.java @@ -102,7 +102,7 @@ public class MigrationPermissionsEx extends SubCommand { maxGroupWeight = Math.max(maxGroupWeight, groupWeight); final String name = group.getName().toLowerCase(); - plugin.getDatastore().createAndLoadGroup(name); + plugin.getDatastore().createAndLoadGroup(name).getOrDefault(false); Group lpGroup = plugin.getGroupManager().get(name); try { LogEntry.build() @@ -226,7 +226,7 @@ public class MigrationPermissionsEx extends SubCommand { } } - plugin.getDatastore().saveGroup(lpGroup); + plugin.getDatastore().saveGroup(lpGroup).getOrDefault(false); } @@ -254,7 +254,7 @@ public class MigrationPermissionsEx extends SubCommand { } userCount++; - plugin.getDatastore().loadUser(u, "null"); + plugin.getDatastore().loadUser(u, "null").getOrDefault(false); User lpUser = plugin.getUserManager().get(u); try { @@ -387,7 +387,7 @@ public class MigrationPermissionsEx extends SubCommand { } plugin.getUserManager().cleanup(lpUser); - plugin.getDatastore().saveUser(lpUser); + plugin.getDatastore().saveUser(lpUser).getOrDefault(false); } log.info("PermissionsEx Migration: Migrated " + userCount + " users."); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPowerfulPerms.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPowerfulPerms.java index 2221e77c..aed259b0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPowerfulPerms.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationPowerfulPerms.java @@ -246,7 +246,7 @@ public class MigrationPowerfulPerms extends SubCommand { log.info("PowerfulPerms Migration: Starting group migration."); Map groups = pm.getGroups(); // All versions for (Group g : groups.values()) { - plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()); + plugin.getDatastore().createAndLoadGroup(g.getName().toLowerCase()).getOrDefault(false); final me.lucko.luckperms.common.groups.Group group = plugin.getGroupManager().get(g.getName().toLowerCase()); try { LogEntry.build() @@ -275,7 +275,7 @@ public class MigrationPowerfulPerms extends SubCommand { } } - plugin.getDatastore().saveGroup(group); + plugin.getDatastore().saveGroup(group).getOrDefault(false); } log.info("PowerfulPerms Migration: Group migration complete."); @@ -288,7 +288,7 @@ public class MigrationPowerfulPerms extends SubCommand { progress.put(uuid, new CountDownLatch(2)); // Create a LuckPerms user for the UUID - plugin.getDatastore().loadUser(uuid, "null"); + plugin.getDatastore().loadUser(uuid, "null").getOrDefault(false); User user = plugin.getUserManager().get(uuid); // Get a list of Permissions held by the user from the PP API. @@ -299,7 +299,7 @@ public class MigrationPowerfulPerms extends SubCommand { synchronized (progress) { progress.get(uuid).countDown(); if (progress.get(uuid).getCount() == 0) { - plugin.getDatastore().saveUser(user); + plugin.getDatastore().saveUser(user).getOrDefault(false); plugin.getUserManager().cleanup(user); } } @@ -422,7 +422,7 @@ public class MigrationPowerfulPerms extends SubCommand { synchronized (progress) { progress.get(uuid).countDown(); if (progress.get(uuid).getCount() == 0) { - plugin.getDatastore().saveUser(user); + plugin.getDatastore().saveUser(user).getOrDefault(false); plugin.getUserManager().cleanup(user); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java index 1835b921..6c942b3a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/subcommands/MigrationZPermissions.java @@ -72,7 +72,7 @@ public class MigrationZPermissions extends SubCommand { // Migrate all groups log.info("zPermissions Migration: Starting group migration."); for (String g : service.getAllGroups()) { - plugin.getDatastore().createAndLoadGroup(g.toLowerCase()); + plugin.getDatastore().createAndLoadGroup(g.toLowerCase()).getOrDefault(false); Group group = plugin.getGroupManager().get(g.toLowerCase()); try { LogEntry.build() @@ -115,13 +115,13 @@ public class MigrationZPermissions extends SubCommand { } } - plugin.getDatastore().saveGroup(group); + plugin.getDatastore().saveGroup(group).getOrDefault(false); } // Migrate all tracks log.info("zPermissions Migration: Starting track migration."); for (String t : service.getAllTracks()) { - plugin.getDatastore().createAndLoadTrack(t.toLowerCase()); + plugin.getDatastore().createAndLoadTrack(t.toLowerCase()).getOrDefault(false); Track track = plugin.getTrackManager().get(t.toLowerCase()); try { LogEntry.build() @@ -144,13 +144,13 @@ public class MigrationZPermissions extends SubCommand { } } - plugin.getDatastore().saveTrack(track); + plugin.getDatastore().saveTrack(track).getOrDefault(false); } // Migrate all users. log.info("zPermissions Migration: Starting user migration."); for (UUID u : service.getAllPlayersUUID()) { - plugin.getDatastore().loadUser(u, "null"); + plugin.getDatastore().loadUser(u, "null").getOrDefault(false); User user = plugin.getUserManager().get(u); for (Map.Entry e : service.getPlayerPermissions(null, null, u).entrySet()) { @@ -243,7 +243,7 @@ public class MigrationZPermissions extends SubCommand { } plugin.getUserManager().cleanup(user); - plugin.getDatastore().saveUser(user); + plugin.getDatastore().saveUser(user).getOrDefault(false); } log.info("zPermissions Migration: Success! Completed without any errors."); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java index b817ba98..22e58755 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java @@ -124,7 +124,7 @@ public class ExportCommand extends SingleMainCommand { int userCount = 0; for (UUID uuid : users) { userCount++; - plugin.getDatastore().loadUser(uuid, "null"); + plugin.getDatastore().loadUser(uuid, "null").getOrDefault(false); User user = plugin.getUserManager().get(uuid); boolean inDefault = false; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java index f1f433ea..ae2cdc27 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SyncCommand.java @@ -38,8 +38,9 @@ public class SyncCommand extends SingleMainCommand { @Override protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List args, String label) { - Message.UPDATE_TASK_RUN.send(sender); - plugin.runUpdateTask(); + Message.UPDATE_TASK_REQUEST.send(sender); + plugin.getUpdateTaskBuffer().request().getOrDefault(null); + Message.UPDATE_TASK_COMPLETE.send(sender); return CommandResult.SUCCESS; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java index b837c64f..eda5e134 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/CreateTrack.java @@ -63,7 +63,6 @@ public class CreateTrack extends SingleMainCommand { Message.CREATE_SUCCESS.send(sender, trackName); LogEntry.build().actor(sender).actedName(trackName).type('T').action("create").build().submit(plugin, sender); - plugin.runUpdateTask(); return CommandResult.SUCCESS; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java index 9d0e58c2..c27e1b17 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/DeleteTrack.java @@ -67,7 +67,7 @@ public class DeleteTrack extends SingleMainCommand { Message.DELETE_SUCCESS.send(sender, trackName); LogEntry.build().actor(sender).actedName(trackName).type('T').action("delete").build().submit(plugin, sender); - plugin.runUpdateTask(); + plugin.getUpdateTaskBuffer().request(); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditGroup.java index a07309f3..26a88db3 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditGroup.java @@ -64,7 +64,7 @@ public class BulkEditGroup extends SubCommand { Set uuids = datastore.getUniqueUsers().getOrDefault(null); for (UUID u : uuids) { - plugin.getDatastore().loadUser(u, "null"); + plugin.getDatastore().loadUser(u, "null").getOrDefault(false); User user = plugin.getUserManager().get(u); if (user == null) { continue; @@ -138,7 +138,7 @@ public class BulkEditGroup extends SubCommand { }); plugin.getUserManager().cleanup(user); - plugin.getDatastore().saveUser(user); + plugin.getDatastore().saveUser(user).getOrDefault(false); } Message.BULK_CHANGE_SUCCESS.send(sender, uuids.size()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditPermission.java index 6a78dc02..928f3c53 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/subcommands/BulkEditPermission.java @@ -64,7 +64,7 @@ public class BulkEditPermission extends SubCommand { Set uuids = datastore.getUniqueUsers().getOrDefault(null); for (UUID u : uuids) { - plugin.getDatastore().loadUser(u, "null"); + plugin.getDatastore().loadUser(u, "null").getOrDefault(false); User user = plugin.getUserManager().get(u); if (user == null) { continue; @@ -128,7 +128,7 @@ public class BulkEditPermission extends SubCommand { }); plugin.getUserManager().cleanup(user); - plugin.getDatastore().saveUser(user); + plugin.getDatastore().saveUser(user).getOrDefault(false); } Message.BULK_CHANGE_SUCCESS.send(sender, uuids.size()); diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index e7cf1ca1..cbba505f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -108,7 +108,8 @@ public enum Message { TRACKS_LOAD_ERROR("An unexpected error occurred. Unable to load all tracks.", true), TRACK_EMPTY("The track cannot be used as it is empty or contains only one group.", true), - UPDATE_TASK_RUN("&bRunning update task for all online users.", true), + UPDATE_TASK_REQUEST("&bUpdate task scheduled.", true), + UPDATE_TASK_COMPLETE("&aUpdate task finished.", true), INFO( "{PREFIX}&2Running &bLuckPerms v{0}&2 by &bLuck&2." + "\n" + "{PREFIX}&f-> &3Platform: &f{1}" + "\n" + diff --git a/common/src/main/java/me/lucko/luckperms/common/runnables/ExpireTemporaryTask.java b/common/src/main/java/me/lucko/luckperms/common/runnables/ExpireTemporaryTask.java index 3d31a577..5a5ee158 100644 --- a/common/src/main/java/me/lucko/luckperms/common/runnables/ExpireTemporaryTask.java +++ b/common/src/main/java/me/lucko/luckperms/common/runnables/ExpireTemporaryTask.java @@ -36,16 +36,16 @@ public class ExpireTemporaryTask implements Runnable { boolean groupChanges = false; for (Group group : plugin.getGroupManager().getAll().values()) { if (group.auditTemporaryPermissions()) { - plugin.getDatastore().saveGroup(group); + plugin.getDatastore().saveGroup(group).getOrDefault(false); groupChanges = true; } } for (User user : plugin.getUserManager().getAll().values()) { if (user.auditTemporaryPermissions()) { - plugin.getDatastore().saveUser(user); + plugin.getDatastore().saveUser(user).getOrDefault(false); if (!groupChanges) { - user.refreshPermissions(); + user.getRefreshBuffer().request(); } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/runnables/UpdateTask.java b/common/src/main/java/me/lucko/luckperms/common/runnables/UpdateTask.java index 2842e18d..4f87eef7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/runnables/UpdateTask.java +++ b/common/src/main/java/me/lucko/luckperms/common/runnables/UpdateTask.java @@ -41,14 +41,14 @@ public class UpdateTask implements Runnable { if (event.isCancelled()) return; // Reload all groups - plugin.getDatastore().loadAllGroups(); + plugin.getDatastore().loadAllGroups().getOrDefault(false); String defaultGroup = plugin.getConfiguration().getDefaultGroupName(); if (!plugin.getGroupManager().isLoaded(defaultGroup)) { - plugin.getDatastore().createAndLoadGroup(defaultGroup); + plugin.getDatastore().createAndLoadGroup(defaultGroup).getOrDefault(false); } // Reload all tracks - plugin.getDatastore().loadAllTracks(); + plugin.getDatastore().loadAllTracks().getOrDefault(false); // Refresh all online users. plugin.getUserManager().updateAllUsers(); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputDatastore.java b/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputDatastore.java index 8771c315..5d331e50 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/BufferedOutputDatastore.java @@ -25,8 +25,7 @@ package me.lucko.luckperms.common.storage; import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; -import me.lucko.luckperms.api.LogEntry; -import me.lucko.luckperms.common.data.Log; +import lombok.experimental.Delegate; import me.lucko.luckperms.common.groups.Group; import me.lucko.luckperms.common.tracks.Track; import me.lucko.luckperms.common.users.User; @@ -34,7 +33,6 @@ import me.lucko.luckperms.common.users.UserIdentifier; import me.lucko.luckperms.common.utils.Buffer; import me.lucko.luckperms.common.utils.LPFuture; -import java.util.Set; import java.util.UUID; @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @@ -44,42 +42,36 @@ public class BufferedOutputDatastore implements Datastore, Runnable { } @Getter + @Delegate(excludes = Exclude.class) private final Datastore backing; private final long flushTime; - private final Buffer logOutputBuffer = new Buffer() { - @Override - public Boolean dequeue(LogEntry logEntry) { - return backing.logAction(logEntry).getOrDefault(false); - } - }; - private final Buffer userOutputBuffer = new Buffer() { @Override public Boolean dequeue(User user) { - return saveUser(user).getOrDefault(false); + return backing.saveUser(user).getOrDefault(false); } }; private final Buffer groupOutputBuffer = new Buffer() { @Override public Boolean dequeue(Group group) { - return saveGroup(group).getOrDefault(false); + return backing.saveGroup(group).getOrDefault(false); } }; private final Buffer trackOutputBuffer = new Buffer() { @Override public Boolean dequeue(Track track) { - return saveTrack(track).getOrDefault(false); + return backing.saveTrack(track).getOrDefault(false); } }; private final Buffer uuidDataOutputBuffer = new Buffer() { @Override protected Boolean dequeue(UserIdentifier userIdentifier) { - return saveUUIDData(userIdentifier.getUsername(), userIdentifier.getUuid()).getOrDefault(false); + return backing.saveUUIDData(userIdentifier.getUsername(), userIdentifier.getUuid()).getOrDefault(false); } }; @@ -93,7 +85,6 @@ public class BufferedOutputDatastore implements Datastore, Runnable { } public void flush(long flushTime) { - logOutputBuffer.flush(flushTime); userOutputBuffer.flush(flushTime); groupOutputBuffer.flush(flushTime); trackOutputBuffer.flush(flushTime); @@ -104,134 +95,38 @@ public class BufferedOutputDatastore implements Datastore, Runnable { return backing; } - @Override - public LPFuture init() { - return backing.init(); - } - @Override public LPFuture shutdown() { forceFlush(); return backing.shutdown(); } - @Override - public LPFuture logAction(LogEntry entry) { - return logOutputBuffer.enqueue(entry); - } - - @Override - public LPFuture getLog() { - return backing.getLog(); - } - - @Override - public LPFuture loadUser(UUID uuid, String username) { - return backing.loadUser(uuid, username); - } - @Override public LPFuture saveUser(User user) { return userOutputBuffer.enqueue(user); } - @Override - public LPFuture cleanupUsers() { - return backing.cleanupUsers(); - } - - @Override - public LPFuture> getUniqueUsers() { - return backing.getUniqueUsers(); - } - - @Override - public LPFuture createAndLoadGroup(String name) { - return backing.createAndLoadGroup(name); - } - - @Override - public LPFuture loadGroup(String name) { - return backing.loadGroup(name); - } - - @Override - public LPFuture loadAllGroups() { - return backing.loadAllGroups(); - } - @Override public LPFuture saveGroup(Group group) { return groupOutputBuffer.enqueue(group); } - @Override - public LPFuture deleteGroup(Group group) { - return backing.deleteGroup(group); - } - - @Override - public LPFuture createAndLoadTrack(String name) { - return backing.createAndLoadTrack(name); - } - - @Override - public LPFuture loadTrack(String name) { - return backing.loadTrack(name); - } - - @Override - public LPFuture loadAllTracks() { - return backing.loadAllTracks(); - } - @Override public LPFuture saveTrack(Track track) { return trackOutputBuffer.enqueue(track); } - @Override - public LPFuture deleteTrack(Track track) { - return backing.deleteTrack(track); - } - @Override public LPFuture saveUUIDData(String username, UUID uuid) { return uuidDataOutputBuffer.enqueue(UserIdentifier.of(uuid, username)); } - @Override - public LPFuture getUUID(String username) { - return backing.getUUID(username); - } - - @Override - public LPFuture getName(UUID uuid) { - return backing.getName(uuid); - } - - @Override - public String getName() { - return backing.getName(); - } - - @Override - public boolean isAcceptingLogins() { - return backing.isAcceptingLogins(); - } - - @Override - public void setAcceptingLogins(boolean acceptingLogins) { - backing.setAcceptingLogins(acceptingLogins); - } - - @Override - public void doAsync(Runnable r) { - backing.doAsync(r); - } - - @Override - public void doSync(Runnable r) { - backing.doSync(r); + private interface Exclude { + Datastore force(); + LPFuture shutdown(); + LPFuture saveUser(User user); + LPFuture saveGroup(Group group); + LPFuture saveTrack(Track track); + LPFuture saveUUIDData(String username, UUID uuid); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java index b97539ff..4f708be7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java @@ -84,8 +84,8 @@ public class StorageFactory { private static Datastore fromString(String storageMethod, LuckPermsPlugin plugin) { switch (storageMethod) { case "mysql": - BufferedOutputDatastore bod = BufferedOutputDatastore.wrap(AbstractDatastore.wrap(new MySQLBacking(plugin, plugin.getConfiguration().getDatabaseValues())), 5000L); - plugin.doAsyncRepeating(bod, 20L); + BufferedOutputDatastore bod = BufferedOutputDatastore.wrap(AbstractDatastore.wrap(new MySQLBacking(plugin, plugin.getConfiguration().getDatabaseValues())), 3000L); + plugin.doAsyncRepeating(bod, 10L); return bod; case "sqlite": return AbstractDatastore.wrap(new SQLiteBacking(plugin, new File(plugin.getDataFolder(), "luckperms.sqlite"))); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/TolerantDatastore.java b/common/src/main/java/me/lucko/luckperms/common/storage/TolerantDatastore.java index 48041e0b..974a684a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/TolerantDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/TolerantDatastore.java @@ -34,6 +34,8 @@ import me.lucko.luckperms.common.utils.LPFuture; import java.util.Set; import java.util.UUID; import java.util.concurrent.Phaser; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; /** * A Datastore wrapping that ensures all tasks are completed before {@link Datastore#shutdown()} is called. @@ -84,8 +86,12 @@ public class TolerantDatastore implements Datastore { @Override public LPFuture shutdown() { - phaser.register(); // Register self - phaser.arriveAndAwaitAdvance(); // Wait for other threads to finish. + // Wait for other threads to finish. + try { + phaser.awaitAdvanceInterruptibly(phaser.getPhase(), 5, TimeUnit.SECONDS); + } catch (InterruptedException | TimeoutException e) { + e.printStackTrace(); + } return backing.shutdown(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java index 0def4cf0..430ae397 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java @@ -140,7 +140,7 @@ public class JSONBacking extends FlatfileBacking { }, false); } finally { user.getIoLock().unlock(); - user.refreshPermissions(); + user.getRefreshBuffer().requestDirectly(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java index a1d8646d..a094fe17 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java @@ -178,7 +178,7 @@ public class MongoDBBacking extends AbstractBacking { }, false); } finally { user.getIoLock().unlock(); - user.refreshPermissions(); + user.getRefreshBuffer().requestDirectly(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java index d39813bb..7a385d7b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java @@ -184,7 +184,7 @@ abstract class SQLBacking extends AbstractBacking { ); } finally { user.getIoLock().unlock(); - user.refreshPermissions(); + user.getRefreshBuffer().requestDirectly(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java index 9fe23292..319caa76 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java @@ -126,7 +126,7 @@ public class YAMLBacking extends FlatfileBacking { }, false); } finally { user.getIoLock().unlock(); - user.refreshPermissions(); + user.getRefreshBuffer().requestDirectly(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/users/User.java b/common/src/main/java/me/lucko/luckperms/common/users/User.java index 5614a652..4cb7b5f1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/users/User.java +++ b/common/src/main/java/me/lucko/luckperms/common/users/User.java @@ -31,6 +31,7 @@ import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.api.internal.UserLink; import me.lucko.luckperms.common.caching.UserData; import me.lucko.luckperms.common.core.PermissionHolder; +import me.lucko.luckperms.common.utils.BufferedRequest; import me.lucko.luckperms.common.utils.Identifiable; import java.util.UUID; @@ -62,6 +63,15 @@ public class User extends PermissionHolder implements Identifiable refreshBuffer = new BufferedRequest(1000L, r -> getPlugin().doAsync(r)) { + @Override + protected Void perform() { + refreshPermissions(); + return null; + } + }; + protected User(UUID uuid, LuckPermsPlugin plugin) { super(uuid.toString(), plugin); this.uuid = uuid; @@ -111,7 +121,7 @@ public class User extends PermissionHolder implements Identifiable { plugin.doAsync(() -> { for (UUID uuid : players) { UUID internal = plugin.getUuidCache().getUUID(uuid); - plugin.getDatastore().loadUser(internal, "null"); + plugin.getDatastore().loadUser(internal, "null").getOrDefault(false); User user = get(internal); - user.refreshPermissions(); + user.getRefreshBuffer().request(); } }); }); diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java b/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java index 6182f172..f63f46b1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java @@ -41,14 +41,14 @@ public class AbstractListener { final UuidCache cache = plugin.getUuidCache(); if (!cache.isOnlineMode()) { - UUID uuid = plugin.getDatastore().getUUID(username).getOrDefault(null); + UUID uuid = plugin.getDatastore().force().getUUID(username).getOrDefault(null); if (uuid != null) { cache.addToCache(u, uuid); } else { // No previous data for this player plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(u, username)); cache.addToCache(u, u); - plugin.getDatastore().saveUUIDData(username, u, Callback.empty()); + plugin.getDatastore().force().saveUUIDData(username, u, Callback.empty()); } } else { UUID uuid = plugin.getDatastore().getUUID(username).getOrDefault(null); @@ -57,10 +57,10 @@ public class AbstractListener { } // Online mode, no cache needed. This is just for name -> uuid lookup. - plugin.getDatastore().saveUUIDData(username, u, Callback.empty()); + plugin.getDatastore().force().saveUUIDData(username, u, Callback.empty()); } - plugin.getDatastore().loadUser(cache.getUUID(u), username); + plugin.getDatastore().force().loadUser(cache.getUUID(u), username).getOrDefault(false); User user = plugin.getUserManager().get(cache.getUUID(u)); if (user == null) { plugin.getLog().warn("Failed to load user: " + username); @@ -75,7 +75,7 @@ public class AbstractListener { // If they were given a default, persist the new assignments back to the storage. if (save) { - plugin.getDatastore().saveUser(user); + plugin.getDatastore().force().saveUser(user).getOrDefault(false); } user.setupData(false); // Pretty nasty calculation call. Sets up the caching system so data is ready when the user joins. @@ -103,7 +103,7 @@ public class AbstractListener { protected void refreshPlayer(UUID uuid) { final User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(uuid)); if (user != null) { - user.refreshPermissions(); + user.getRefreshBuffer().requestDirectly(); } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java b/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java index 5f58f641..9fb223da 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java @@ -27,7 +27,6 @@ import lombok.RequiredArgsConstructor; import me.lucko.luckperms.common.storage.AbstractFuture; import java.lang.ref.WeakReference; -import java.util.concurrent.Future; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; import java.util.function.Supplier; @@ -42,7 +41,7 @@ public abstract class BufferedRequest { @Getter private ReentrantLock lock = new ReentrantLock(); - public Future request() { + public LPFuture request() { lock.lock(); try { if (processor != null) { @@ -62,6 +61,10 @@ public abstract class BufferedRequest { } } + public T requestDirectly() { + return perform(); + } + protected abstract T perform(); @@ -109,11 +112,11 @@ public abstract class BufferedRequest { future.complete(result); } - public Future get() { + public LPFuture get() { return future; } - public Future getAndExtend() { + public LPFuture getAndExtend() { lock.lock(); try { executionTime = System.currentTimeMillis() + delayMillis; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index c1676d3a..8ea18400 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -46,6 +46,7 @@ import me.lucko.luckperms.common.storage.Datastore; import me.lucko.luckperms.common.storage.StorageFactory; import me.lucko.luckperms.common.tracks.TrackManager; import me.lucko.luckperms.common.users.UserManager; +import me.lucko.luckperms.common.utils.BufferedRequest; import me.lucko.luckperms.common.utils.LocaleManager; import me.lucko.luckperms.common.utils.LogFactory; import me.lucko.luckperms.sponge.contexts.WorldCalculator; @@ -106,6 +107,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { private LocaleManager localeManager; private ContextManager contextManager; private CalculatorFactory calculatorFactory; + private BufferedRequest updateTaskBuffer; @Listener public void onEnable(GamePreInitializationEvent event) { @@ -157,13 +159,22 @@ public class LPSpongePlugin implements LuckPermsPlugin { ApiHandler.registerProvider(apiProvider); Sponge.getServiceManager().setProvider(this, LuckPermsApi.class, apiProvider); + final LPSpongePlugin i = this; + updateTaskBuffer = new BufferedRequest(6000L, this::doAsync) { + @Override + protected Void perform() { + scheduler.createTaskBuilder().async().execute(new UpdateTask(i)).submit(i); + return null; + } + }; + int mins = getConfiguration().getSyncTime(); if (mins > 0) { scheduler.createTaskBuilder().async().interval(mins, TimeUnit.MINUTES).execute(new UpdateTask(this)) .submit(LPSpongePlugin.this); } else { // Update online users - runUpdateTask(); + updateTaskBuffer.request(); } scheduler.createTaskBuilder().intervalTicks(1L).execute(SpongeSenderFactory.get(this)).submit(this); @@ -292,11 +303,6 @@ public class LPSpongePlugin implements LuckPermsPlugin { return game.getPluginManager().isLoaded(name); } - @Override - public void runUpdateTask() { - scheduler.createTaskBuilder().async().execute(new UpdateTask(this)).submit(this); - } - @Override public void doAsync(Runnable r) { scheduler.createTaskBuilder().async().execute(r).submit(this); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java index 15a92b75..30cbc916 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java @@ -52,16 +52,12 @@ public class LuckPermsSubjectData implements SubjectData { private final PermissionHolder holder; private void objectSave(PermissionHolder t) { - service.getPlugin().doAsync(() -> { - if (t instanceof User) { - ((User) t).refreshPermissions(); - service.getPlugin().getDatastore().saveUser(((User) t)); - } - if (t instanceof Group) { - service.getPlugin().getDatastore().saveGroup(((Group) t)); - service.getPlugin().runUpdateTask(); - } - }); + if (t instanceof User) { + service.getPlugin().getDatastore().saveUser(((User) t), b -> ((User) t).getRefreshBuffer().request()); + } + if (t instanceof Group) { + service.getPlugin().getDatastore().saveGroup(((Group) t), b -> service.getPlugin().getUpdateTaskBuffer().request()); + } } @Override