Expose a means to implement the plugin's MessagingService via the API
This commit is contained in:
@@ -55,7 +55,7 @@ import me.lucko.luckperms.common.locale.NoopLocaleManager;
|
||||
import me.lucko.luckperms.common.locale.SimpleLocaleManager;
|
||||
import me.lucko.luckperms.common.logging.SenderLogger;
|
||||
import me.lucko.luckperms.common.managers.track.StandardTrackManager;
|
||||
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.SchedulerAdapter;
|
||||
import me.lucko.luckperms.common.storage.Storage;
|
||||
@@ -172,7 +172,7 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
|
||||
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;
|
||||
@@ -370,10 +370,17 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ExtendedMessagingService> getMessagingService() {
|
||||
public Optional<InternalMessagingService> getMessagingService() {
|
||||
return Optional.ofNullable(this.messagingService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMessagingService(InternalMessagingService messagingService) {
|
||||
if (this.messagingService == null) {
|
||||
this.messagingService = messagingService;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<FileWatcher> getFileWatcher() {
|
||||
return Optional.ofNullable(this.fileWatcher);
|
||||
|
||||
+14
-10
@@ -27,8 +27,9 @@ package me.lucko.luckperms.sponge.messaging;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import me.lucko.luckperms.common.messaging.AbstractMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.ExtendedMessagingService;
|
||||
import me.lucko.luckperms.api.messenger.IncomingMessageConsumer;
|
||||
import me.lucko.luckperms.api.messenger.Messenger;
|
||||
import me.lucko.luckperms.api.messenger.message.OutgoingMessage;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
import org.spongepowered.api.Platform;
|
||||
@@ -44,15 +45,19 @@ import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* An implementation of {@link ExtendedMessagingService} using the plugin messaging channels.
|
||||
* An implementation of {@link Messenger} using the plugin messaging channels.
|
||||
*/
|
||||
public class BungeeMessagingService extends AbstractMessagingService implements RawDataListener {
|
||||
public class BungeeMessenger implements Messenger, RawDataListener {
|
||||
private static final String CHANNEL = "lpuc";
|
||||
|
||||
private final LPSpongePlugin plugin;
|
||||
private final IncomingMessageConsumer consumer;
|
||||
|
||||
private ChannelBinding.RawDataChannel channel = null;
|
||||
|
||||
public BungeeMessagingService(LPSpongePlugin plugin) {
|
||||
super(plugin, "Bungee");
|
||||
public BungeeMessenger(LPSpongePlugin plugin, IncomingMessageConsumer consumer) {
|
||||
this.plugin = plugin;
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
@@ -68,7 +73,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(String message) {
|
||||
public void sendOutgoingMessage(@Nonnull OutgoingMessage outgoingMessage) {
|
||||
this.plugin.getSpongeScheduler().createTaskBuilder().interval(10, TimeUnit.SECONDS).execute(task -> {
|
||||
if (!this.plugin.getGame().isServerAvailable()) {
|
||||
return;
|
||||
@@ -80,8 +85,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
return;
|
||||
}
|
||||
|
||||
this.channel.sendTo(p, buf -> buf.writeUTF(message));
|
||||
|
||||
this.channel.sendTo(p, buf -> buf.writeUTF(outgoingMessage.asEncodedString()));
|
||||
task.cancel();
|
||||
}).submit(this.plugin);
|
||||
}
|
||||
@@ -89,6 +93,6 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
@Override
|
||||
public void handlePayload(@Nonnull ChannelBuf buf, @Nonnull RemoteConnection connection, @Nonnull Platform.Type type) {
|
||||
String msg = buf.readUTF();
|
||||
onMessage(msg, null);
|
||||
this.consumer.consumeIncomingMessageAsString(msg);
|
||||
}
|
||||
}
|
||||
+31
-5
@@ -25,23 +25,49 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.messaging;
|
||||
|
||||
import me.lucko.luckperms.common.messaging.ExtendedMessagingService;
|
||||
import me.lucko.luckperms.api.messenger.IncomingMessageConsumer;
|
||||
import me.lucko.luckperms.api.messenger.Messenger;
|
||||
import me.lucko.luckperms.api.messenger.MessengerProvider;
|
||||
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.LuckPermsMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.MessagingFactory;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class SpongeMessagingFactory extends MessagingFactory<LPSpongePlugin> {
|
||||
public SpongeMessagingFactory(LPSpongePlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExtendedMessagingService getServiceFor(String messagingType) {
|
||||
protected InternalMessagingService getServiceFor(String messagingType) {
|
||||
if (messagingType.equals("bungee")) {
|
||||
BungeeMessagingService bungeeMessaging = new BungeeMessagingService(getPlugin());
|
||||
bungeeMessaging.init();
|
||||
return bungeeMessaging;
|
||||
try {
|
||||
return new LuckPermsMessagingService(getPlugin(), new BungeeMessengerProvider());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return super.getServiceFor(messagingType);
|
||||
}
|
||||
|
||||
private class BungeeMessengerProvider implements MessengerProvider {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Bungee";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Messenger obtain(@Nonnull IncomingMessageConsumer incomingMessageConsumer) {
|
||||
BungeeMessenger bungeeMessaging = new BungeeMessenger(getPlugin(), incomingMessageConsumer);
|
||||
bungeeMessaging.init();
|
||||
return bungeeMessaging;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user