mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-04-09 00:20:26 +00:00
last bug was caused by confusion due Proxy Called server in some cases Which resulted in new API methods and some refactor
This commit is contained in:
@@ -21,7 +21,6 @@ import java.util.*;
|
||||
*
|
||||
* @author tuxed
|
||||
* @since 0.2.3 | updated 0.7.0
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class RedisBungeeAPI {
|
||||
@@ -34,7 +33,7 @@ public class RedisBungeeAPI {
|
||||
redisBungeeApi = this;
|
||||
this.reservedChannels = ImmutableList.of(
|
||||
"redisbungee-allservers",
|
||||
"redisbungee-" + plugin.getConfiguration().getServerId(),
|
||||
"redisbungee-" + plugin.getConfiguration().getProxyId(),
|
||||
"redisbungee-data"
|
||||
);
|
||||
new RedisBungee(this);
|
||||
@@ -175,8 +174,8 @@ public class RedisBungeeAPI {
|
||||
*
|
||||
* @param proxyId a proxy ID
|
||||
* @param command the command to send and execute
|
||||
* @see #getServerId()
|
||||
* @see #getAllServers()
|
||||
* @see #getProxyId()
|
||||
* @see #getAllProxies()
|
||||
* @since 0.2.5
|
||||
*/
|
||||
public final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
|
||||
@@ -196,14 +195,38 @@ public class RedisBungeeAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current BungeeCord server ID for this server.
|
||||
* Get the current BungeeCord / Velocity proxy ID for this server.
|
||||
*
|
||||
* @return the current server ID
|
||||
* @see #getAllProxies()
|
||||
* @since 0.8.0
|
||||
*/
|
||||
public final String getProxyId() {
|
||||
return plugin.getConfiguration().getProxyId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current BungeeCord / Velocity proxy ID for this server.
|
||||
*
|
||||
* @return the current server ID
|
||||
* @see #getAllServers()
|
||||
* @since 0.2.5
|
||||
* @deprecated to avoid confusion between A server and A proxy see #getProxyId()
|
||||
*/
|
||||
@Deprecated
|
||||
public final String getServerId() {
|
||||
return plugin.getConfiguration().getServerId();
|
||||
return getProxyId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the linked proxies in this network.
|
||||
*
|
||||
* @return the list of all proxies
|
||||
* @see #getProxyId()
|
||||
* @since 0.8.0
|
||||
*/
|
||||
public final List<String> getAllProxies() {
|
||||
return plugin.getProxiesIds();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,9 +235,11 @@ public class RedisBungeeAPI {
|
||||
* @return the list of all proxies
|
||||
* @see #getServerId()
|
||||
* @since 0.2.5
|
||||
* @deprecated to avoid confusion between A server and A proxy see see {@link #getAllProxies()}
|
||||
*/
|
||||
@Deprecated
|
||||
public final List<String> getAllServers() {
|
||||
return plugin.getServerIds();
|
||||
return getAllProxies();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +263,7 @@ public class RedisBungeeAPI {
|
||||
Preconditions.checkArgument(!reservedChannels.contains(channel), "attempting to unregister internal channel");
|
||||
}
|
||||
|
||||
plugin.getPubSubListener().removeChannel(channels);
|
||||
plugin.getPubSubListener().removeChannel(channels);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -310,6 +335,7 @@ public class RedisBungeeAPI {
|
||||
|
||||
/**
|
||||
* This gives you instance of Jedis
|
||||
*
|
||||
* @return {@link Jedis}
|
||||
* @since 0.7.0
|
||||
*/
|
||||
@@ -320,10 +346,12 @@ public class RedisBungeeAPI {
|
||||
throw new RuntimeException("RedisBungee is on Cluster MODE!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets Redis Bungee {@link JedisPool}
|
||||
*
|
||||
* @return {@link JedisPool}
|
||||
* @since 0.6.5
|
||||
* @since 0.6.5
|
||||
*/
|
||||
public JedisPool getJedisPool() {
|
||||
if (getMode() == RedisBungeeMode.SINGLE) {
|
||||
@@ -345,6 +373,7 @@ public class RedisBungeeAPI {
|
||||
|
||||
/**
|
||||
* This gives you instance of Jedis Cluster
|
||||
*
|
||||
* @return {@link redis.clients.jedis.JedisCluster}
|
||||
* @since 0.8.0
|
||||
*/
|
||||
@@ -358,6 +387,7 @@ public class RedisBungeeAPI {
|
||||
|
||||
/**
|
||||
* shows what mode is RedisBungee is on
|
||||
*
|
||||
* @return {@link RedisBungeeMode}
|
||||
* @since 0.8.0
|
||||
*/
|
||||
@@ -368,6 +398,7 @@ public class RedisBungeeAPI {
|
||||
|
||||
/**
|
||||
* Api instance
|
||||
*
|
||||
* @return the API instance.
|
||||
* @since 0.6.5
|
||||
*/
|
||||
|
||||
@@ -79,7 +79,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
|
||||
P player = plugin.getPlayer(uuid);
|
||||
|
||||
if (player != null)
|
||||
return plugin.getConfiguration().getServerId();
|
||||
return plugin.getConfiguration().getProxyId();
|
||||
|
||||
try {
|
||||
return proxyCache.get(uuid, new RedisTask<String>(plugin.getApi()) {
|
||||
@@ -183,7 +183,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
|
||||
|
||||
String source = jsonObject.get("source").getAsString();
|
||||
|
||||
if (source.equals(plugin.getConfiguration().getServerId()))
|
||||
if (source.equals(plugin.getConfiguration().getProxyId()))
|
||||
return;
|
||||
|
||||
DataManagerMessage.Action action = DataManagerMessage.Action.valueOf(jsonObject.get("action").getAsString());
|
||||
|
||||
@@ -27,7 +27,7 @@ public class PubSubListener implements Runnable {
|
||||
public Void jedisTask(Jedis jedis) {
|
||||
try {
|
||||
jpsh = new JedisPubSubHandler(plugin);
|
||||
addedChannels.add("redisbungee-" + plugin.getConfiguration().getServerId());
|
||||
addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId());
|
||||
addedChannels.add("redisbungee-allservers");
|
||||
addedChannels.add("redisbungee-data");
|
||||
jedis.subscribe(jpsh, addedChannels.toArray(new String[0]));
|
||||
@@ -51,7 +51,7 @@ public class PubSubListener implements Runnable {
|
||||
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||
try {
|
||||
jpsh = new JedisPubSubHandler(plugin);
|
||||
addedChannels.add("redisbungee-" + plugin.getConfiguration().getServerId());
|
||||
addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId());
|
||||
addedChannels.add("redisbungee-allservers");
|
||||
addedChannels.add("redisbungee-data");
|
||||
jedisCluster.subscribe(jpsh, addedChannels.toArray(new String[0]));
|
||||
|
||||
@@ -7,13 +7,13 @@ import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
|
||||
public class RedisBungeeConfiguration {
|
||||
private final String serverId;
|
||||
private final String proxyId;
|
||||
private final List<InetAddress> exemptAddresses;
|
||||
private final boolean overrideBungeeCommands;
|
||||
private static RedisBungeeConfiguration config;
|
||||
|
||||
public RedisBungeeConfiguration(String serverId, List<String> exemptAddresses, boolean overrideBungeeCommands) {
|
||||
this.serverId = serverId;
|
||||
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean overrideBungeeCommands) {
|
||||
this.proxyId = proxyId;
|
||||
|
||||
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
|
||||
for (String s : exemptAddresses) {
|
||||
@@ -24,8 +24,8 @@ public class RedisBungeeConfiguration {
|
||||
this.overrideBungeeCommands = overrideBungeeCommands;
|
||||
}
|
||||
|
||||
public String getServerId() {
|
||||
return serverId;
|
||||
public String getProxyId() {
|
||||
return proxyId;
|
||||
}
|
||||
|
||||
public List<InetAddress> getExemptAddresses() {
|
||||
|
||||
@@ -52,9 +52,9 @@ public interface RedisBungeePlugin<P> extends EventsPlatform {
|
||||
|
||||
void sendProxyCommand(String serverId, String command);
|
||||
|
||||
List<String> getServerIds();
|
||||
List<String> getProxiesIds();
|
||||
|
||||
List<String> getCurrentServerIds(boolean nag, boolean lagged);
|
||||
List<String> getCurrentProxiesIds(boolean nag, boolean lagged);
|
||||
|
||||
PubSubListener getPubSubListener();
|
||||
|
||||
|
||||
@@ -15,31 +15,31 @@ public class RedisUtil {
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
public static void cleanUpPlayer(String player, Jedis rsc) {
|
||||
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", player);
|
||||
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", player);
|
||||
rsc.hdel("player:" + player, "server", "ip", "proxy");
|
||||
long timestamp = System.currentTimeMillis();
|
||||
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
|
||||
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
|
||||
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
|
||||
new AbstractDataManager.LogoutPayload(timestamp))));
|
||||
}
|
||||
|
||||
public static void cleanUpPlayer(String player, Pipeline rsc) {
|
||||
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", player);
|
||||
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", player);
|
||||
rsc.hdel("player:" + player, "server", "ip", "proxy");
|
||||
long timestamp = System.currentTimeMillis();
|
||||
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
|
||||
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
|
||||
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
|
||||
new AbstractDataManager.LogoutPayload(timestamp))));
|
||||
}
|
||||
public static void cleanUpPlayer(String player, JedisCluster rsc) {
|
||||
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", player);
|
||||
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", player);
|
||||
rsc.hdel("player:" + player, "server", "ip", "proxy");
|
||||
long timestamp = System.currentTimeMillis();
|
||||
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
|
||||
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
|
||||
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
|
||||
new AbstractDataManager.LogoutPayload(timestamp))));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user