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

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

View File

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

View File

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

View File

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

View File

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