2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2026-04-08 16:10:26 +00:00

make RedisBungeeAPI class platform dependant and make Abstract version of it

This commit is contained in:
2022-07-27 17:43:51 +04:00
parent 576bcc39d2
commit 17897bc112
18 changed files with 163 additions and 102 deletions

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -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())) {