mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-12-23 02:28:01 +00:00
make RedisBungeeAPI class platform dependant and make Abstract version of it
This commit is contained in:
parent
576bcc39d2
commit
17897bc112
@ -10,11 +10,11 @@ Velocity*: *version 3.1.2 or above is only supported, any version below that mig
|
||||
This fork ensures compatibility with old plugins, so it should work as drop replacement,
|
||||
but since Api has been split from the platform there some changes that have to be done, so your plugin might not work if:
|
||||
|
||||
* your plugin have used the Method `RedisBungeeAPI#getServerFor(UUID player)` as it was returning `net.md_5.bungee.api.config.ServerInfo`
|
||||
now it returns `String`.
|
||||
* there is none at the moment, please report any findings at the issue page.
|
||||
|
||||
as of version 0.8.0,
|
||||
If you are using static method `RedisBungee#getPool()` it might fail in:
|
||||
Cluster mode compatibility in version 0.8.0:
|
||||
|
||||
If you are using static legacy method `RedisBungee#getPool()` it might fail in:
|
||||
* if Cluster mode is enabled, due fact its Uses different classes
|
||||
* JedisPool compatibility mode is disabled in the config due fact project internally switched to JedisPooled than Jedis
|
||||
|
||||
|
@ -4,11 +4,11 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummoner;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisPooledSummoner;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
@ -18,21 +18,21 @@ import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class exposes some internal RedisBungee functions. You obtain an instance of this object by invoking {@link RedisBungeeAPI#getRedisBungeeApi()}
|
||||
* or somehow you got the Plugin instance by you can call the api using {@link RedisBungeePlugin#getRedisBungeeApi()}.
|
||||
* This abstract class is extended by platform plugin to provide some platform specific methods.
|
||||
* overall its general contains all methods needed by external usage.
|
||||
*
|
||||
* @author tuxed
|
||||
* @since 0.2.3 | updated 0.7.0
|
||||
* @author Ham1255
|
||||
* @since 0.8.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class RedisBungeeAPI {
|
||||
private final RedisBungeePlugin<?> plugin;
|
||||
private final List<String> reservedChannels;
|
||||
private static RedisBungeeAPI redisBungeeApi;
|
||||
public abstract class AbstractRedisBungeeAPI {
|
||||
protected final RedisBungeePlugin<?> plugin;
|
||||
private static AbstractRedisBungeeAPI abstractRedisBungeeAPI;
|
||||
protected final List<String> reservedChannels;
|
||||
|
||||
RedisBungeeAPI(RedisBungeePlugin<?> plugin) {
|
||||
AbstractRedisBungeeAPI(RedisBungeePlugin<?> plugin) {
|
||||
abstractRedisBungeeAPI = this;
|
||||
this.plugin = plugin;
|
||||
redisBungeeApi = this;
|
||||
this.reservedChannels = ImmutableList.of(
|
||||
"redisbungee-allservers",
|
||||
"redisbungee-" + plugin.getConfiguration().getProxyId(),
|
||||
@ -59,15 +59,14 @@ public class RedisBungeeAPI {
|
||||
public final long getLastOnline(@NonNull UUID player) {
|
||||
return plugin.getDataManager().getLastOnline(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the server where the specified player is playing. This function also deals with the case of local players
|
||||
* as well, and will return local information on them.
|
||||
*
|
||||
* @param player a player name
|
||||
* @param player a player uuid
|
||||
* @return a String name for the server the player is on.
|
||||
*/
|
||||
public final String getServerFor(@NonNull UUID player) {
|
||||
public final String getServerNameFor(@NonNull UUID player) {
|
||||
return plugin.getDataManager().getServer(player);
|
||||
}
|
||||
|
||||
@ -447,15 +446,7 @@ public class RedisBungeeAPI {
|
||||
return this.plugin.getRedisBungeeMode();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Api instance
|
||||
*
|
||||
* @return the API instance.
|
||||
* @since 0.6.5
|
||||
*/
|
||||
public static RedisBungeeAPI getRedisBungeeApi() {
|
||||
return redisBungeeApi;
|
||||
public static AbstractRedisBungeeAPI getAbstractRedisBungeeAPI() {
|
||||
return abstractRedisBungeeAPI;
|
||||
}
|
||||
|
||||
}
|
@ -49,7 +49,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
|
||||
return plugin.isPlayerOnAServer(player) ? plugin.getPlayerServerName(player) : null;
|
||||
|
||||
try {
|
||||
return serverCache.get(uuid, new RedisTask<String>(plugin.getRedisBungeeApi()) {
|
||||
return serverCache.get(uuid, new RedisTask<String>(plugin.getAbstractRedisBungeeApi()) {
|
||||
@Override
|
||||
public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||
return Objects.requireNonNull(unifiedJedis.hget("player:" + uuid, "server"), "user not found");
|
||||
@ -72,7 +72,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
|
||||
return plugin.getConfiguration().getProxyId();
|
||||
|
||||
try {
|
||||
return proxyCache.get(uuid, new RedisTask<String>(plugin.getRedisBungeeApi()) {
|
||||
return proxyCache.get(uuid, new RedisTask<String>(plugin.getAbstractRedisBungeeApi()) {
|
||||
@Override
|
||||
public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||
return Objects.requireNonNull(unifiedJedis.hget("player:" + uuid, "proxy"), "user not found");
|
||||
@ -93,7 +93,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
|
||||
return plugin.getPlayerIp(player);
|
||||
|
||||
try {
|
||||
return ipCache.get(uuid, new RedisTask<InetAddress>(plugin.getRedisBungeeApi()) {
|
||||
return ipCache.get(uuid, new RedisTask<InetAddress>(plugin.getAbstractRedisBungeeApi()) {
|
||||
@Override
|
||||
public InetAddress unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||
String result = unifiedJedis.hget("player:" + uuid, "ip");
|
||||
@ -117,7 +117,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
|
||||
return 0;
|
||||
|
||||
try {
|
||||
return lastOnlineCache.get(uuid, new RedisTask<Long>(plugin.getRedisBungeeApi()) {
|
||||
return lastOnlineCache.get(uuid, new RedisTask<Long>(plugin.getAbstractRedisBungeeApi()) {
|
||||
|
||||
@Override
|
||||
public Long unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||
|
@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.ConfigLoader;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
||||
@ -101,7 +101,7 @@ public interface RedisBungeePlugin<P> extends EventsPlatform, ConfigLoader {
|
||||
}.execute();
|
||||
}
|
||||
|
||||
RedisBungeeAPI getRedisBungeeApi();
|
||||
AbstractRedisBungeeAPI getAbstractRedisBungeeApi();
|
||||
|
||||
UUIDTranslator getUuidTranslator();
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.api.tasks;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummoner;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisPooledSummoner;
|
||||
@ -13,7 +13,7 @@ import java.util.concurrent.Callable;
|
||||
public abstract class RedisTask<V> implements Runnable, Callable<V> {
|
||||
|
||||
protected final Summoner<?> summoner;
|
||||
protected final RedisBungeeAPI api;
|
||||
protected final AbstractRedisBungeeAPI api;
|
||||
protected RedisBungeePlugin<?> plugin;
|
||||
|
||||
@Override
|
||||
@ -21,14 +21,14 @@ public abstract class RedisTask<V> implements Runnable, Callable<V> {
|
||||
return execute();
|
||||
}
|
||||
|
||||
public RedisTask(RedisBungeeAPI api) {
|
||||
public RedisTask(AbstractRedisBungeeAPI api) {
|
||||
this.api = api;
|
||||
this.summoner = api.getSummoner();
|
||||
}
|
||||
|
||||
public RedisTask(RedisBungeePlugin<?> plugin) {
|
||||
this.plugin = plugin;
|
||||
this.api = plugin.getRedisBungeeApi();
|
||||
this.api = plugin.getAbstractRedisBungeeApi();
|
||||
this.summoner = api.getSummoner();
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,8 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.api.util.payload;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.AbstractDataManager;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.UnifiedJedis;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@ -16,14 +13,14 @@ public class PayloadUtils {
|
||||
|
||||
public static void playerJoinPayload(UUID uuid, UnifiedJedis unifiedJedis, InetAddress inetAddress) {
|
||||
unifiedJedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
|
||||
uuid, AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
|
||||
new AbstractDataManager.LoginPayload(inetAddress))));
|
||||
}
|
||||
|
||||
|
||||
public static void playerQuitPayload(String uuid, UnifiedJedis unifiedJedis, long timestamp) {
|
||||
unifiedJedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||
UUID.fromString(uuid), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
|
||||
UUID.fromString(uuid), AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
|
||||
new AbstractDataManager.LogoutPayload(timestamp))));
|
||||
}
|
||||
|
||||
@ -31,14 +28,14 @@ public class PayloadUtils {
|
||||
|
||||
public static void playerServerChangePayload(UUID uuid, UnifiedJedis unifiedJedis, String newServer, String oldServer) {
|
||||
unifiedJedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
|
||||
uuid, AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
|
||||
new AbstractDataManager.ServerChangePayload(newServer, oldServer))));
|
||||
}
|
||||
|
||||
|
||||
public static void kickPlayerPayload(UUID uuid, String message, UnifiedJedis unifiedJedis) {
|
||||
unifiedJedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.KICK,
|
||||
uuid, AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId(), AbstractDataManager.DataManagerMessage.Action.KICK,
|
||||
new AbstractDataManager.KickPayload(message))));
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.api.util.player;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
||||
import redis.clients.jedis.UnifiedJedis;
|
||||
|
||||
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerQuitPayload;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
|
||||
public static void cleanUpPlayer(String uuid, UnifiedJedis rsc, boolean firePayload) {
|
||||
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", uuid);
|
||||
rsc.srem("proxy:" + AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId() + ":usersOnline", uuid);
|
||||
rsc.hdel("player:" + uuid, "server", "ip", "proxy");
|
||||
long timestamp = System.currentTimeMillis();
|
||||
rsc.hset("player:" + uuid, "online", String.valueOf(timestamp));
|
||||
|
@ -70,7 +70,7 @@ public final class UUIDTranslator {
|
||||
if (!plugin.isOnlineMode()) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
RedisTask<UUID> redisTask = new RedisTask<UUID>(plugin.getRedisBungeeApi()) {
|
||||
RedisTask<UUID> redisTask = new RedisTask<UUID>(plugin.getAbstractRedisBungeeApi()) {
|
||||
@Override
|
||||
public UUID unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||
String stored = unifiedJedis.hget("uuid-cache", player.toLowerCase());
|
||||
@ -135,7 +135,7 @@ public final class UUIDTranslator {
|
||||
uuidToNameMap.remove(player);
|
||||
}
|
||||
|
||||
RedisTask<String> redisTask = new RedisTask<String>(plugin.getRedisBungeeApi()) {
|
||||
RedisTask<String> redisTask = new RedisTask<String>(plugin.getAbstractRedisBungeeApi()) {
|
||||
@Override
|
||||
public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||
String stored = unifiedJedis.hget("uuid-cache", player.toString());
|
||||
|
@ -1,10 +1,7 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.UnifiedJedis;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -38,7 +38,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
||||
|
||||
private static RedisBungeeAPI apiStatic;
|
||||
|
||||
private RedisBungeeAPI api;
|
||||
private AbstractRedisBungeeAPI api;
|
||||
private RedisBungeeMode redisBungeeMode;
|
||||
private PubSubListener psl = null;
|
||||
private Summoner<?> summoner;
|
||||
@ -82,7 +82,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
||||
|
||||
|
||||
@Override
|
||||
public RedisBungeeAPI getRedisBungeeApi() {
|
||||
public AbstractRedisBungeeAPI getAbstractRedisBungeeApi() {
|
||||
return this.api;
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
||||
}
|
||||
// init the api class
|
||||
this.api = new RedisBungeeAPI(this);
|
||||
apiStatic = this.api;
|
||||
apiStatic = (RedisBungeeAPI) this.api;
|
||||
// init the http lib
|
||||
httpClient = new OkHttpClient();
|
||||
Dispatcher dispatcher = new Dispatcher(getExecutorService());
|
||||
@ -333,7 +333,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
||||
*
|
||||
* @deprecated Please use {@link RedisBungeeAPI#getRedisBungeeApi()} this class intended to for old plugins that no longer updated.
|
||||
*
|
||||
* @return the {@link RedisBungeeAPI} object instance.
|
||||
* @return the {@link AbstractRedisBungeeAPI} object instance.
|
||||
*/
|
||||
@Deprecated
|
||||
public static RedisBungeeAPI getApi() {
|
||||
|
@ -0,0 +1,49 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This platform class exposes some internal RedisBungee functions. You obtain an instance of this object by invoking {@link RedisBungeeAPI#getRedisBungeeApi()}
|
||||
* or somehow you got the Plugin instance by you can call the api using {@link RedisBungeePlugin#getAbstractRedisBungeeApi()}.
|
||||
*
|
||||
* @author tuxed
|
||||
* @since 0.2.3 | updated 0.8.0
|
||||
*/
|
||||
public class RedisBungeeAPI extends AbstractRedisBungeeAPI {
|
||||
|
||||
private static RedisBungeeAPI redisBungeeApi;
|
||||
|
||||
RedisBungeeAPI(RedisBungeePlugin<?> plugin) {
|
||||
super(plugin);
|
||||
redisBungeeApi = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the server where the specified player is playing. This function also deals with the case of local players
|
||||
* as well, and will return local information on them.
|
||||
*
|
||||
* @param player a player uuid
|
||||
* @return {@link ServerInfo}
|
||||
* @deprecated This does return null even if player is on a server if the server is not on the proxy
|
||||
* @see #getServerNameFor(UUID)
|
||||
*/
|
||||
@Deprecated
|
||||
public final ServerInfo getServerFor(@NonNull UUID player) {
|
||||
return ((Plugin) this.plugin).getProxy().getServerInfo(this.getServerNameFor(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Api instance
|
||||
*
|
||||
* @return the API instance.
|
||||
* @since 0.6.5
|
||||
*/
|
||||
public static RedisBungeeAPI getRedisBungeeApi() {
|
||||
return redisBungeeApi;
|
||||
}
|
||||
}
|
@ -152,7 +152,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
||||
original = plugin.getPlayers();
|
||||
} else {
|
||||
try {
|
||||
original = plugin.getRedisBungeeApi().getPlayersOnServer(type);
|
||||
original = plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
@ -170,7 +170,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
||||
} else {
|
||||
out.writeUTF(type);
|
||||
try {
|
||||
out.writeInt(plugin.getRedisBungeeApi().getPlayersOnServer(type).size());
|
||||
out.writeInt(plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type).size());
|
||||
} catch (IllegalArgumentException e) {
|
||||
out.writeInt(0);
|
||||
}
|
||||
@ -180,12 +180,12 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
||||
String user = in.readUTF();
|
||||
out.writeUTF("LastOnline");
|
||||
out.writeUTF(user);
|
||||
out.writeLong(plugin.getRedisBungeeApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
|
||||
out.writeLong(plugin.getAbstractRedisBungeeApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
|
||||
break;
|
||||
case "ServerPlayers":
|
||||
String type1 = in.readUTF();
|
||||
out.writeUTF("ServerPlayers");
|
||||
Multimap<String, UUID> multimap = plugin.getRedisBungeeApi().getServerToPlayers();
|
||||
Multimap<String, UUID> multimap = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
||||
|
||||
boolean includesUsers;
|
||||
|
||||
@ -221,7 +221,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
||||
String username = in.readUTF();
|
||||
out.writeUTF("PlayerProxy");
|
||||
out.writeUTF(username);
|
||||
out.writeUTF(plugin.getRedisBungeeApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
|
||||
out.writeUTF(plugin.getAbstractRedisBungeeApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
@ -235,7 +235,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onPubSubMessage(PubSubMessageEvent event) {
|
||||
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getRedisBungeeApi().getProxyId())) {
|
||||
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getAbstractRedisBungeeApi().getProxyId())) {
|
||||
String message = event.getMessage();
|
||||
if (message.startsWith("/"))
|
||||
message = message.substring(1);
|
||||
|
@ -4,7 +4,7 @@ import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
@ -23,7 +23,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* This class contains subclasses that are used for the commands RedisBungee overrides or includes: /glist, /find and /lastseen.
|
||||
* <p>
|
||||
* All classes use the {@link RedisBungeeAPI}.
|
||||
* All classes use the {@link AbstractRedisBungeeAPI}.
|
||||
*
|
||||
* @author tuxed
|
||||
* @since 0.2.3
|
||||
@ -53,11 +53,11 @@ public class RedisBungeeCommands {
|
||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int count = plugin.getRedisBungeeApi().getPlayerCount();
|
||||
int count = plugin.getAbstractRedisBungeeApi().getPlayerCount();
|
||||
BaseComponent[] playersOnline = new ComponentBuilder("").color(ChatColor.YELLOW)
|
||||
.append(playerPlural(count) + " currently online.").create();
|
||||
if (args.length > 0 && args[0].equals("showall")) {
|
||||
Multimap<String, UUID> serverToPlayers = plugin.getRedisBungeeApi().getServerToPlayers();
|
||||
Multimap<String, UUID> serverToPlayers = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
||||
Multimap<String, String> human = HashMultimap.create();
|
||||
for (Map.Entry<String, UUID> entry : serverToPlayers.entries()) {
|
||||
// if for any reason UUID translation fails just return the uuid as name, to make command finish executing.
|
||||
@ -105,7 +105,7 @@ public class RedisBungeeCommands {
|
||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
ServerInfo si = plugin.getProxy().getServerInfo(plugin.getRedisBungeeApi().getServerFor(uuid));
|
||||
ServerInfo si = plugin.getProxy().getServerInfo(plugin.getAbstractRedisBungeeApi().getServerNameFor(uuid));
|
||||
if (si != null) {
|
||||
TextComponent message = new TextComponent();
|
||||
message.setColor(ChatColor.BLUE);
|
||||
@ -141,7 +141,7 @@ public class RedisBungeeCommands {
|
||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
long secs = plugin.getRedisBungeeApi().getLastOnline(uuid);
|
||||
long secs = plugin.getAbstractRedisBungeeApi().getLastOnline(uuid);
|
||||
TextComponent message = new TextComponent();
|
||||
if (secs == 0) {
|
||||
message.setColor(ChatColor.GREEN);
|
||||
@ -181,7 +181,7 @@ public class RedisBungeeCommands {
|
||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
InetAddress ia = plugin.getRedisBungeeApi().getPlayerIp(uuid);
|
||||
InetAddress ia = plugin.getAbstractRedisBungeeApi().getPlayerIp(uuid);
|
||||
if (ia != null) {
|
||||
TextComponent message = new TextComponent();
|
||||
message.setColor(ChatColor.GREEN);
|
||||
@ -217,7 +217,7 @@ public class RedisBungeeCommands {
|
||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
String proxy = plugin.getRedisBungeeApi().getProxy(uuid);
|
||||
String proxy = plugin.getAbstractRedisBungeeApi().getProxy(uuid);
|
||||
if (proxy != null) {
|
||||
TextComponent message = new TextComponent();
|
||||
message.setColor(ChatColor.GREEN);
|
||||
@ -246,7 +246,7 @@ public class RedisBungeeCommands {
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (args.length > 0) {
|
||||
String command = Joiner.on(" ").skipNulls().join(args);
|
||||
plugin.getRedisBungeeApi().sendProxyCommand(command);
|
||||
plugin.getAbstractRedisBungeeApi().sendProxyCommand(command);
|
||||
TextComponent message = new TextComponent();
|
||||
message.setColor(ChatColor.GREEN);
|
||||
message.setText("Sent the command /" + command + " to all proxies.");
|
||||
@ -268,7 +268,7 @@ public class RedisBungeeCommands {
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
TextComponent textComponent = new TextComponent();
|
||||
textComponent.setText("You are on " + plugin.getRedisBungeeApi().getProxyId() + ".");
|
||||
textComponent.setText("You are on " + plugin.getAbstractRedisBungeeApi().getProxyId() + ".");
|
||||
textComponent.setColor(ChatColor.YELLOW);
|
||||
sender.sendMessage(textComponent);
|
||||
}
|
||||
@ -284,7 +284,7 @@ public class RedisBungeeCommands {
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] strings) {
|
||||
TextComponent textComponent = new TextComponent();
|
||||
textComponent.setText("All server IDs: " + Joiner.on(", ").join(plugin.getRedisBungeeApi().getAllProxies()));
|
||||
textComponent.setText("All server IDs: " + Joiner.on(", ").join(plugin.getAbstractRedisBungeeApi().getAllProxies()));
|
||||
textComponent.setColor(ChatColor.YELLOW);
|
||||
sender.sendMessage(textComponent);
|
||||
}
|
||||
@ -308,11 +308,11 @@ public class RedisBungeeCommands {
|
||||
sender.sendMessage(new ComponentBuilder(proxy + " is not a valid proxy. See /serverids for valid proxies.").color(ChatColor.RED).create());
|
||||
return;
|
||||
}
|
||||
Set<UUID> players = plugin.getRedisBungeeApi().getPlayersOnProxy(proxy);
|
||||
Set<UUID> players = plugin.getAbstractRedisBungeeApi().getPlayersOnProxy(proxy);
|
||||
BaseComponent[] playersOnline = new ComponentBuilder("").color(ChatColor.YELLOW)
|
||||
.append(playerPlural(players.size()) + " currently on proxy " + proxy + ".").create();
|
||||
if (args.length >= 2 && args[1].equals("showall")) {
|
||||
Multimap<String, UUID> serverToPlayers = plugin.getRedisBungeeApi().getServerToPlayers();
|
||||
Multimap<String, UUID> serverToPlayers = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
||||
Multimap<String, String> human = HashMultimap.create();
|
||||
for (Map.Entry<String, UUID> entry : serverToPlayers.entries()) {
|
||||
if (players.contains(entry.getValue())) {
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
|
||||
/**
|
||||
* This platform class exposes some internal RedisBungee functions. You obtain an instance of this object by invoking {@link RedisBungeeAPI#getRedisBungeeApi()}
|
||||
* or somehow you got the Plugin instance by you can call the api using {@link RedisBungeePlugin#getAbstractRedisBungeeApi()}.
|
||||
*
|
||||
* @author tuxed
|
||||
* @since 0.2.3 | updated 0.8.0
|
||||
*/
|
||||
public class RedisBungeeAPI extends AbstractRedisBungeeAPI {
|
||||
|
||||
private static RedisBungeeAPI redisBungeeApi;
|
||||
|
||||
RedisBungeeAPI(RedisBungeePlugin<?> plugin) {
|
||||
super(plugin);
|
||||
redisBungeeApi = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Api instance
|
||||
*
|
||||
* @return the API instance.
|
||||
* @since 0.6.5
|
||||
*/
|
||||
public static RedisBungeeAPI getRedisBungeeApi() {
|
||||
return redisBungeeApi;
|
||||
}
|
||||
}
|
@ -156,7 +156,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
original = plugin.getPlayers();
|
||||
} else {
|
||||
try {
|
||||
original = plugin.getRedisBungeeApi().getPlayersOnServer(type);
|
||||
original = plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
@ -174,7 +174,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
} else {
|
||||
out.writeUTF(type);
|
||||
try {
|
||||
out.writeInt(plugin.getRedisBungeeApi().getPlayersOnServer(type).size());
|
||||
out.writeInt(plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type).size());
|
||||
} catch (IllegalArgumentException e) {
|
||||
out.writeInt(0);
|
||||
}
|
||||
@ -184,12 +184,12 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
String user = in.readUTF();
|
||||
out.writeUTF("LastOnline");
|
||||
out.writeUTF(user);
|
||||
out.writeLong(plugin.getRedisBungeeApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
|
||||
out.writeLong(plugin.getAbstractRedisBungeeApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
|
||||
break;
|
||||
case "ServerPlayers":
|
||||
String type1 = in.readUTF();
|
||||
out.writeUTF("ServerPlayers");
|
||||
Multimap<String, UUID> multimap = plugin.getRedisBungeeApi().getServerToPlayers();
|
||||
Multimap<String, UUID> multimap = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
||||
|
||||
boolean includesUsers;
|
||||
|
||||
@ -225,7 +225,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
String username = in.readUTF();
|
||||
out.writeUTF("PlayerProxy");
|
||||
out.writeUTF(username);
|
||||
out.writeUTF(plugin.getRedisBungeeApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
|
||||
out.writeUTF(plugin.getAbstractRedisBungeeApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
@ -240,7 +240,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
@Override
|
||||
@Subscribe
|
||||
public void onPubSubMessage(PubSubMessageEvent event) {
|
||||
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getRedisBungeeApi().getProxyId())) {
|
||||
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getAbstractRedisBungeeApi().getProxyId())) {
|
||||
String message = event.getMessage();
|
||||
if (message.startsWith("/"))
|
||||
message = message.substring(1);
|
||||
|
@ -47,7 +47,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private final Path dataFolder;
|
||||
private final RedisBungeeAPI api;
|
||||
private final AbstractRedisBungeeAPI api;
|
||||
private final PubSubListener psl;
|
||||
private Summoner<?> jedisSummoner;
|
||||
private RedisBungeeMode redisBungeeMode;
|
||||
@ -130,7 +130,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisBungeeAPI getRedisBungeeApi() {
|
||||
public AbstractRedisBungeeAPI getAbstractRedisBungeeApi() {
|
||||
return this.api;
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,6 @@ package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.UnifiedJedis;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -20,9 +18,9 @@ public class VelocityPlayerUtils {
|
||||
Map<String, String> playerData = new HashMap<>(4);
|
||||
playerData.put("online", "0");
|
||||
playerData.put("ip", player.getRemoteAddress().getHostName());
|
||||
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getProxyId());
|
||||
playerData.put("proxy", AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId());
|
||||
|
||||
unifiedJedis.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", player.getUniqueId().toString());
|
||||
unifiedJedis.sadd("proxy:" + AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId() + ":usersOnline", player.getUniqueId().toString());
|
||||
unifiedJedis.hmset("player:" + player.getUniqueId().toString(), playerData);
|
||||
|
||||
if (fireEvent) {
|
||||
|
@ -9,7 +9,7 @@ import java.util.UUID;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeVelocityPlugin;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
@ -24,7 +24,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
/**
|
||||
* This class contains subclasses that are used for the commands RedisBungee overrides or includes: /glist, /find and /lastseen.
|
||||
* <p>
|
||||
* All classes use the {@link RedisBungeeAPI}.
|
||||
* All classes use the {@link AbstractRedisBungeeAPI}.
|
||||
*
|
||||
* @author tuxed
|
||||
* @since 0.2.3
|
||||
@ -52,11 +52,11 @@ public class RedisBungeeCommands {
|
||||
@Override
|
||||
public void execute(final Invocation invocation) {
|
||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
||||
int count = plugin.getRedisBungeeApi().getPlayerCount();
|
||||
int count = plugin.getAbstractRedisBungeeApi().getPlayerCount();
|
||||
Component playersOnline = Component.text(playerPlural(count) + " currently online.", NamedTextColor.YELLOW);
|
||||
CommandSource sender = invocation.source();
|
||||
if (invocation.arguments().length > 0 && invocation.arguments()[0].equals("showall")) {
|
||||
Multimap<String, UUID> serverToPlayers = plugin.getRedisBungeeApi().getServerToPlayers();
|
||||
Multimap<String, UUID> serverToPlayers = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
||||
Multimap<String, String> human = HashMultimap.create();
|
||||
serverToPlayers.forEach((key, value) -> {
|
||||
// if for any reason UUID translation fails just return the uuid as name, to make command finish executing.
|
||||
@ -101,7 +101,7 @@ public class RedisBungeeCommands {
|
||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
ServerInfo si = plugin.getProxy().getServer(plugin.getRedisBungeeApi().getServerFor(uuid)).map(RegisteredServer::getServerInfo).orElse(null);
|
||||
ServerInfo si = plugin.getProxy().getServer(plugin.getAbstractRedisBungeeApi().getServerNameFor(uuid)).map(RegisteredServer::getServerInfo).orElse(null);
|
||||
if (si != null) {
|
||||
Component message = Component.text(args[0] + " is on " + si.getName() + ".", NamedTextColor.BLUE);
|
||||
sender.sendMessage(message);
|
||||
@ -138,7 +138,7 @@ public class RedisBungeeCommands {
|
||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
long secs = plugin.getRedisBungeeApi().getLastOnline(uuid);
|
||||
long secs = plugin.getAbstractRedisBungeeApi().getLastOnline(uuid);
|
||||
TextComponent.Builder message = Component.text();
|
||||
if (secs == 0) {
|
||||
message.color(NamedTextColor.GREEN);
|
||||
@ -181,7 +181,7 @@ public class RedisBungeeCommands {
|
||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
InetAddress ia = plugin.getRedisBungeeApi().getPlayerIp(uuid);
|
||||
InetAddress ia = plugin.getAbstractRedisBungeeApi().getPlayerIp(uuid);
|
||||
if (ia != null) {
|
||||
TextComponent message = Component.text(args[0] + " is connected from " + ia.toString() + ".", NamedTextColor.GREEN);
|
||||
sender.sendMessage(message);
|
||||
@ -218,7 +218,7 @@ public class RedisBungeeCommands {
|
||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
String proxy = plugin.getRedisBungeeApi().getProxy(uuid);
|
||||
String proxy = plugin.getAbstractRedisBungeeApi().getProxy(uuid);
|
||||
if (proxy != null) {
|
||||
TextComponent message = Component.text(args[0] + " is connected to " + proxy + ".", NamedTextColor.GREEN);
|
||||
sender.sendMessage(message);
|
||||
@ -251,7 +251,7 @@ public class RedisBungeeCommands {
|
||||
CommandSource sender = invocation.source();
|
||||
if (args.length > 0) {
|
||||
String command = Joiner.on(" ").skipNulls().join(args);
|
||||
plugin.getRedisBungeeApi().sendProxyCommand(command);
|
||||
plugin.getAbstractRedisBungeeApi().sendProxyCommand(command);
|
||||
TextComponent message = Component.text("Sent the command /" + command + " to all proxies.", NamedTextColor.GREEN);
|
||||
sender.sendMessage(message);
|
||||
} else {
|
||||
@ -274,7 +274,7 @@ public class RedisBungeeCommands {
|
||||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
invocation.source().sendMessage(Component.text("You are on " + plugin.getRedisBungeeApi().getProxyId() + ".", NamedTextColor.YELLOW));
|
||||
invocation.source().sendMessage(Component.text("You are on " + plugin.getAbstractRedisBungeeApi().getProxyId() + ".", NamedTextColor.YELLOW));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -293,7 +293,7 @@ public class RedisBungeeCommands {
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
invocation.source().sendMessage(
|
||||
Component.text("All server IDs: " + Joiner.on(", ").join(plugin.getRedisBungeeApi().getAllProxies()), NamedTextColor.YELLOW));
|
||||
Component.text("All server IDs: " + Joiner.on(", ").join(plugin.getAbstractRedisBungeeApi().getAllProxies()), NamedTextColor.YELLOW));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -319,10 +319,10 @@ public class RedisBungeeCommands {
|
||||
sender.sendMessage(Component.text(proxy + " is not a valid proxy. See /serverids for valid proxies.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Set<UUID> players = plugin.getRedisBungeeApi().getPlayersOnProxy(proxy);
|
||||
Set<UUID> players = plugin.getAbstractRedisBungeeApi().getPlayersOnProxy(proxy);
|
||||
Component playersOnline = Component.text(playerPlural(players.size()) + " currently on proxy " + proxy + ".", NamedTextColor.YELLOW);
|
||||
if (args.length >= 2 && args[1].equals("showall")) {
|
||||
Multimap<String, UUID> serverToPlayers = plugin.getRedisBungeeApi().getServerToPlayers();
|
||||
Multimap<String, UUID> serverToPlayers = plugin.getAbstractRedisBungeeApi().getServerToPlayers();
|
||||
Multimap<String, String> human = HashMultimap.create();
|
||||
serverToPlayers.forEach((key, value) -> {
|
||||
if (players.contains(value)) {
|
||||
|
Loading…
Reference in New Issue
Block a user