mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 21:29:47 +01:00
Add RedisBungee messaging service option for BungeeCord
This commit is contained in:
parent
d2bf940105
commit
9e83a5e4d9
@ -65,7 +65,7 @@ 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.messaging.RedisMessagingService;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.storage.Storage;
|
||||
import me.lucko.luckperms.common.storage.StorageFactory;
|
||||
@ -215,7 +215,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
|
||||
if (messagingType.equals("redis")) {
|
||||
if (getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||
RedisMessaging redis = new RedisMessaging(this);
|
||||
RedisMessagingService redis = new RedisMessagingService(this);
|
||||
try {
|
||||
redis.init(getConfiguration().get(ConfigKeys.REDIS_ADDRESS), getConfiguration().get(ConfigKeys.REDIS_PASSWORD));
|
||||
messagingService = redis;
|
||||
|
@ -32,6 +32,7 @@ import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.api.PlatformType;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.bungee.messaging.BungeeMessagingService;
|
||||
import me.lucko.luckperms.bungee.messaging.RedisBungeeMessagingService;
|
||||
import me.lucko.luckperms.bungee.util.RedisBungeeUtil;
|
||||
import me.lucko.luckperms.common.api.ApiHandler;
|
||||
import me.lucko.luckperms.common.api.ApiProvider;
|
||||
@ -58,7 +59,7 @@ 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.messaging.RedisMessagingService;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsScheduler;
|
||||
import me.lucko.luckperms.common.storage.Storage;
|
||||
@ -159,7 +160,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
|
||||
if (messagingType.equals("redis")) {
|
||||
if (getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||
RedisMessaging redis = new RedisMessaging(this);
|
||||
RedisMessagingService redis = new RedisMessagingService(this);
|
||||
try {
|
||||
redis.init(getConfiguration().get(ConfigKeys.REDIS_ADDRESS), getConfiguration().get(ConfigKeys.REDIS_PASSWORD));
|
||||
messagingService = redis;
|
||||
@ -174,6 +175,14 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
BungeeMessagingService bungeeMessaging = new BungeeMessagingService(this);
|
||||
bungeeMessaging.init();
|
||||
messagingService = bungeeMessaging;
|
||||
} else if (messagingType.equals("redisbungee")) {
|
||||
if (getProxy().getPluginManager().getPlugin("RedisBungee") == null) {
|
||||
getLog().warn("RedisBungee plugin not present.");
|
||||
} else {
|
||||
RedisBungeeMessagingService redisBungeeMessaging = new RedisBungeeMessagingService(this);
|
||||
redisBungeeMessaging.init();
|
||||
messagingService = redisBungeeMessaging;
|
||||
}
|
||||
} else if (!messagingType.equals("none")) {
|
||||
getLog().warn("Messaging service '" + messagingType + "' not recognised.");
|
||||
}
|
||||
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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.bungee.messaging;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||
|
||||
import me.lucko.luckperms.bungee.LPBungeePlugin;
|
||||
import me.lucko.luckperms.common.messaging.AbstractMessagingService;
|
||||
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
/**
|
||||
* An implementation of {@link me.lucko.luckperms.api.MessagingService} using Redis, via RedisBungee's API.
|
||||
*/
|
||||
public class RedisBungeeMessagingService extends AbstractMessagingService implements Listener {
|
||||
private final LPBungeePlugin plugin;
|
||||
private RedisBungeeAPI redisBungee;
|
||||
|
||||
public RedisBungeeMessagingService(LPBungeePlugin plugin) {
|
||||
super(plugin, "RedisBungee");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
this.redisBungee = RedisBungee.getApi();
|
||||
redisBungee.registerPubSubChannels(CHANNEL);
|
||||
|
||||
plugin.getProxy().getPluginManager().registerListener(plugin, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
redisBungee.unregisterPubSubChannels(CHANNEL);
|
||||
redisBungee = null;
|
||||
|
||||
plugin.getProxy().getPluginManager().unregisterListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(String channel, String message) {
|
||||
redisBungee.sendChannelMessage(channel, message);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMessage(PubSubMessageEvent e) {
|
||||
onMessage(e.getChannel(), e.getMessage(), null);
|
||||
}
|
||||
}
|
@ -243,9 +243,12 @@ data:
|
||||
# LuckPerms to poll the database for changes.
|
||||
#
|
||||
# Available options:
|
||||
# -> bungee uses the plugin messaging channels. Must be enabled on all connected servers to work.
|
||||
# -> redis uses redis pub sub to push changes. Your redis server must be configured below.
|
||||
# -> none nothing
|
||||
# -> bungee uses the plugin messaging channels. Must be enabled on all connected servers to
|
||||
# work.
|
||||
# -> redis uses redis pub sub to push changes. Your redis server must be configured below.
|
||||
# -> redisbungee uses redis pub sub to push changes, using RedisBungee's API. You need to have the
|
||||
# RedisBungee plugin installed.
|
||||
# -> none nothing
|
||||
messaging-service: none
|
||||
|
||||
# If LuckPerms should automatically push updates after a change has been made with a command.
|
||||
|
@ -37,12 +37,12 @@ import redis.clients.jedis.shaded.JedisPubSub;
|
||||
/**
|
||||
* An implementation of {@link me.lucko.luckperms.api.MessagingService} using Redis.
|
||||
*/
|
||||
public class RedisMessaging extends AbstractMessagingService {
|
||||
public class RedisMessagingService extends AbstractMessagingService {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private JedisPool jedisPool;
|
||||
private LPSub sub;
|
||||
|
||||
public RedisMessaging(LuckPermsPlugin plugin) {
|
||||
public RedisMessagingService(LuckPermsPlugin plugin) {
|
||||
super(plugin, "Redis");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@ -85,7 +85,7 @@ public class RedisMessaging extends AbstractMessagingService {
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private static class LPSub extends JedisPubSub {
|
||||
private final RedisMessaging parent;
|
||||
private final RedisMessagingService parent;
|
||||
|
||||
@Override
|
||||
public void onMessage(String channel, String msg) {
|
@ -53,7 +53,7 @@ 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.messaging.RedisMessagingService;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsScheduler;
|
||||
import me.lucko.luckperms.common.storage.Storage;
|
||||
@ -212,7 +212,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
if (messagingType.equals("redis")) {
|
||||
if (getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||
RedisMessaging redis = new RedisMessaging(this);
|
||||
RedisMessagingService redis = new RedisMessagingService(this);
|
||||
try {
|
||||
redis.init(getConfiguration().get(ConfigKeys.REDIS_ADDRESS), getConfiguration().get(ConfigKeys.REDIS_PASSWORD));
|
||||
messagingService = redis;
|
||||
|
Loading…
Reference in New Issue
Block a user