2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2026-05-03 11:40:29 +00:00

7 Commits

4 changed files with 29 additions and 15 deletions

View File

@@ -224,7 +224,7 @@ public abstract class AbstractRedisBungeeAPI {
* @since 0.2.5 * @since 0.2.5
* @deprecated to avoid confusion between A server and A proxy see #getProxyId() * @deprecated to avoid confusion between A server and A proxy see #getProxyId()
*/ */
@Deprecated @Deprecated(forRemoval = true)
public final String getServerId() { public final String getServerId() {
return getProxyId(); return getProxyId();
} }
@@ -248,7 +248,7 @@ public abstract class AbstractRedisBungeeAPI {
* @since 0.2.5 * @since 0.2.5
* @deprecated to avoid confusion between A server and A proxy see see {@link #getAllProxies()} * @deprecated to avoid confusion between A server and A proxy see see {@link #getAllProxies()}
*/ */
@Deprecated @Deprecated(forRemoval = true)
public final List<String> getAllServers() { public final List<String> getAllServers() {
return getAllProxies(); return getAllProxies();
} }
@@ -260,7 +260,7 @@ public abstract class AbstractRedisBungeeAPI {
* @since 0.3 * @since 0.3
* @deprecated No longer required * @deprecated No longer required
*/ */
@Deprecated @Deprecated(forRemoval = true)
public final void registerPubSubChannels(String... channels) { public final void registerPubSubChannels(String... channels) {
} }
@@ -271,7 +271,7 @@ public abstract class AbstractRedisBungeeAPI {
* @since 0.3 * @since 0.3
* @deprecated No longer required * @deprecated No longer required
*/ */
@Deprecated @Deprecated(forRemoval = true)
public final void unregisterPubSubChannels(String... channels) { public final void unregisterPubSubChannels(String... channels) {
} }
@@ -352,7 +352,7 @@ public abstract class AbstractRedisBungeeAPI {
* @since 0.8.0 * @since 0.8.0
* @deprecated * @deprecated
*/ */
@Deprecated @Deprecated(forRemoval = true)
public void kickPlayer(String playerName, String message) { public void kickPlayer(String playerName, String message) {
kickPlayer(getUuidFromName(playerName), message); kickPlayer(getUuidFromName(playerName), message);
} }
@@ -365,7 +365,7 @@ public abstract class AbstractRedisBungeeAPI {
* @since 0.8.0 * @since 0.8.0
* @deprecated * @deprecated
*/ */
@Deprecated @Deprecated(forRemoval = true)
public void kickPlayer(UUID playerUUID, String message) { public void kickPlayer(UUID playerUUID, String message) {
kickPlayer(playerUUID, Component.text(message)); kickPlayer(playerUUID, Component.text(message));
} }
@@ -402,7 +402,9 @@ public abstract class AbstractRedisBungeeAPI {
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE} * @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE}
* @see #getJedisPool() * @see #getJedisPool()
* @since 0.7.0 * @since 0.7.0
* @deprecated use {@link #getSummoner() }
*/ */
@Deprecated(forRemoval = true)
public Jedis requestJedis() { public Jedis requestJedis() {
if (getMode() == RedisBungeeMode.SINGLE) { if (getMode() == RedisBungeeMode.SINGLE) {
return getJedisPool().getResource(); return getJedisPool().getResource();
@@ -438,7 +440,9 @@ public abstract class AbstractRedisBungeeAPI {
* @return {@link redis.clients.jedis.JedisCluster} * @return {@link redis.clients.jedis.JedisCluster}
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#CLUSTER} * @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#CLUSTER}
* @since 0.8.0 * @since 0.8.0
* @deprecated use {@link #getSummoner()}
*/ */
@Deprecated(forRemoval = true)
public JedisCluster requestClusterJedis() { public JedisCluster requestClusterJedis() {
if (getMode() == RedisBungeeMode.CLUSTER) { if (getMode() == RedisBungeeMode.CLUSTER) {
return ((JedisClusterSummoner) this.plugin.getSummoner()).obtainResource(); return ((JedisClusterSummoner) this.plugin.getSummoner()).obtainResource();
@@ -454,7 +458,9 @@ public abstract class AbstractRedisBungeeAPI {
* @return {@link redis.clients.jedis.JedisPooled} * @return {@link redis.clients.jedis.JedisPooled}
* @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE} * @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE}
* @since 0.8.0 * @since 0.8.0
* @deprecated use {@link #getSummoner()}
*/ */
@Deprecated(forRemoval = true)
public JedisPooled requestJedisPooled() { public JedisPooled requestJedisPooled() {
if (getMode() == RedisBungeeMode.SINGLE) { if (getMode() == RedisBungeeMode.SINGLE) {
return ((JedisPooledSummoner) this.plugin.getSummoner()).obtainResource(); return ((JedisPooledSummoner) this.plugin.getSummoner()).obtainResource();

View File

@@ -37,15 +37,16 @@ import java.util.concurrent.TimeUnit;
public abstract class PlayerDataManager<P, LE, DE, PS extends IPubSubMessageEvent, SC extends IPlayerChangedServerNetworkEvent, NJE extends IPlayerLeftNetworkEvent, CE> { public abstract class PlayerDataManager<P, LE, DE, PS extends IPubSubMessageEvent, SC extends IPlayerChangedServerNetworkEvent, NJE extends IPlayerLeftNetworkEvent, CE> {
protected final RedisBungeePlugin<P> plugin; protected final RedisBungeePlugin<P> plugin;
private final LoadingCache<UUID, String> serverCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build(this::getServerFromRedis);
private final LoadingCache<UUID, String> lastServerCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build(this::getLastServerFromRedis);
private final LoadingCache<UUID, String> proxyCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build(this::getProxyFromRedis);
private final LoadingCache<UUID, InetAddress> ipCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build(this::getIpAddressFromRedis);
private final Object SERVERS_TO_PLAYERS_KEY = new Object(); private final Object SERVERS_TO_PLAYERS_KEY = new Object();
private final LoadingCache<Object, Multimap<String, UUID>> serverToPlayersCache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build(this::serversToPlayersBuilder);
private final UnifiedJedis unifiedJedis; private final UnifiedJedis unifiedJedis;
private final String proxyId; private final String proxyId;
private final String networkId; private final String networkId;
private final LoadingCache<UUID, String> serverCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getServerFromRedis);
private final LoadingCache<UUID, String> lastServerCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getLastServerFromRedis);
private final LoadingCache<UUID, String> proxyCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getProxyFromRedis);
private final LoadingCache<UUID, InetAddress> ipCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getIpAddressFromRedis);
private final LoadingCache<Object, Multimap<String, UUID>> serverToPlayersCache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build(this::serversToPlayersBuilder);
private final JSONComponentSerializer COMPONENT_SERIALIZER = JSONComponentSerializer.json();
public PlayerDataManager(RedisBungeePlugin<P> plugin) { public PlayerDataManager(RedisBungeePlugin<P> plugin) {
this.plugin = plugin; this.plugin = plugin;
@@ -69,16 +70,21 @@ public abstract class PlayerDataManager<P, LE, DE, PS extends IPubSubMessageEven
public abstract void onDisconnectEvent(DE event); public abstract void onDisconnectEvent(DE event);
protected void handleNetworkPlayerServerChange(IPlayerChangedServerNetworkEvent event) { protected void handleNetworkPlayerServerChange(IPlayerChangedServerNetworkEvent event) {
this.serverCache.invalidate(event.getUuid()); this.serverCache.invalidate(event.getUuid());
this.lastServerCache.invalidate(event.getUuid()); this.lastServerCache.invalidate(event.getUuid());
//TODO: We could also rely on redisbungee-serverchange pubsub messages to update the cache in-place without querying redis. That would be a lot more efficient.
this.serverToPlayersCache.invalidate(SERVERS_TO_PLAYERS_KEY);
} }
protected void handleNetworkPlayerQuit(IPlayerLeftNetworkEvent event) { protected void handleNetworkPlayerQuit(IPlayerLeftNetworkEvent event) {
this.proxyCache.invalidate(event.getUuid()); this.proxyCache.invalidate(event.getUuid());
this.serverCache.invalidate(event.getUuid()); this.serverCache.invalidate(event.getUuid());
this.ipCache.invalidate(event.getUuid()); this.ipCache.invalidate(event.getUuid());
//TODO: We could also rely on redisbungee-serverchange pubsub messages to update the cache in-place without querying redis. That would be a lot more efficient.
this.serverToPlayersCache.invalidate(SERVERS_TO_PLAYERS_KEY);
} }
protected void handlePubSubMessageEvent(IPubSubMessageEvent event) { protected void handlePubSubMessageEvent(IPubSubMessageEvent event) {
@@ -140,8 +146,6 @@ public abstract class PlayerDataManager<P, LE, DE, PS extends IPubSubMessageEven
handleServerChangeRedis(uuid, to); handleServerChangeRedis(uuid, to);
} }
private final JSONComponentSerializer COMPONENT_SERIALIZER =JSONComponentSerializer.json();
public void kickPlayer(UUID uuid, Component message) { public void kickPlayer(UUID uuid, Component message) {
if (!plugin.handlePlatformKick(uuid, message)) { // handle locally before SENDING a message if (!plugin.handlePlatformKick(uuid, message)) { // handle locally before SENDING a message
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
@@ -213,6 +217,7 @@ public abstract class PlayerDataManager<P, LE, DE, PS extends IPubSubMessageEven
public String getLastServerFor(UUID uuid) { public String getLastServerFor(UUID uuid) {
return this.lastServerCache.get(uuid); return this.lastServerCache.get(uuid);
} }
public String getServerFor(UUID uuid) { public String getServerFor(UUID uuid) {
return this.serverCache.get(uuid); return this.serverCache.get(uuid);
} }

View File

@@ -88,6 +88,9 @@ public abstract class ProxyDataManager implements Runnable {
public synchronized void sendCommandTo(String proxyToRun, String command) { public synchronized void sendCommandTo(String proxyToRun, String command) {
if (isClosed()) return; if (isClosed()) return;
if (proxyToRun.equals("allservers") || proxyToRun.equals(this.proxyId())) {
handlePlatformCommandExecution(command);
}
publishPayload(new RunCommandPayload(this.proxyId, proxyToRun, command)); publishPayload(new RunCommandPayload(this.proxyId, proxyToRun, command));
} }

View File

@@ -1,2 +1,2 @@
group=com.imaginarycode.minecraft group=com.imaginarycode.minecraft
version=0.12.3-SNAPSHOT version=0.12.4