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 4fecf952..9df16e07 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -60,6 +60,7 @@ import me.lucko.luckperms.common.managers.impl.GenericGroupManager; import me.lucko.luckperms.common.managers.impl.GenericTrackManager; import me.lucko.luckperms.common.managers.impl.GenericUserManager; import me.lucko.luckperms.common.messaging.InternalMessagingService; +import me.lucko.luckperms.common.messaging.NoopMessagingService; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.storage.Storage; @@ -217,6 +218,10 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { getLog().warn("Messaging service '" + messagingType + "' not recognised."); } + if (messagingService == null) { + messagingService = new NoopMessagingService(); + } + // setup the update task buffer updateTaskBuffer = new BufferedRequest(1000L, this::doAsync) { @Override diff --git a/bukkit/src/main/resources/config.yml b/bukkit/src/main/resources/config.yml index 41c88811..abe8385c 100644 --- a/bukkit/src/main/resources/config.yml +++ b/bukkit/src/main/resources/config.yml @@ -258,6 +258,9 @@ data: # none ==> nothing messaging-service: none +# If LuckPerms should automatically push updates after a change has been made with a command. +auto-push-updates: true + # Settings for Redis. # Port 6379 is used by default; set address to "host:port" if differs redis: 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 ab7c76fc..c6eb92d7 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -52,6 +52,7 @@ import me.lucko.luckperms.common.managers.impl.GenericGroupManager; import me.lucko.luckperms.common.managers.impl.GenericTrackManager; import me.lucko.luckperms.common.managers.impl.GenericUserManager; import me.lucko.luckperms.common.messaging.InternalMessagingService; +import me.lucko.luckperms.common.messaging.NoopMessagingService; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsScheduler; @@ -162,6 +163,10 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { getLog().warn("Messaging service '" + messagingType + "' not recognised."); } + if (messagingService == null) { + messagingService = new NoopMessagingService(); + } + // setup the update task buffer updateTaskBuffer = new BufferedRequest(1000L, this::doAsync) { @Override diff --git a/bungee/src/main/resources/config.yml b/bungee/src/main/resources/config.yml index b65cfeef..dd8d7925 100644 --- a/bungee/src/main/resources/config.yml +++ b/bungee/src/main/resources/config.yml @@ -199,6 +199,9 @@ data: # none ==> nothing messaging-service: none +# If LuckPerms should automatically push updates after a change has been made with a command. +auto-push-updates: true + # Settings for Redis. # Port 6379 is used by default; set address to "host:port" if differs redis: 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 f62fd8a5..0746445a 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 @@ -46,6 +46,8 @@ import me.lucko.luckperms.common.core.NodeBuilder; import me.lucko.luckperms.common.core.UserIdentifier; import me.lucko.luckperms.common.event.EventFactory; import me.lucko.luckperms.common.event.LuckPermsEventBus; +import me.lucko.luckperms.common.messaging.InternalMessagingService; +import me.lucko.luckperms.common.messaging.NoopMessagingService; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import java.util.Optional; @@ -103,7 +105,8 @@ public class ApiProvider implements LuckPermsApi { @Override public Optional getMessagingService() { - return Optional.ofNullable(plugin.getMessagingService()); + InternalMessagingService service = plugin.getMessagingService(); + return service instanceof NoopMessagingService ? Optional.empty() : Optional.of(service); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SubCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SubCommand.java index d6b909d3..f5924463 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SubCommand.java @@ -29,11 +29,14 @@ import com.google.common.base.Splitter; import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; +import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.core.model.User; +import me.lucko.luckperms.common.messaging.InternalMessagingService; +import me.lucko.luckperms.common.messaging.NoopMessagingService; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.treeview.PermissionVault; import me.lucko.luckperms.common.treeview.TreeNode; @@ -174,6 +177,11 @@ public abstract class SubCommand extends Command { user.getRefreshBuffer().requestDirectly(); } + InternalMessagingService messagingService = plugin.getMessagingService(); + if (!sender.isImport() && !(messagingService instanceof NoopMessagingService) && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) { + messagingService.getUpdateBuffer().request(); + } + if (success) { Message.USER_SAVE_SUCCESS.send(sender); } else { @@ -190,6 +198,11 @@ public abstract class SubCommand extends Command { plugin.getUpdateTaskBuffer().requestDirectly(); } + InternalMessagingService messagingService = plugin.getMessagingService(); + if (!sender.isImport() && !(messagingService instanceof NoopMessagingService) && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) { + messagingService.getUpdateBuffer().request(); + } + if (success) { Message.GROUP_SAVE_SUCCESS.send(sender); } else { @@ -206,6 +219,11 @@ public abstract class SubCommand extends Command { plugin.getUpdateTaskBuffer().requestDirectly(); } + InternalMessagingService messagingService = plugin.getMessagingService(); + if (!sender.isImport() && !(messagingService instanceof NoopMessagingService) && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) { + messagingService.getUpdateBuffer().request(); + } + if (success) { Message.TRACK_SAVE_SUCCESS.send(sender); } else { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java index d6a67156..4805c071 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java @@ -30,6 +30,7 @@ import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.config.LuckPermsConfiguration; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; +import me.lucko.luckperms.common.messaging.NoopMessagingService; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.utils.Predicates; @@ -66,7 +67,7 @@ public class InfoCommand extends SingleCommand { plugin.getStorage().getName(), c.get(ConfigKeys.SERVER), c.get(ConfigKeys.SYNC_TIME), - plugin.getMessagingService() == null ? "None" : plugin.getMessagingService().getName(), + plugin.getMessagingService() instanceof NoopMessagingService ? "None" : plugin.getMessagingService().getName(), plugin.getPlayerCount(), plugin.getUserManager().getAll().size(), plugin.getGroupManager().getAll().size(), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/NetworkSyncCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/NetworkSyncCommand.java index bf228340..753b1578 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/NetworkSyncCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/NetworkSyncCommand.java @@ -28,6 +28,7 @@ import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.messaging.InternalMessagingService; +import me.lucko.luckperms.common.messaging.NoopMessagingService; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.utils.Predicates; @@ -47,7 +48,7 @@ public class NetworkSyncCommand extends SingleCommand { InternalMessagingService messagingService = plugin.getMessagingService(); - if (messagingService == null) { + if (messagingService instanceof NoopMessagingService) { Message.UPDATE_TASK_PUSH_FAILURE_NOT_SETUP.send(sender); return CommandResult.FAILURE; } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java index 37c619d1..ccd82b79 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java @@ -180,6 +180,7 @@ public class ConfigKeys { .build(); })); public static final ConfigKey MESSAGING_SERVICE = EnduringKey.wrap(StringKey.of("messaging-service", "none")); + public static final ConfigKey AUTO_PUSH_UPDATES = EnduringKey.wrap(BooleanKey.of("auto-push-updates", true)); public static final ConfigKey REDIS_ENABLED = EnduringKey.wrap(BooleanKey.of("redis.enabled", false)); public static final ConfigKey REDIS_ADDRESS = EnduringKey.wrap(StringKey.of("redis.address", null)); public static final ConfigKey REDIS_PASSWORD = EnduringKey.wrap(StringKey.of("redis.password", "")); diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/AbstractMessagingService.java b/common/src/main/java/me/lucko/luckperms/common/messaging/AbstractMessagingService.java index e0755bbe..b715d368 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/AbstractMessagingService.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/AbstractMessagingService.java @@ -26,6 +26,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; +import me.lucko.luckperms.common.utils.BufferedRequest; import java.util.Collections; import java.util.HashSet; @@ -40,6 +41,7 @@ import java.util.function.Consumer; public abstract class AbstractMessagingService implements InternalMessagingService { public static final String CHANNEL = "lpuc"; + @Getter private final LuckPermsPlugin plugin; @Getter @@ -47,6 +49,15 @@ public abstract class AbstractMessagingService implements InternalMessagingServi private final Set receivedMsgs = Collections.synchronizedSet(new HashSet<>()); + @Getter + private final BufferedRequest updateBuffer = new BufferedRequest(10000L, r -> getPlugin().doAsync(r)) { + @Override + protected Void perform() { + pushUpdate(); + return null; + } + }; + protected abstract void sendMessage(String channel, String message); protected void onMessage(String channel, String msg, Consumer callback) { diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/InternalMessagingService.java b/common/src/main/java/me/lucko/luckperms/common/messaging/InternalMessagingService.java index 85bc797c..a32c2850 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/InternalMessagingService.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/InternalMessagingService.java @@ -23,10 +23,27 @@ package me.lucko.luckperms.common.messaging; import me.lucko.luckperms.api.MessagingService; +import me.lucko.luckperms.common.utils.BufferedRequest; public interface InternalMessagingService extends MessagingService { + /** + * Gets the name of this messaging service + * + * @return the name of this messaging service + */ String getName(); + + /** + * Closes the messaging service + */ void close(); + /** + * Gets the buffer for sending updates to other servers + * + * @return the update buffer + */ + BufferedRequest getUpdateBuffer(); + } diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/NoopMessagingService.java b/common/src/main/java/me/lucko/luckperms/common/messaging/NoopMessagingService.java new file mode 100644 index 00000000..fd3f382c --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/NoopMessagingService.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.common.messaging; + +import me.lucko.luckperms.common.utils.BufferedRequest; + +public class NoopMessagingService implements InternalMessagingService { + + @Override + public String getName() { + return "No op"; + } + + @Override + public void close() { + + } + + @Override + public BufferedRequest getUpdateBuffer() { + return null; + } + + @Override + public void pushUpdate() { + + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java index 42616d46..5e6fb09e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java @@ -100,7 +100,7 @@ public interface LuckPermsPlugin { Storage getStorage(); /** - * Gets the redis messaging instance if present. Could return null if redis is not enabled. + * Gets the redis messaging instance. * * @return the redis messaging service */ 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 2add8732..e1be359a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -49,6 +49,7 @@ import me.lucko.luckperms.common.locale.SimpleLocaleManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.impl.GenericTrackManager; import me.lucko.luckperms.common.messaging.InternalMessagingService; +import me.lucko.luckperms.common.messaging.NoopMessagingService; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsScheduler; @@ -222,6 +223,10 @@ public class LPSpongePlugin implements LuckPermsPlugin { getLog().warn("Messaging service '" + messagingType + "' not recognised."); } + if (messagingService == null) { + messagingService = new NoopMessagingService(); + } + // setup the update task buffer updateTaskBuffer = new BufferedRequest(1000L, this::doAsync) { @Override diff --git a/sponge/src/main/resources/luckperms.conf b/sponge/src/main/resources/luckperms.conf index 25483506..996f2b6f 100644 --- a/sponge/src/main/resources/luckperms.conf +++ b/sponge/src/main/resources/luckperms.conf @@ -209,6 +209,9 @@ data { # none ==> nothing messaging-service="none" +# If LuckPerms should automatically push updates after a change has been made with a command. +auto-push-updates=true + # Settings for Redis. # Port 6379 is used by default; set address to "host:port" if differs redis {