2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-22 20:28:00 +00:00

Change Plugin instance of Bungeecord to RedisBungee to maintain old plugin compatibility

This commit is contained in:
mohammed jasem alaajel 2022-07-26 18:42:29 +04:00
parent 2ae9b5d480
commit 64af12044e
14 changed files with 86 additions and 131 deletions

View File

@ -10,14 +10,6 @@ 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 has used Internal classes of RedisBungee like getting the `JedisPool` or something else.
because `RedisBungee.java` is no longer an Plugin for example:
```java
// this will be broken
RedisBungee plugin = (RedisBungee) ProxyServer.getInstance().getPluginManager().getPlugin("RedisBungee");
JedisPool jedisPool = plugin.getPool();
```
* 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`.

View File

@ -1,38 +0,0 @@
package com.imaginarycode.minecraft.redisbungee;
import redis.clients.jedis.JedisPool;
/**
* This used to be old plugin instance of redis-bungee, but now it's used to get the api for old plugins
*
* @deprecated its deprecated but won't be removed, so please use {@link RedisBungeeAPI#getRedisBungeeApi()}
*
*/
@Deprecated
public class RedisBungee {
private static RedisBungeeAPI api;
public RedisBungee(RedisBungeeAPI api) {
RedisBungee.api = api;
}
/**
* This returns an instance of {@link RedisBungeeAPI}
*
* @deprecated Please use {@link RedisBungeeAPI#getRedisBungeeApi()} this class intended to for old plugins that no longer updated.
*
* @return the {@link RedisBungeeAPI} object instance.
*/
@Deprecated
public static RedisBungeeAPI getApi() {
return api;
}
@Deprecated
public JedisPool getPool() {
return api.getJedisPool();
}
}

View File

@ -19,7 +19,7 @@ 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#getApi()}.
* or somehow you got the Plugin instance by you can call the api using {@link RedisBungeePlugin#getRedisBungeeApi()}.
*
* @author tuxed
* @since 0.2.3 | updated 0.7.0
@ -38,7 +38,6 @@ public class RedisBungeeAPI {
"redisbungee-" + plugin.getConfiguration().getProxyId(),
"redisbungee-data"
);
new RedisBungee(this);
}
/**

View File

@ -11,7 +11,6 @@ import com.google.gson.JsonParser;
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
import redis.clients.jedis.UnifiedJedis;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.util.Objects;
import java.util.UUID;
@ -50,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.getApi()) {
return serverCache.get(uuid, new RedisTask<String>(plugin.getRedisBungeeApi()) {
@Override
public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
return Objects.requireNonNull(unifiedJedis.hget("player:" + uuid, "server"), "user not found");
@ -73,7 +72,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
return plugin.getConfiguration().getProxyId();
try {
return proxyCache.get(uuid, new RedisTask<String>(plugin.getApi()) {
return proxyCache.get(uuid, new RedisTask<String>(plugin.getRedisBungeeApi()) {
@Override
public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
return Objects.requireNonNull(unifiedJedis.hget("player:" + uuid, "proxy"), "user not found");
@ -94,7 +93,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
return plugin.getPlayerIp(player);
try {
return ipCache.get(uuid, new RedisTask<InetAddress>(plugin.getApi()) {
return ipCache.get(uuid, new RedisTask<InetAddress>(plugin.getRedisBungeeApi()) {
@Override
public InetAddress unifiedJedisTask(UnifiedJedis unifiedJedis) {
String result = unifiedJedis.hget("player:" + uuid, "ip");
@ -118,7 +117,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
return 0;
try {
return lastOnlineCache.get(uuid, new RedisTask<Long>(plugin.getApi()) {
return lastOnlineCache.get(uuid, new RedisTask<Long>(plugin.getRedisBungeeApi()) {
@Override
public Long unifiedJedisTask(UnifiedJedis unifiedJedis) {

View File

@ -101,7 +101,7 @@ public interface RedisBungeePlugin<P> extends EventsPlatform, ConfigLoader {
}.execute();
}
RedisBungeeAPI getApi();
RedisBungeeAPI getRedisBungeeApi();
UUIDTranslator getUuidTranslator();

View File

@ -6,7 +6,6 @@ import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummone
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisPooledSummoner;
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.UnifiedJedis;
import java.util.concurrent.Callable;
@ -29,7 +28,7 @@ public abstract class RedisTask<V> implements Runnable, Callable<V> {
public RedisTask(RedisBungeePlugin<?> plugin) {
this.plugin = plugin;
this.api = plugin.getApi();
this.api = plugin.getRedisBungeeApi();
this.summoner = api.getSummoner();
}

View File

@ -8,9 +8,6 @@ import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
import org.checkerframework.checker.nullness.qual.NonNull;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.UnifiedJedis;
import redis.clients.jedis.exceptions.JedisException;
@ -73,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.getApi()) {
RedisTask<UUID> redisTask = new RedisTask<UUID>(plugin.getRedisBungeeApi()) {
@Override
public UUID unifiedJedisTask(UnifiedJedis unifiedJedis) {
String stored = unifiedJedis.hget("uuid-cache", player.toLowerCase());
@ -138,7 +135,7 @@ public final class UUIDTranslator {
uuidToNameMap.remove(player);
}
RedisTask<String> redisTask = new RedisTask<String>(plugin.getApi()) {
RedisTask<String> redisTask = new RedisTask<String>(plugin.getRedisBungeeApi()) {
@Override
public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
String stored = unifiedJedis.hget("uuid-cache", player.toString());

View File

@ -33,9 +33,10 @@ import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import static com.google.common.base.Preconditions.checkArgument;
public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin<ProxiedPlayer> {
public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlayer> {
private static RedisBungeeAPI apiStatic;
private RedisBungeeAPI api;
private RedisBungeeMode redisBungeeMode;
@ -81,7 +82,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
@Override
public RedisBungeeAPI getApi() {
public RedisBungeeAPI getRedisBungeeApi() {
return this.api;
}
@ -201,6 +202,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
}
// init the api class
this.api = new RedisBungeeAPI(this);
apiStatic = this.api;
// init the http lib
httpClient = new OkHttpClient();
Dispatcher dispatcher = new Dispatcher(getExecutorService());
@ -325,4 +327,21 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
this.redisBungeeMode = mode;
this.summoner = summoner;
}
/**
* This returns an instance of {@link RedisBungeeAPI}
*
* @deprecated Please use {@link RedisBungeeAPI#getRedisBungeeApi()} this class intended to for old plugins that no longer updated.
*
* @return the {@link RedisBungeeAPI} object instance.
*/
@Deprecated
public static RedisBungeeAPI getApi() {
return apiStatic;
}
@Deprecated
public JedisPool getPool() {
return api.getJedisPool();
}
}

View File

@ -20,9 +20,6 @@ import net.md_5.bungee.api.event.*;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.UnifiedJedis;
import java.net.InetAddress;
@ -155,7 +152,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
original = plugin.getPlayers();
} else {
try {
original = plugin.getApi().getPlayersOnServer(type);
original = plugin.getRedisBungeeApi().getPlayersOnServer(type);
} catch (IllegalArgumentException ignored) {
}
}
@ -173,7 +170,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
} else {
out.writeUTF(type);
try {
out.writeInt(plugin.getApi().getPlayersOnServer(type).size());
out.writeInt(plugin.getRedisBungeeApi().getPlayersOnServer(type).size());
} catch (IllegalArgumentException e) {
out.writeInt(0);
}
@ -183,12 +180,12 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
String user = in.readUTF();
out.writeUTF("LastOnline");
out.writeUTF(user);
out.writeLong(plugin.getApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
out.writeLong(plugin.getRedisBungeeApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
break;
case "ServerPlayers":
String type1 = in.readUTF();
out.writeUTF("ServerPlayers");
Multimap<String, UUID> multimap = plugin.getApi().getServerToPlayers();
Multimap<String, UUID> multimap = plugin.getRedisBungeeApi().getServerToPlayers();
boolean includesUsers;
@ -224,7 +221,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
String username = in.readUTF();
out.writeUTF("PlayerProxy");
out.writeUTF(username);
out.writeUTF(plugin.getApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
out.writeUTF(plugin.getRedisBungeeApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
break;
default:
return;
@ -238,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.getApi().getProxyId())) {
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getRedisBungeeApi().getProxyId())) {
String message = event.getMessage();
if (message.startsWith("/"))
message = message.substring(1);

View File

@ -3,8 +3,8 @@ package com.imaginarycode.minecraft.redisbungee.commands;
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.RedisBungeeBungeePlugin;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.BaseComponent;
@ -41,9 +41,9 @@ public class RedisBungeeCommands {
}
public static class GlistCommand extends Command {
private final RedisBungeeBungeePlugin plugin;
private final RedisBungee plugin;
public GlistCommand(RedisBungeeBungeePlugin plugin) {
public GlistCommand(RedisBungee plugin) {
super("glist", "bungeecord.command.list", "redisbungee", "rglist");
this.plugin = plugin;
}
@ -53,11 +53,11 @@ public class RedisBungeeCommands {
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
@Override
public void run() {
int count = plugin.getApi().getPlayerCount();
int count = plugin.getRedisBungeeApi().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.getApi().getServerToPlayers();
Multimap<String, UUID> serverToPlayers = plugin.getRedisBungeeApi().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.
@ -87,9 +87,9 @@ public class RedisBungeeCommands {
}
public static class FindCommand extends Command {
private final RedisBungeeBungeePlugin plugin;
private final RedisBungee plugin;
public FindCommand(RedisBungeeBungeePlugin plugin) {
public FindCommand(RedisBungee plugin) {
super("find", "bungeecord.command.find", "rfind");
this.plugin = plugin;
}
@ -105,7 +105,7 @@ public class RedisBungeeCommands {
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
ServerInfo si = plugin.getProxy().getServerInfo(plugin.getApi().getServerFor(uuid));
ServerInfo si = plugin.getProxy().getServerInfo(plugin.getRedisBungeeApi().getServerFor(uuid));
if (si != null) {
TextComponent message = new TextComponent();
message.setColor(ChatColor.BLUE);
@ -123,9 +123,9 @@ public class RedisBungeeCommands {
}
public static class LastSeenCommand extends Command {
private final RedisBungeeBungeePlugin plugin;
private final RedisBungee plugin;
public LastSeenCommand(RedisBungeeBungeePlugin plugin) {
public LastSeenCommand(RedisBungee plugin) {
super("lastseen", "redisbungee.command.lastseen", "rlastseen");
this.plugin = plugin;
}
@ -141,7 +141,7 @@ public class RedisBungeeCommands {
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
long secs = plugin.getApi().getLastOnline(uuid);
long secs = plugin.getRedisBungeeApi().getLastOnline(uuid);
TextComponent message = new TextComponent();
if (secs == 0) {
message.setColor(ChatColor.GREEN);
@ -163,9 +163,9 @@ public class RedisBungeeCommands {
}
public static class IpCommand extends Command {
private final RedisBungeeBungeePlugin plugin;
private final RedisBungee plugin;
public IpCommand(RedisBungeeBungeePlugin plugin) {
public IpCommand(RedisBungee plugin) {
super("ip", "redisbungee.command.ip", "playerip", "rip", "rplayerip");
this.plugin = plugin;
}
@ -181,7 +181,7 @@ public class RedisBungeeCommands {
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
InetAddress ia = plugin.getApi().getPlayerIp(uuid);
InetAddress ia = plugin.getRedisBungeeApi().getPlayerIp(uuid);
if (ia != null) {
TextComponent message = new TextComponent();
message.setColor(ChatColor.GREEN);
@ -199,9 +199,9 @@ public class RedisBungeeCommands {
}
public static class PlayerProxyCommand extends Command {
private final RedisBungeeBungeePlugin plugin;
private final RedisBungee plugin;
public PlayerProxyCommand(RedisBungeeBungeePlugin plugin) {
public PlayerProxyCommand(RedisBungee plugin) {
super("pproxy", "redisbungee.command.pproxy");
this.plugin = plugin;
}
@ -217,7 +217,7 @@ public class RedisBungeeCommands {
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
String proxy = plugin.getApi().getProxy(uuid);
String proxy = plugin.getRedisBungeeApi().getProxy(uuid);
if (proxy != null) {
TextComponent message = new TextComponent();
message.setColor(ChatColor.GREEN);
@ -235,9 +235,9 @@ public class RedisBungeeCommands {
}
public static class SendToAll extends Command {
private final RedisBungeeBungeePlugin plugin;
private final RedisBungee plugin;
public SendToAll(RedisBungeeBungeePlugin plugin) {
public SendToAll(RedisBungee plugin) {
super("sendtoall", "redisbungee.command.sendtoall", "rsendtoall");
this.plugin = plugin;
}
@ -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.getApi().sendProxyCommand(command);
plugin.getRedisBungeeApi().sendProxyCommand(command);
TextComponent message = new TextComponent();
message.setColor(ChatColor.GREEN);
message.setText("Sent the command /" + command + " to all proxies.");
@ -258,9 +258,9 @@ public class RedisBungeeCommands {
}
public static class ServerId extends Command {
private final RedisBungeeBungeePlugin plugin;
private final RedisBungee plugin;
public ServerId(RedisBungeeBungeePlugin plugin) {
public ServerId(RedisBungee plugin) {
super("serverid", "redisbungee.command.serverid", "rserverid");
this.plugin = plugin;
}
@ -268,15 +268,15 @@ public class RedisBungeeCommands {
@Override
public void execute(CommandSender sender, String[] args) {
TextComponent textComponent = new TextComponent();
textComponent.setText("You are on " + plugin.getApi().getProxyId() + ".");
textComponent.setText("You are on " + plugin.getRedisBungeeApi().getProxyId() + ".");
textComponent.setColor(ChatColor.YELLOW);
sender.sendMessage(textComponent);
}
}
public static class ServerIds extends Command {
private final RedisBungeeBungeePlugin plugin;
public ServerIds(RedisBungeeBungeePlugin plugin) {
private final RedisBungee plugin;
public ServerIds(RedisBungee plugin) {
super("serverids", "redisbungee.command.serverids");
this.plugin =plugin;
}
@ -284,16 +284,16 @@ public class RedisBungeeCommands {
@Override
public void execute(CommandSender sender, String[] strings) {
TextComponent textComponent = new TextComponent();
textComponent.setText("All server IDs: " + Joiner.on(", ").join(plugin.getApi().getAllProxies()));
textComponent.setText("All server IDs: " + Joiner.on(", ").join(plugin.getRedisBungeeApi().getAllProxies()));
textComponent.setColor(ChatColor.YELLOW);
sender.sendMessage(textComponent);
}
}
public static class PlistCommand extends Command {
private final RedisBungeeBungeePlugin plugin;
private final RedisBungee plugin;
public PlistCommand(RedisBungeeBungeePlugin plugin) {
public PlistCommand(RedisBungee plugin) {
super("plist", "redisbungee.command.plist", "rplist");
this.plugin = plugin;
}
@ -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.getApi().getPlayersOnProxy(proxy);
Set<UUID> players = plugin.getRedisBungeeApi().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.getApi().getServerToPlayers();
Multimap<String, UUID> serverToPlayers = plugin.getRedisBungeeApi().getServerToPlayers();
Multimap<String, String> human = HashMultimap.create();
for (Map.Entry<String, UUID> entry : serverToPlayers.entries()) {
if (players.contains(entry.getValue())) {

View File

@ -1,5 +1,5 @@
name: RedisBungee
main: com.imaginarycode.minecraft.redisbungee.RedisBungeeBungeePlugin
main: com.imaginarycode.minecraft.redisbungee.RedisBungee
version: ${project.parent.version}-${git.commit.id.abbrev}
author: "astei, ProxioDev"
# This is used so that we can automatically override default BungeeCord behavior.

View File

@ -27,9 +27,6 @@ import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.server.ServerPing;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.UnifiedJedis;
import java.net.InetAddress;
@ -159,7 +156,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
original = plugin.getPlayers();
} else {
try {
original = plugin.getApi().getPlayersOnServer(type);
original = plugin.getRedisBungeeApi().getPlayersOnServer(type);
} catch (IllegalArgumentException ignored) {
}
}
@ -177,7 +174,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
} else {
out.writeUTF(type);
try {
out.writeInt(plugin.getApi().getPlayersOnServer(type).size());
out.writeInt(plugin.getRedisBungeeApi().getPlayersOnServer(type).size());
} catch (IllegalArgumentException e) {
out.writeInt(0);
}
@ -187,12 +184,12 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
String user = in.readUTF();
out.writeUTF("LastOnline");
out.writeUTF(user);
out.writeLong(plugin.getApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
out.writeLong(plugin.getRedisBungeeApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
break;
case "ServerPlayers":
String type1 = in.readUTF();
out.writeUTF("ServerPlayers");
Multimap<String, UUID> multimap = plugin.getApi().getServerToPlayers();
Multimap<String, UUID> multimap = plugin.getRedisBungeeApi().getServerToPlayers();
boolean includesUsers;
@ -228,7 +225,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
String username = in.readUTF();
out.writeUTF("PlayerProxy");
out.writeUTF(username);
out.writeUTF(plugin.getApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
out.writeUTF(plugin.getRedisBungeeApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
break;
default:
return;
@ -243,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.getApi().getProxyId())) {
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getRedisBungeeApi().getProxyId())) {
String message = event.getMessage();
if (message.startsWith("/"))
message = message.substring(1);

View File

@ -96,10 +96,6 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
this.httpClient.setDispatcher(dispatcher);
NameFetcher.setHttpClient(httpClient);
UUIDFetcher.setHttpClient(httpClient);
// keeping this lol
new RedisBungee(api);
}
@ -134,7 +130,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
}
@Override
public RedisBungeeAPI getApi() {
public RedisBungeeAPI getRedisBungeeApi() {
return this.api;
}

View File

@ -2,11 +2,9 @@ package com.imaginarycode.minecraft.redisbungee.commands;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import com.google.common.base.Joiner;
import com.google.common.collect.HashMultimap;
@ -54,11 +52,11 @@ public class RedisBungeeCommands {
@Override
public void execute(final Invocation invocation) {
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
int count = plugin.getApi().getPlayerCount();
int count = plugin.getRedisBungeeApi().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.getApi().getServerToPlayers();
Multimap<String, UUID> serverToPlayers = plugin.getRedisBungeeApi().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.
@ -103,7 +101,7 @@ public class RedisBungeeCommands {
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
ServerInfo si = plugin.getProxy().getServer(plugin.getApi().getServerFor(uuid)).map(RegisteredServer::getServerInfo).orElse(null);
ServerInfo si = plugin.getProxy().getServer(plugin.getRedisBungeeApi().getServerFor(uuid)).map(RegisteredServer::getServerInfo).orElse(null);
if (si != null) {
Component message = Component.text(args[0] + " is on " + si.getName() + ".", NamedTextColor.BLUE);
sender.sendMessage(message);
@ -140,7 +138,7 @@ public class RedisBungeeCommands {
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
long secs = plugin.getApi().getLastOnline(uuid);
long secs = plugin.getRedisBungeeApi().getLastOnline(uuid);
TextComponent.Builder message = Component.text();
if (secs == 0) {
message.color(NamedTextColor.GREEN);
@ -183,7 +181,7 @@ public class RedisBungeeCommands {
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
InetAddress ia = plugin.getApi().getPlayerIp(uuid);
InetAddress ia = plugin.getRedisBungeeApi().getPlayerIp(uuid);
if (ia != null) {
TextComponent message = Component.text(args[0] + " is connected from " + ia.toString() + ".", NamedTextColor.GREEN);
sender.sendMessage(message);
@ -220,7 +218,7 @@ public class RedisBungeeCommands {
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
String proxy = plugin.getApi().getProxy(uuid);
String proxy = plugin.getRedisBungeeApi().getProxy(uuid);
if (proxy != null) {
TextComponent message = Component.text(args[0] + " is connected to " + proxy + ".", NamedTextColor.GREEN);
sender.sendMessage(message);
@ -253,7 +251,7 @@ public class RedisBungeeCommands {
CommandSource sender = invocation.source();
if (args.length > 0) {
String command = Joiner.on(" ").skipNulls().join(args);
plugin.getApi().sendProxyCommand(command);
plugin.getRedisBungeeApi().sendProxyCommand(command);
TextComponent message = Component.text("Sent the command /" + command + " to all proxies.", NamedTextColor.GREEN);
sender.sendMessage(message);
} else {
@ -276,7 +274,7 @@ public class RedisBungeeCommands {
@Override
public void execute(Invocation invocation) {
invocation.source().sendMessage(Component.text("You are on " + plugin.getApi().getProxyId() + ".", NamedTextColor.YELLOW));
invocation.source().sendMessage(Component.text("You are on " + plugin.getRedisBungeeApi().getProxyId() + ".", NamedTextColor.YELLOW));
}
@Override
@ -295,7 +293,7 @@ public class RedisBungeeCommands {
@Override
public void execute(Invocation invocation) {
invocation.source().sendMessage(
Component.text("All server IDs: " + Joiner.on(", ").join(plugin.getApi().getAllProxies()), NamedTextColor.YELLOW));
Component.text("All server IDs: " + Joiner.on(", ").join(plugin.getRedisBungeeApi().getAllProxies()), NamedTextColor.YELLOW));
}
@Override
@ -321,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.getApi().getPlayersOnProxy(proxy);
Set<UUID> players = plugin.getRedisBungeeApi().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.getApi().getServerToPlayers();
Multimap<String, UUID> serverToPlayers = plugin.getRedisBungeeApi().getServerToPlayers();
Multimap<String, String> human = HashMultimap.create();
serverToPlayers.forEach((key, value) -> {
if (players.contains(value)) {