diff --git a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java
index 3d97be97..a8fe6d6d 100644
--- a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java
+++ b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java
@@ -33,6 +33,7 @@ import me.lucko.luckperms.api.event.EventBus;
import me.lucko.luckperms.api.manager.GroupManager;
import me.lucko.luckperms.api.manager.TrackManager;
import me.lucko.luckperms.api.manager.UserManager;
+import me.lucko.luckperms.api.messenger.MessengerProvider;
import me.lucko.luckperms.api.metastacking.MetaStackFactory;
import me.lucko.luckperms.api.platform.PlatformInfo;
@@ -172,6 +173,17 @@ public interface LuckPermsApi {
@Nonnull
Optional Note that the mere action of registering a provider doesn't
+ * necessarily mean that it will be used. The standard response by other servers will be to execute a overall
+ * sync of all live data, equivalent to calling
+ * {@link LuckPermsApi#runUpdateTask()}. This will push the update asynchronously, and this method will return
- * immediately. Calling this method is equivalent to running "/lp networksync",
- * except will not sync this server.
The standard response by other servers is undefined, however the + * current implementation will reload the corresponding users data if they + * are online.
+ * + *This will push the update asynchronously, and this method will return + * immediately. Note that this method will not cause an update to be + * processed on the local server.
+ * + * @param user the user to push the update for + * @since 4.1 + */ + void pushUserUpdate(@Nonnull User user); + } diff --git a/api/src/main/java/me/lucko/luckperms/api/messenger/IncomingMessageConsumer.java b/api/src/main/java/me/lucko/luckperms/api/messenger/IncomingMessageConsumer.java new file mode 100644 index 00000000..5de6f04d --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/messenger/IncomingMessageConsumer.java @@ -0,0 +1,78 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck)The boolean returned from this method indicates whether or not the + * platform accepted the message. Some implementations which have multiple + * distribution channels may wish to use this result to dispatch the same + * message back to additional receivers.
+ * + *The implementation will usually return false
if a message
+ * with the same ping id has already been processed.
This method will decode strings obtained by calling + * {@link OutgoingMessage#asEncodedString()}. This means that basic + * implementations can successfully implement {@link Messenger} without + * providing their own serialisation.
+ * + *The boolean returned from this method indicates whether or not the + * platform accepted the message. Some implementations which have multiple + * distribution channels may wish to use this result to dispatch the same + * message back to additional receivers.
+ * + *The implementation will usually return false
if a message
+ * with the same ping id has already been processed.
The outgoing message instance is guaranteed to be an instance of one + * of the interfaces extending {@link Message} in the + * 'api.messenger.message.type' package.
+ * + *This call is always made async.
+ * + * @param outgoingMessage the outgoing message + */ + void sendOutgoingMessage(@Nonnull OutgoingMessage outgoingMessage); + + @Override + default void close() { + + } +} diff --git a/api/src/main/java/me/lucko/luckperms/api/messenger/MessengerProvider.java b/api/src/main/java/me/lucko/luckperms/api/messenger/MessengerProvider.java new file mode 100644 index 00000000..97669c83 --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/messenger/MessengerProvider.java @@ -0,0 +1,65 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck)Users wishing to provide their own implementation for the plugins + * "Messaging Service" should implement and register this interface.
+ * + * @since 4.1 + * @see LuckPermsApi#registerMessengerProvider(MessengerProvider) + */ +public interface MessengerProvider { + + /** + * Gets the name of this provider. + * + * @return the provider name + */ + @Nonnull + String getName(); + + /** + * Creates and returns a new {@link Messenger} instance, which passes + * incoming messages to the provided {@link IncomingMessageConsumer}. + * + *As the agent should pass incoming messages to the given consumer, + * this method should always return a new object.
+ * + * @param incomingMessageConsumer the consumer the new instance should pass + * incoming messages to + * @return a new messenger agent instance + */ + @Nonnull + Messenger obtain(@Nonnull IncomingMessageConsumer incomingMessageConsumer); + +} diff --git a/api/src/main/java/me/lucko/luckperms/api/messenger/message/Message.java b/api/src/main/java/me/lucko/luckperms/api/messenger/message/Message.java new file mode 100644 index 00000000..55b23b1d --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/messenger/message/Message.java @@ -0,0 +1,52 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck)This ID is used to ensure a single server instance doesn't process + * the same message twice.
+ * + * @return the id of the message + */ + @Nonnull + UUID getId(); + +} diff --git a/api/src/main/java/me/lucko/luckperms/api/messenger/message/OutgoingMessage.java b/api/src/main/java/me/lucko/luckperms/api/messenger/message/OutgoingMessage.java new file mode 100644 index 00000000..86e459b3 --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/messenger/message/OutgoingMessage.java @@ -0,0 +1,62 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck)Outgoing messages are ones which have been generated by this instance. + * (in other words, they are implemented by LuckPerms)
+ * + *Note that all implementations of this interface are guaranteed to be an + * instance of one of the interfaces extending {@link Message} in the + * 'api.messenger.message.type' package.
+ * + * @since 4.1 + */ +public interface OutgoingMessage extends Message { + + /** + * Gets an encoded string form of this message. + * + *The format of this string is likely to change between versions and + * should not be depended on.
+ * + *Implementations which want to use a standard method of serialisation + * can send outgoing messages using the string returned by this method, and + * pass on the message on the "other side" using + * {@link IncomingMessageConsumer#consumeIncomingMessageAsString(String)}.
+ * + * @return an encoded string form of the message + */ + @Nonnull + String asEncodedString(); + +} diff --git a/api/src/main/java/me/lucko/luckperms/api/messenger/message/type/LogMessage.java b/api/src/main/java/me/lucko/luckperms/api/messenger/message/type/LogMessage.java new file mode 100644 index 00000000..8bf93aab --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/messenger/message/type/LogMessage.java @@ -0,0 +1,50 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck)Used to dispatch live log updates to other servers.
+ * + * @since 4.1 + */ +public interface LogMessage extends Message { + + /** + * Gets the log entry being sent + * + * @return the log entry + */ + @Nonnull + LogEntry getLogEntry(); + +} diff --git a/api/src/main/java/me/lucko/luckperms/api/messenger/message/type/UpdateMessage.java b/api/src/main/java/me/lucko/luckperms/api/messenger/message/type/UpdateMessage.java new file mode 100644 index 00000000..e78ed5ab --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/messenger/message/type/UpdateMessage.java @@ -0,0 +1,39 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck)Used to notify other servers of general changes.
+ * + * @since 4.1 + */ +public interface UpdateMessage extends Message { + +} diff --git a/api/src/main/java/me/lucko/luckperms/api/messenger/message/type/UserUpdateMessage.java b/api/src/main/java/me/lucko/luckperms/api/messenger/message/type/UserUpdateMessage.java new file mode 100644 index 00000000..7d8656d0 --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/messenger/message/type/UserUpdateMessage.java @@ -0,0 +1,51 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck)Used to notify other servers of a change to a specific user.
+ * + * @since 4.1 + */ +public interface UserUpdateMessage extends Message { + + /** + * Gets the user the message is for. + * + * @return the user + */ + @Nonnull + UUID getUser(); + +} 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 ca752f08..6abb8b20 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -69,7 +69,7 @@ import me.lucko.luckperms.common.logging.SenderLogger; import me.lucko.luckperms.common.managers.group.StandardGroupManager; import me.lucko.luckperms.common.managers.track.StandardTrackManager; import me.lucko.luckperms.common.managers.user.StandardUserManager; -import me.lucko.luckperms.common.messaging.ExtendedMessagingService; +import me.lucko.luckperms.common.messaging.InternalMessagingService; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.storage.Storage; @@ -119,7 +119,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { private StandardTrackManager trackManager; private Storage storage; private FileWatcher fileWatcher = null; - private ExtendedMessagingService messagingService = null; + private InternalMessagingService messagingService = null; private UuidCache uuidCache; private LuckPermsApiProvider apiProvider; private EventFactory eventFactory; @@ -443,10 +443,17 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { } @Override - public Optional{ private final P plugin; @@ -39,7 +45,7 @@ public class MessagingFactory
{ return this.plugin; } - public final ExtendedMessagingService getInstance() { + public final InternalMessagingService getInstance() { String messagingType = this.plugin.getConfiguration().get(ConfigKeys.MESSAGING_SERVICE).toLowerCase(); if (messagingType.equals("none") && this.plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) { messagingType = "redis"; @@ -51,7 +57,7 @@ public class MessagingFactory
{ this.plugin.getLog().info("Loading messaging service... [" + messagingType.toUpperCase() + "]"); - ExtendedMessagingService service = getServiceFor(messagingType); + InternalMessagingService service = getServiceFor(messagingType); if (service != null) { return service; } @@ -60,15 +66,12 @@ public class MessagingFactory
{ return null; } - protected ExtendedMessagingService getServiceFor(String messagingType) { + protected InternalMessagingService getServiceFor(String messagingType) { if (messagingType.equals("redis")) { if (this.plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) { - RedisMessagingService redis = new RedisMessagingService(this.plugin); try { - redis.init(this.plugin.getConfiguration().get(ConfigKeys.REDIS_ADDRESS), this.plugin.getConfiguration().get(ConfigKeys.REDIS_PASSWORD)); - return redis; + return new LuckPermsMessagingService(this.plugin, new RedisMessengerProvider()); } catch (Exception e) { - this.plugin.getLog().warn("Couldn't load redis..."); e.printStackTrace(); } } else { @@ -79,4 +82,21 @@ public class MessagingFactory
{
return null;
}
+ private class RedisMessengerProvider implements MessengerProvider {
+
+ @Nonnull
+ @Override
+ public String getName() {
+ return "Redis";
+ }
+
+ @Nonnull
+ @Override
+ public Messenger obtain(@Nonnull IncomingMessageConsumer incomingMessageConsumer) {
+ RedisMessenger redis = new RedisMessenger(getPlugin(), incomingMessageConsumer);
+ redis.init(getPlugin().getConfiguration().get(ConfigKeys.REDIS_ADDRESS), getPlugin().getConfiguration().get(ConfigKeys.REDIS_PASSWORD));
+ return redis;
+ }
+ }
+
}
diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/message/AbstractMessage.java b/common/src/main/java/me/lucko/luckperms/common/messaging/message/AbstractMessage.java
new file mode 100644
index 00000000..683d7a8d
--- /dev/null
+++ b/common/src/main/java/me/lucko/luckperms/common/messaging/message/AbstractMessage.java
@@ -0,0 +1,48 @@
+/*
+ * This file is part of LuckPerms, licensed under the MIT License.
+ *
+ * Copyright (c) lucko (Luck)