From 424af27a478e9cc7d3462508ae58118e3b597b76 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 29 Jan 2017 11:09:11 +0000 Subject: [PATCH] Change update messages to account for more than just redis messaging --- .../luckperms/bukkit/LPBukkitPlugin.java | 4 +-- .../luckperms/bungee/LPBungeePlugin.java | 4 +-- .../luckperms/common/LuckPermsPlugin.java | 4 +-- .../common/commands/misc/InfoCommand.java | 2 +- .../commands/misc/NetworkSyncCommand.java | 21 ++++++++---- .../luckperms/common/constants/Message.java | 27 ++++++++-------- .../messaging/AbstractMessagingService.java | 8 ++--- .../messaging/InternalMessagingService.java | 32 +++++++++++++++++++ default-lang.yml | 29 +++++++++-------- .../luckperms/sponge/LPSpongePlugin.java | 4 +-- 10 files changed, 89 insertions(+), 46 deletions(-) create mode 100644 common/src/main/java/me/lucko/luckperms/common/messaging/InternalMessagingService.java 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 12ec850a0..87ab4462a 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -64,7 +64,7 @@ import me.lucko.luckperms.common.managers.UserManager; 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.AbstractMessagingService; +import me.lucko.luckperms.common.messaging.InternalMessagingService; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; @@ -117,7 +117,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { private GroupManager groupManager; private TrackManager trackManager; private Storage storage; - private AbstractMessagingService messagingService = null; + private InternalMessagingService messagingService = null; private UuidCache uuidCache; private BukkitListener listener; private ApiProvider apiProvider; 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 96129c610..24e4acc28 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -55,7 +55,7 @@ import me.lucko.luckperms.common.managers.UserManager; 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.AbstractMessagingService; +import me.lucko.luckperms.common.messaging.InternalMessagingService; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; @@ -93,7 +93,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { private GroupManager groupManager; private TrackManager trackManager; private Storage storage; - private AbstractMessagingService messagingService = null; + private InternalMessagingService messagingService = null; private UuidCache uuidCache; private ApiProvider apiProvider; private Logger log; diff --git a/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java index 4d985ca08..0ba9ca570 100644 --- a/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java @@ -42,7 +42,7 @@ import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.managers.GroupManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.UserManager; -import me.lucko.luckperms.common.messaging.AbstractMessagingService; +import me.lucko.luckperms.common.messaging.InternalMessagingService; import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.utils.BufferedRequest; import me.lucko.luckperms.common.utils.PermissionCache; @@ -103,7 +103,7 @@ public interface LuckPermsPlugin { * * @return the redis messaging service */ - AbstractMessagingService getMessagingService(); + InternalMessagingService getMessagingService(); /** * Gets a wrapped logger instance for the platform. diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java index a3d2e3a3c..1f554a9e6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java @@ -67,6 +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.getPlayerCount(), plugin.getUserManager().getAll().size(), plugin.getGroupManager().getAll().size(), @@ -77,7 +78,6 @@ public class InfoCommand extends SingleCommand { plugin.getPreProcessContexts(false).size(), plugin.getContextManager().getCalculatorsSize(), formatBoolean(c.get(ConfigKeys.ONLINE_MODE)), - formatBoolean(c.get(ConfigKeys.REDIS_ENABLED)), formatBoolean(c.get(ConfigKeys.INCLUDING_GLOBAL_PERMS)), formatBoolean(c.get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS)), formatBoolean(c.get(ConfigKeys.APPLYING_GLOBAL_GROUPS)), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java index d527be455..b5b69e7cc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/NetworkSyncCommand.java @@ -28,6 +28,7 @@ import me.lucko.luckperms.common.commands.SingleCommand; 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.utils.Predicates; import java.util.List; @@ -44,13 +45,21 @@ public class NetworkSyncCommand extends SingleCommand { plugin.getUpdateTaskBuffer().request().join(); Message.UPDATE_TASK_COMPLETE_NETWORK.send(sender); - if (plugin.getMessagingService() != null) { - plugin.getMessagingService().pushUpdate(); - Message.UPDATE_TASK_PUSH_SUCCESS.send(sender); - } else { - Message.UPDATE_TASK_PUSH_FAILURE.send(sender); + InternalMessagingService messagingService = plugin.getMessagingService(); + + if (messagingService == null) { + Message.UPDATE_TASK_PUSH_FAILURE_NOT_SETUP.send(sender); + return CommandResult.FAILURE; } - return CommandResult.SUCCESS; + try { + messagingService.pushUpdate(); + Message.UPDATE_TASK_PUSH_SUCCESS.send(sender, messagingService.getName()); + return CommandResult.SUCCESS; + } catch (Exception e) { + e.printStackTrace(); + Message.UPDATE_TASK_PUSH_FAILURE.send(sender); + return CommandResult.FAILURE; + } } } 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 763acd6f5..50dd65180 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 @@ -138,8 +138,9 @@ public enum Message { UPDATE_TASK_REQUEST("&bUpdate task scheduled.", true), UPDATE_TASK_COMPLETE("&aUpdate task finished.", true), UPDATE_TASK_COMPLETE_NETWORK("&aUpdate task finished. Now attempting to push to other servers.", true), - UPDATE_TASK_PUSH_SUCCESS("&aOther servers were notified successfully.", true), - UPDATE_TASK_PUSH_FAILURE("&cError whilst pushing changes to other servers. Is Redis enabled?", true), + UPDATE_TASK_PUSH_SUCCESS("&aOther servers were notified via &b{0} Messaging &asuccessfully.", true), + UPDATE_TASK_PUSH_FAILURE("&cError whilst pushing changes to other servers.", true), + UPDATE_TASK_PUSH_FAILURE_NOT_SETUP("&cError whilst pushing changes to other servers. A messaging service has not been configured.", true), RELOAD_CONFIG_SUCCESS("&aThe configuration file was reloaded. &7(some options will only apply after the server has restarted.)", true), INFO( "{PREFIX}&2Running &bLuckPerms v{0}&2 by &bLuck&2." + "\n" + @@ -147,19 +148,19 @@ public enum Message { "{PREFIX}&f- &3Storage Method: &f{2}" + "\n" + "{PREFIX}&f- &3Server Name: &f{3}" + "\n" + "{PREFIX}&f- &3Sync Interval: &a{4} &fminutes" + "\n" + + "{PREFIX}&f- &3Messaging Service: &f{5}" + "\n" + "{PREFIX}&f- &bCounts:" + "\n" + - "{PREFIX}&f- &3Online Players: &a{5}" + "\n" + - "{PREFIX}&f- &3Loaded Users: &a{6}" + "\n" + - "{PREFIX}&f- &3Loaded Groups: &a{7}" + "\n" + - "{PREFIX}&f- &3Loaded Tracks: &a{8}" + "\n" + - "{PREFIX}&f- &3Log size: &a{9}" + "\n" + - "{PREFIX}&f- &3UUID Cache size: &a{10}" + "\n" + - "{PREFIX}&f- &3Translations loaded: &a{11}" + "\n" + - "{PREFIX}&f- &3Pre-process contexts: &a{12}" + "\n" + - "{PREFIX}&f- &3Context Calculators: &a{13}" + "\n" + + "{PREFIX}&f- &3Online Players: &a{6}" + "\n" + + "{PREFIX}&f- &3Loaded Users: &a{7}" + "\n" + + "{PREFIX}&f- &3Loaded Groups: &a{8}" + "\n" + + "{PREFIX}&f- &3Loaded Tracks: &a{9}" + "\n" + + "{PREFIX}&f- &3Log size: &a{10}" + "\n" + + "{PREFIX}&f- &3UUID Cache size: &a{11}" + "\n" + + "{PREFIX}&f- &3Translations loaded: &a{12}" + "\n" + + "{PREFIX}&f- &3Pre-process contexts: &a{13}" + "\n" + + "{PREFIX}&f- &3Context Calculators: &a{14}" + "\n" + "{PREFIX}&f- &bConfiguration:" + "\n" + - "{PREFIX}&f- &3Online Mode: {14}" + "\n" + - "{PREFIX}&f- &3Redis Enabled: {15}" + "\n" + + "{PREFIX}&f- &3Online Mode: {15}" + "\n" + "{PREFIX}&f- &bPermission Calculation:" + "\n" + "{PREFIX}&f- &3Including Global: {16}" + "\n" + "{PREFIX}&f- &3Including Global World: {17}" + "\n" + 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 ffed1614e..be0a82e3c 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 @@ -22,9 +22,9 @@ package me.lucko.luckperms.common.messaging; +import lombok.Getter; import lombok.RequiredArgsConstructor; -import me.lucko.luckperms.api.MessagingService; import me.lucko.luckperms.common.LuckPermsPlugin; import java.util.Collections; @@ -37,16 +37,16 @@ import java.util.function.Consumer; * An abstract implementation of {@link me.lucko.luckperms.api.MessagingService}. */ @RequiredArgsConstructor -public abstract class AbstractMessagingService implements MessagingService { +public abstract class AbstractMessagingService implements InternalMessagingService { public static final String CHANNEL = "lpuc"; private final LuckPermsPlugin plugin; + + @Getter private final String name; private final Set receivedMsgs = Collections.synchronizedSet(new HashSet<>()); - public abstract void close(); - 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 new file mode 100644 index 000000000..85bc797c5 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/InternalMessagingService.java @@ -0,0 +1,32 @@ +/* + * 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.api.MessagingService; + +public interface InternalMessagingService extends MessagingService { + + String getName(); + void close(); + +} diff --git a/default-lang.yml b/default-lang.yml index c1c17290d..28d042675 100644 --- a/default-lang.yml +++ b/default-lang.yml @@ -96,8 +96,9 @@ track-empty: "The track cannot be used as it is empty or contains only one group update-task-request: "&bUpdate task scheduled." update-task-complete: "&aUpdate task finished." update-task-complete-network: "&aUpdate task finished. Now attempting to push to other servers." -update-task-push-success: "&aOther servers were notified successfully." -update-task-push-failure: "&cError whilst pushing changes to other servers. Is Redis enabled?" +update-task-push-success: "&aOther servers were notified via &b{0} Messaging &asuccessfully." +update-task-push-failure: "&cError whilst pushing changes to other servers." +update-task-push-failure-not-setup: "&cError whilst pushing changes to other servers. A messaging service has not been configured." reload-config-success: "&aThe configuration file was reloaded. &7(some options will only apply after the server has restarted.)" info: > {PREFIX}&2Running &bLuckPerms v{0}&2 by &bLuck&2.\n @@ -105,19 +106,19 @@ info: > {PREFIX}&f- &3Storage Method: &f{2}\n {PREFIX}&f- &3Server Name: &f{3}\n {PREFIX}&f- &3Sync Interval: &a{4} &fminutes\n + {PREFIX}&f- &3Messaging Service: &f{5}\n {PREFIX}&f- &bCounts:\n - {PREFIX}&f- &3Online Players: &a{5}\n - {PREFIX}&f- &3Loaded Users: &a{6}\n - {PREFIX}&f- &3Loaded Groups: &a{7}\n - {PREFIX}&f- &3Loaded Tracks: &a{8}\n - {PREFIX}&f- &3Log size: &a{9}\n - {PREFIX}&f- &3UUID Cache size: &a{10}\n - {PREFIX}&f- &3Translations loaded: &a{11}\n - {PREFIX}&f- &3Pre-process contexts: &a{12}\n - {PREFIX}&f- &3Context Calculators: &a{13}\n + {PREFIX}&f- &3Online Players: &a{6}\n + {PREFIX}&f- &3Loaded Users: &a{7}\n + {PREFIX}&f- &3Loaded Groups: &a{8}\n + {PREFIX}&f- &3Loaded Tracks: &a{9}\n + {PREFIX}&f- &3Log size: &a{10}\n + {PREFIX}&f- &3UUID Cache size: &a{11}\n + {PREFIX}&f- &3Translations loaded: &a{12}\n + {PREFIX}&f- &3Pre-process contexts: &a{13}\n + {PREFIX}&f- &3Context Calculators: &a{14}\n {PREFIX}&f- &bConfiguration:\n - {PREFIX}&f- &3Online Mode: {14}\n - {PREFIX}&f- &3Redis Enabled: {15}\n + {PREFIX}&f- &3Online Mode: {15}\n {PREFIX}&f- &bPermission Calculation:\n {PREFIX}&f- &3Including Global: {16}\n {PREFIX}&f- &3Including Global World: {17}\n @@ -125,7 +126,7 @@ info: > {PREFIX}&f- &3Applying Global World Groups: {19}\n {PREFIX}&f- &3Applying Wildcards: {20}\n {PREFIX}&f- &3Applying Regex: {21}\n - {PREFIX}&f- &3Applying Shorthand: {22}" + {PREFIX}&f- &3Applying Shorthand: {22} create-group-error: "There was an error whilst creating the group." delete-group-error: "There was an error whilst deleting the group." delete-group-error-default: "You cannot delete the default group." 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 554c037fe..b46667c29 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -51,7 +51,7 @@ import me.lucko.luckperms.common.locale.NoopLocaleManager; 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.AbstractMessagingService; +import me.lucko.luckperms.common.messaging.InternalMessagingService; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; @@ -148,7 +148,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { private SpongeGroupManager groupManager; private TrackManager trackManager; private Storage storage; - private AbstractMessagingService messagingService = null; + private InternalMessagingService messagingService = null; private UuidCache uuidCache; private ApiProvider apiProvider; private me.lucko.luckperms.api.Logger log;