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

General improvements, remove player cleanup from RedisUtils class and bug fixes

fixed bug where PlayerNetoworkJoin is not fireing, and also fixed wrong arguments being passed on server change network event, Moved Payload creation to it own Util class, Remove player creation from RedisUtils class and move it to GenericPlayerUtils, and also renamed Bungeecord/Velocity Player Util classes to <PLATFORM>PlayerUtils.java, removed the use of reflection to create event instances
This commit is contained in:
mohammed jasem alaajel 2022-07-20 12:32:04 +04:00
parent 17e6e12c24
commit 4d3f1a551e
11 changed files with 180 additions and 168 deletions

View File

@ -190,20 +190,14 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
switch (action) {
case JOIN:
final DataManagerMessage<LoginPayload> message1 = gson.fromJson(jsonObject, new TypeToken<DataManagerMessage<LoginPayload>>() {}.getType());
final DataManagerMessage<LoginPayload> message1 = gson.fromJson(jsonObject, new TypeToken<DataManagerMessage<LoginPayload>>() {
}.getType());
proxyCache.put(message1.getTarget(), message1.getSource());
lastOnlineCache.put(message1.getTarget(), (long) 0);
ipCache.put(message1.getTarget(), message1.getPayload().getAddress());
plugin.executeAsync(() -> {
Object event;
try {
event = plugin.getNetworkJoinEventClass().getDeclaredConstructor(UUID.class).newInstance(message1.getTarget());
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException e) {
throw new RuntimeException("unable to dispatch an network join event", e);
}
Object event = plugin.createPlayerJoinedNetworkEvent(message1.getTarget());
plugin.callEvent(event);
});
break;
case LEAVE:
@ -212,32 +206,22 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
invalidate(message2.getTarget());
lastOnlineCache.put(message2.getTarget(), message2.getPayload().getTimestamp());
plugin.executeAsync(() -> {
Object event;
try {
event = plugin.getNetworkQuitEventClass().getDeclaredConstructor(UUID.class).newInstance(message2.getTarget());
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException e) {
throw new RuntimeException("unable to dispatch an network quit event", e);
}
Object event = plugin.createPlayerLeftNetworkEvent(message2.getTarget());
plugin.callEvent(event);
});
break;
case SERVER_CHANGE:
final DataManagerMessage<ServerChangePayload> message3 = gson.fromJson(jsonObject, new TypeToken<DataManagerMessage<ServerChangePayload>>() {}.getType());
final DataManagerMessage<ServerChangePayload> message3 = gson.fromJson(jsonObject, new TypeToken<DataManagerMessage<ServerChangePayload>>() {
}.getType());
serverCache.put(message3.getTarget(), message3.getPayload().getServer());
plugin.executeAsync(() -> {
Object event;
try {
event = plugin.getServerChangeEventClass().getDeclaredConstructor(UUID.class, String.class, String.class).newInstance(message3.getTarget(), ((ServerChangePayload) message3.getPayload()).getOldServer(), ((ServerChangePayload) message3.getPayload()).getServer());
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException e) {
throw new RuntimeException("unable to dispatch an server change event", e);
}
Object event = plugin.createPlayerChangedNetworkEvent(message3.getTarget(), message3.getPayload().getOldServer(), message3.getPayload().getServer());
plugin.callEvent(event);
});
break;
case KICK:
final DataManagerMessage<KickPayload> kickPayload = gson.fromJson(jsonObject, new TypeToken<DataManagerMessage<KickPayload>>() {}.getType());
final DataManagerMessage<KickPayload> kickPayload = gson.fromJson(jsonObject, new TypeToken<DataManagerMessage<KickPayload>>() {
}.getType());
plugin.executeAsync(() -> handleKick(kickPayload.target, kickPayload.payload.message));
break;
@ -281,7 +265,8 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
}
}
public static abstract class Payload {}
public static abstract class Payload {
}
public static class KickPayload extends Payload {

View File

@ -1,5 +1,7 @@
package com.imaginarycode.minecraft.redisbungee.api;
import java.util.UUID;
/**
* Since each platform have their own events' implementation for example Bungeecord events extends Event while velocity don't
*
@ -9,12 +11,13 @@ package com.imaginarycode.minecraft.redisbungee.api;
*/
public interface EventsPlatform {
Class<?> getPubSubEventClass();
Object createPlayerChangedNetworkEvent(UUID uuid, String previousServer, String server);
Class<?> getNetworkJoinEventClass();
Object createPlayerJoinedNetworkEvent(UUID uuid);
Class<?> getServerChangeEventClass();
Object createPlayerLeftNetworkEvent(UUID uuid);
Object createPubSubEvent(String channel, String message);
Class<?> getNetworkQuitEventClass();
}

View File

@ -0,0 +1,40 @@
package com.imaginarycode.minecraft.redisbungee.api;
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.Pipeline;
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerQuitPayload;
public class GenericPlayerUtils {
public static void cleanUpPlayer(String uuid, Jedis rsc) {
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", uuid);
rsc.hdel("player:" + uuid, "server", "ip", "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + uuid, "online", String.valueOf(timestamp));
playerQuitPayload(uuid, rsc, timestamp);
}
public static void cleanUpPlayer(String uuid, Pipeline rsc) {
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", uuid);
rsc.hdel("player:" + uuid, "server", "ip", "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + uuid, "online", String.valueOf(timestamp));
playerQuitPayload(uuid, rsc, timestamp);
}
public static void cleanUpPlayer(String uuid, JedisCluster rsc) {
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", uuid);
rsc.hdel("player:" + uuid, "server", "ip", "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + uuid, "online", String.valueOf(timestamp));
playerQuitPayload(uuid, rsc, timestamp);
}
}

View File

@ -9,10 +9,9 @@ import java.lang.reflect.InvocationTargetException;
public class JedisPubSubHandler extends JedisPubSub {
private final RedisBungeePlugin<?> plugin;
private final Class<?> eventClass;
public JedisPubSubHandler(RedisBungeePlugin<?> plugin) {
this.plugin = plugin;
this.eventClass = plugin.getPubSubEventClass();
}
@Override
@ -21,12 +20,7 @@ public class JedisPubSubHandler extends JedisPubSub {
plugin.executeAsync(new Runnable() {
@Override
public void run() {
Object event;
try {
event = eventClass.getDeclaredConstructor(String.class, String.class).newInstance(s, s2);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException("unable to dispatch an pubsub event", e);
}
Object event = plugin.createPubSubEvent(s, s2);
plugin.callEvent(event);
}
});

View File

@ -7,54 +7,81 @@ import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.Pipeline;
import java.net.InetAddress;
import java.util.UUID;
public class PayloadUtils {
private static final Gson gson = new Gson();
public static void cleanUpPlayer(String uuid, Jedis rsc) {
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", uuid);
rsc.hdel("player:" + uuid, "server", "ip", "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + uuid, "online", String.valueOf(timestamp));
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
public static void playerJoinPayload(UUID uuid, Pipeline pipeline, InetAddress inetAddress) {
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(inetAddress))));
}
public static void playerJoinPayload(UUID uuid, JedisCluster jedisCluster, InetAddress inetAddress) {
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(inetAddress))));
}
public static void playerJoinPayload(UUID uuid, Jedis jedis, InetAddress inetAddress) {
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(inetAddress))));
}
public static void playerQuitPayload(String uuid, Jedis jedis, long timestamp) {
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
UUID.fromString(uuid), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
new AbstractDataManager.LogoutPayload(timestamp))));
}
public static void cleanUpPlayer(String uuid, Pipeline rsc) {
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", uuid);
rsc.hdel("player:" + uuid, "server", "ip", "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + uuid, "online", String.valueOf(timestamp));
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
public static void playerQuitPayload(String uuid, JedisCluster jedisCluster, long timestamp) {
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
UUID.fromString(uuid), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
new AbstractDataManager.LogoutPayload(timestamp))));
}
public static void cleanUpPlayer(String uuid, JedisCluster rsc) {
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", uuid);
rsc.hdel("player:" + uuid, "server", "ip", "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + uuid, "online", String.valueOf(timestamp));
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
public static void playerQuitPayload(String uuid, Pipeline pipeline, long timestamp) {
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
UUID.fromString(uuid), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
new AbstractDataManager.LogoutPayload(timestamp))));
}
public static void kickPlayer(UUID uuid, String message, Pipeline pipeline) {
public static void playerServerChangePayload(UUID uuid, Jedis jedis, String newServer, String oldServer) {
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(newServer, oldServer))));
}
public static void playerServerChangePayload(UUID uuid, Pipeline pipeline, String newServer, String oldServer) {
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(newServer, oldServer))));
}
public static void playerServerChangePayload(UUID uuid, JedisCluster jedisCluster, String newServer, String oldServer) {
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(newServer, oldServer))));
}
public static void kickPlayerPayload(UUID uuid, String message, Pipeline pipeline) {
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.KICK,
new AbstractDataManager.KickPayload(message))));
}
public static void kickPlayer(UUID uuid, String message, Jedis jedis) {
public static void kickPlayerPayload(UUID uuid, String message, Jedis jedis) {
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.KICK,
new AbstractDataManager.KickPayload(message))));
}
public static void kickPlayer(UUID uuid, String message, JedisCluster jedisCluster) {
public static void kickPlayerPayload(UUID uuid, String message, JedisCluster jedisCluster) {
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
uuid, RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.KICK,
new AbstractDataManager.KickPayload(message))));

View File

@ -1,7 +1,6 @@
package com.imaginarycode.minecraft.redisbungee;
import com.google.gson.Gson;
import com.imaginarycode.minecraft.redisbungee.api.AbstractDataManager;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import redis.clients.jedis.JedisCluster;
@ -10,17 +9,17 @@ import redis.clients.jedis.Pipeline;
import java.util.HashMap;
import java.util.Map;
public class PlayerUtils {
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerJoinPayload;
private static final Gson gson = new Gson();
public class BungeePlayerUtils {
protected static void createPlayer(ProxiedPlayer player, Pipeline pipeline, boolean fireEvent) {
public static void createPlayer(ProxiedPlayer player, Pipeline pipeline, boolean fireEvent) {
createPlayer(player.getPendingConnection(), pipeline, fireEvent);
if (player.getServer() != null)
pipeline.hset("player:" + player.getUniqueId().toString(), "server", player.getServer().getInfo().getName());
}
protected static void createPlayer(PendingConnection connection, Pipeline pipeline, boolean fireEvent) {
public static void createPlayer(PendingConnection connection, Pipeline pipeline, boolean fireEvent) {
Map<String, String> playerData = new HashMap<>(4);
playerData.put("online", "0");
playerData.put("ip", connection.getAddress().getAddress().getHostAddress());
@ -30,19 +29,17 @@ public class PlayerUtils {
pipeline.hmset("player:" + connection.getUniqueId().toString(), playerData);
if (fireEvent) {
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
connection.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(connection.getAddress().getAddress()))));
playerJoinPayload(connection.getUniqueId(), pipeline, connection.getAddress().getAddress());
}
}
protected static void createPlayer(ProxiedPlayer player, JedisCluster jedisCluster, boolean fireEvent) {
public static void createPlayer(ProxiedPlayer player, JedisCluster jedisCluster, boolean fireEvent) {
createPlayer(player.getPendingConnection(), jedisCluster, fireEvent);
if (player.getServer() != null)
jedisCluster.hset("player:" + player.getUniqueId().toString(), "server", player.getServer().getInfo().getName());
}
protected static void createPlayer(PendingConnection connection, JedisCluster jedisCluster, boolean fireEvent) {
public static void createPlayer(PendingConnection connection, JedisCluster jedisCluster, boolean fireEvent) {
Map<String, String> playerData = new HashMap<>(4);
playerData.put("online", "0");
playerData.put("ip", connection.getAddress().getAddress().getHostAddress());
@ -52,9 +49,7 @@ public class PlayerUtils {
jedisCluster.hmset("player:" + connection.getUniqueId().toString(), playerData);
if (fireEvent) {
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
connection.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(connection.getAddress().getAddress()))));
playerJoinPayload(connection.getUniqueId(), jedisCluster, connection.getAddress().getAddress());
}
}

View File

@ -8,6 +8,7 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.imaginarycode.minecraft.redisbungee.api.AbstractRedisBungeeListener;
import com.imaginarycode.minecraft.redisbungee.api.AbstractDataManager;
import com.imaginarycode.minecraft.redisbungee.api.GenericPlayerUtils;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
import com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils;
@ -120,30 +121,18 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
// which will register the player into the redis database.
Pipeline pipeline = jedis.pipelined();
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), pipeline);
PlayerUtils.createPlayer(event.getPlayer(), pipeline, false);
BungeePlayerUtils.createPlayer(event.getPlayer(), pipeline, true);
pipeline.sync();
// the end of moved code.
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
return null;
}
@Override
public Void clusterJedisTask(JedisCluster jedisCluster) {
// this code was moved out from login event due being async..
// and it can be cancelled but it will show as false in redis-bungee
// which will register the player into the redis database.
// due no support to pipeline in jedis cluster just use the instance instead.
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), jedisCluster);
PlayerUtils.createPlayer(event.getPlayer(), jedisCluster, false);
// the end of moved code.
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
BungeePlayerUtils.createPlayer(event.getPlayer(), jedisCluster, true);
return null;
}
});
@ -158,7 +147,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
@Override
public Void jedisTask(Jedis jedis) {
Pipeline pipeline = jedis.pipelined();
PayloadUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), pipeline);
GenericPlayerUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), pipeline);
pipeline.sync();
return null;
}
@ -166,7 +155,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
@Override
public Void clusterJedisTask(JedisCluster jedisCluster) {
// Due some reason JedisCluster does not support pipeline, use instance instead
PayloadUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), jedisCluster);
GenericPlayerUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), jedisCluster);
return null;
}
});
@ -177,22 +166,19 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
@EventHandler
public void onServerChange(ServerConnectedEvent event) {
final String currentServer = event.getPlayer().getServer() == null ? null : event.getPlayer().getServer().getInfo().getName();
final String oldServer = event.getPlayer().getServer() == null ? null : event.getPlayer().getServer().getInfo().getName();
plugin.executeAsync(new RedisTask<Void>(plugin) {
@Override
public Void jedisTask(Jedis jedis) {
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(event.getServer().getInfo().getName(), currentServer))));
PayloadUtils.playerServerChangePayload(event.getPlayer().getUniqueId(), jedis, currentServer, oldServer);
return null;
}
@Override
public Void clusterJedisTask(JedisCluster jedisCluster) {
jedisCluster.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(event.getServer().getInfo().getName(), currentServer))));
PayloadUtils.playerServerChangePayload(event.getPlayer().getUniqueId(), jedisCluster, currentServer, oldServer);
return null;
}
});

View File

@ -15,6 +15,7 @@ import com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils;
import com.imaginarycode.minecraft.redisbungee.commands.RedisBungeeCommands;
import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent;
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent;
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import com.imaginarycode.minecraft.redisbungee.api.*;
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
@ -665,7 +666,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
if (!laggedPlayers.isEmpty()) {
getLogger().info("Cleaning up lagged proxy " + s + " (" + laggedPlayers.size() + " players)...");
for (String laggedPlayer : laggedPlayers) {
PayloadUtils.cleanUpPlayer(laggedPlayer, jedis);
GenericPlayerUtils.cleanUpPlayer(laggedPlayer, jedis);
}
}
}
@ -686,7 +687,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
}
}
if (!found) {
PayloadUtils.cleanUpPlayer(member, jedis);
GenericPlayerUtils.cleanUpPlayer(member, jedis);
getLogger().warning("Player found in set that was not found locally and globally: " + member);
} else {
jedis.srem("proxy:" + configuration.getProxyId() + ":usersOnline", member);
@ -704,7 +705,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
if (proxiedPlayer == null)
continue; // We'll deal with it later.
PlayerUtils.createPlayer(proxiedPlayer, pipeline, true);
BungeePlayerUtils.createPlayer(proxiedPlayer, pipeline, true);
}
pipeline.sync();
@ -728,7 +729,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
if (!laggedPlayers.isEmpty()) {
getLogger().info("Cleaning up lagged proxy " + s + " (" + laggedPlayers.size() + " players)...");
for (String laggedPlayer : laggedPlayers) {
PayloadUtils.cleanUpPlayer(laggedPlayer, jedisCluster);
GenericPlayerUtils.cleanUpPlayer(laggedPlayer, jedisCluster);
}
}
}
@ -749,7 +750,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
}
}
if (!found) {
PayloadUtils.cleanUpPlayer(member, jedisCluster);
GenericPlayerUtils.cleanUpPlayer(member, jedisCluster);
getLogger().warning("Player found in set that was not found locally and globally: " + member);
} else {
jedisCluster.srem("proxy:" + configuration.getProxyId() + ":usersOnline", member);
@ -767,7 +768,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
if (proxiedPlayer == null)
continue; // We'll deal with it later.
PlayerUtils.createPlayer(proxiedPlayer, jedisCluster, true);
BungeePlayerUtils.createPlayer(proxiedPlayer, jedisCluster, true);
}
} catch (Throwable e) {
@ -818,7 +819,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
if (jedis.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
Set<String> players = jedis.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
for (String member : players)
PayloadUtils.cleanUpPlayer(member, jedis);
GenericPlayerUtils.cleanUpPlayer(member, jedis);
}
return null;
}
@ -829,7 +830,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
if (jedisCluster.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
Set<String> players = jedisCluster.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
for (String member : players)
PayloadUtils.cleanUpPlayer(member, jedisCluster);
GenericPlayerUtils.cleanUpPlayer(member, jedisCluster);
}
return null;
}
@ -923,13 +924,13 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
new RedisTask<Void>(api) {
@Override
public Void jedisTask(Jedis jedis) {
PayloadUtils.kickPlayer(playerUniqueId, message, jedis);
PayloadUtils.kickPlayerPayload(playerUniqueId, message, jedis);
return null;
}
@Override
public Void clusterJedisTask(JedisCluster jedisCluster) {
PayloadUtils.kickPlayer(playerUniqueId, message, jedisCluster);
PayloadUtils.kickPlayerPayload(playerUniqueId, message, jedisCluster);
return null;
}
}.execute();
@ -964,24 +965,22 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
}
@Override
public Class<?> getPubSubEventClass() {
return PubSubMessageEvent.class;
public Object createPlayerChangedNetworkEvent(UUID uuid, String previousServer, String server) {
return new PlayerChangedServerNetworkEvent(uuid, previousServer, server);
}
@Override
public Class<?> getNetworkJoinEventClass() {
return PlayerJoinedNetworkEvent.class;
public Object createPlayerJoinedNetworkEvent(UUID uuid) {
return new PlayerJoinedNetworkEvent(uuid);
}
@Override
public Class<?> getServerChangeEventClass() {
return PlayerChangedServerNetworkEvent.class;
public Object createPlayerLeftNetworkEvent(UUID uuid) {
return new PlayerLeftNetworkEvent(uuid);
}
@Override
public Class<?> getNetworkQuitEventClass() {
return PlayerJoinedNetworkEvent.class;
public Object createPubSubEvent(String channel, String message) {
return new PubSubMessageEvent(channel, message);
}
}

View File

@ -8,6 +8,7 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.imaginarycode.minecraft.redisbungee.api.AbstractRedisBungeeListener;
import com.imaginarycode.minecraft.redisbungee.api.AbstractDataManager;
import com.imaginarycode.minecraft.redisbungee.api.GenericPlayerUtils;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
import com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils;
@ -117,25 +118,15 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
public Void jedisTask(Jedis jedis) {
Pipeline pipeline = jedis.pipelined();
plugin.getUuidTranslator().persistInfo(event.getPlayer().getUsername(), event.getPlayer().getUniqueId(), pipeline);
PlayerUtils.createPlayer(event.getPlayer(), pipeline, false);
VelocityPlayerUtils.createPlayer(event.getPlayer(), pipeline, true);
pipeline.sync();
// the end of moved code.
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(event.getPlayer().getRemoteAddress().getAddress()))));
return null;
}
@Override
public Void clusterJedisTask(JedisCluster jedisCluster) {
plugin.getUuidTranslator().persistInfo(event.getPlayer().getUsername(), event.getPlayer().getUniqueId(), jedisCluster);
PlayerUtils.createPlayer(event.getPlayer(), jedisCluster, false);
// the end of moved code.
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(event.getPlayer().getRemoteAddress().getAddress()))));
VelocityPlayerUtils.createPlayer(event.getPlayer(), jedisCluster, true);
return null;
}
});
@ -148,14 +139,14 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
@Override
public Void jedisTask(Jedis jedis) {
Pipeline pipeline = jedis.pipelined();
PayloadUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), pipeline);
GenericPlayerUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), pipeline);
pipeline.sync();
return null;
}
@Override
public Void clusterJedisTask(JedisCluster jedisCluster) {
PayloadUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), jedisCluster);
GenericPlayerUtils.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), jedisCluster);
return null;
}
@ -168,23 +159,20 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
public void onServerChange(ServerConnectedEvent event) {
Optional<ServerConnection> optionalServerConnection = event.getPlayer().getCurrentServer();
final String currentServer = optionalServerConnection.map(serverConnection -> serverConnection.getServerInfo().getName()).orElse(null);
final String oldServer = event.getPreviousServer().map(serverConnection -> serverConnection.getServerInfo().getName()).orElse(null);
plugin.executeAsync(new RedisTask<Void>(plugin) {
@Override
public Void jedisTask(Jedis jedis) {
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getServerInfo().getName());
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(event.getServer().getServerInfo().getName(), currentServer))));
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", currentServer);
PayloadUtils.playerServerChangePayload(event.getPlayer().getUniqueId(), jedis, currentServer, oldServer);
return null;
}
@Override
public Void clusterJedisTask(JedisCluster jedisCluster) {
jedisCluster.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getServerInfo().getName());
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(event.getServer().getServerInfo().getName(), currentServer))));
jedisCluster.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", currentServer);
PayloadUtils.playerServerChangePayload(event.getPlayer().getUniqueId(), jedisCluster, currentServer, oldServer);
return null;
}
});

View File

@ -23,6 +23,7 @@ import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDTranslator;
import com.imaginarycode.minecraft.redisbungee.commands.RedisBungeeCommands;
import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent;
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent;
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import com.squareup.okhttp.Dispatcher;
import com.squareup.okhttp.OkHttpClient;
@ -694,7 +695,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
if (!laggedPlayers.isEmpty()) {
getLogger().info("Cleaning up lagged proxy {} ({} players)...", s, laggedPlayers.size());
for (String laggedPlayer : laggedPlayers) {
PayloadUtils.cleanUpPlayer(laggedPlayer, jedis);
GenericPlayerUtils.cleanUpPlayer(laggedPlayer, jedis);
}
}
}
@ -715,7 +716,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
}
}
if (!found) {
PayloadUtils.cleanUpPlayer(member, jedis);
GenericPlayerUtils.cleanUpPlayer(member, jedis);
getLogger().warn("Player found in set that was not found locally and globally: {}", member);
} else {
jedis.srem("proxy:" + configuration.getProxyId() + ":usersOnline", member);
@ -733,7 +734,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
if (playerProxied == null)
continue; // We'll deal with it later.
PlayerUtils.createPlayer(playerProxied, pipeline, true);
VelocityPlayerUtils.createPlayer(playerProxied, pipeline, true);
}
pipeline.sync();
@ -757,7 +758,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
if (!laggedPlayers.isEmpty()) {
getLogger().info("Cleaning up lagged proxy {} ({} players)...", s, laggedPlayers.size());
for (String laggedPlayer : laggedPlayers) {
PayloadUtils.cleanUpPlayer(laggedPlayer, jedisCluster);
GenericPlayerUtils.cleanUpPlayer(laggedPlayer, jedisCluster);
}
}
}
@ -778,7 +779,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
}
}
if (!found) {
PayloadUtils.cleanUpPlayer(member, jedisCluster);
GenericPlayerUtils.cleanUpPlayer(member, jedisCluster);
getLogger().warn("Player found in set that was not found locally and globally: {}", member);
} else {
jedisCluster.srem("proxy:" + configuration.getProxyId() + ":usersOnline", member);
@ -794,7 +795,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
if (playerProxied == null)
continue; // We'll deal with it later.
PlayerUtils.createPlayer(playerProxied, jedisCluster, true);
VelocityPlayerUtils.createPlayer(playerProxied, jedisCluster, true);
}
} catch (Throwable e) {
getLogger().error("Unable to fix up stored player data", e);
@ -841,7 +842,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
if (jedis.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
Set<String> players = jedis.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
for (String member : players)
PayloadUtils.cleanUpPlayer(member, jedis);
GenericPlayerUtils.cleanUpPlayer(member, jedis);
}
return null;
}
@ -852,7 +853,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
if (jedisCluster.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
Set<String> players = jedisCluster.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
for (String member : players)
PayloadUtils.cleanUpPlayer(member, jedisCluster);
GenericPlayerUtils.cleanUpPlayer(member, jedisCluster);
}
return null;
}
@ -961,13 +962,13 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
new RedisTask<Void>(api) {
@Override
public Void jedisTask(Jedis jedis) {
PayloadUtils.kickPlayer(playerUniqueId, message, jedis);
PayloadUtils.kickPlayerPayload(playerUniqueId, message, jedis);
return null;
}
@Override
public Void clusterJedisTask(JedisCluster jedisCluster) {
PayloadUtils.kickPlayer(playerUniqueId, message, jedisCluster);
PayloadUtils.kickPlayerPayload(playerUniqueId, message, jedisCluster);
return null;
}
}.execute();
@ -1003,26 +1004,25 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
@Override
public Class<?> getPubSubEventClass() {
return PubSubMessageEvent.class;
public Object createPlayerChangedNetworkEvent(UUID uuid, String previousServer, String server) {
return new PlayerChangedServerNetworkEvent(uuid, previousServer, server);
}
@Override
public Class<?> getNetworkJoinEventClass() {
return PlayerJoinedNetworkEvent.class;
public Object createPlayerJoinedNetworkEvent(UUID uuid) {
return new PlayerJoinedNetworkEvent(uuid);
}
@Override
public Class<?> getServerChangeEventClass() {
return PlayerChangedServerNetworkEvent.class;
public Object createPlayerLeftNetworkEvent(UUID uuid) {
return new PlayerLeftNetworkEvent(uuid);
}
@Override
public Class<?> getNetworkQuitEventClass() {
return PlayerJoinedNetworkEvent.class;
public Object createPubSubEvent(String channel, String message) {
return new PubSubMessageEvent(channel, message);
}
public ProxyServer getProxy() {
return server;
}

View File

@ -1,7 +1,5 @@
package com.imaginarycode.minecraft.redisbungee;
import com.google.gson.Gson;
import com.imaginarycode.minecraft.redisbungee.api.AbstractDataManager;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import redis.clients.jedis.JedisCluster;
@ -11,8 +9,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class PlayerUtils {
private static final Gson gson = new Gson();
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerJoinPayload;
public class VelocityPlayerUtils {
protected static void createPlayer(Player player, Pipeline pipeline, boolean fireEvent) {
Optional<ServerConnection> server = player.getCurrentServer();
@ -27,9 +26,7 @@ public class PlayerUtils {
pipeline.hmset("player:" + player.getUniqueId().toString(), playerData);
if (fireEvent) {
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
player.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(player.getRemoteAddress().getAddress()))));
playerJoinPayload(player.getUniqueId(), pipeline, player.getRemoteAddress().getAddress());
}
}
@ -46,9 +43,7 @@ public class PlayerUtils {
jedisCluster.hmset("player:" + player.getUniqueId().toString(), playerData);
if (fireEvent) {
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
player.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(player.getRemoteAddress().getAddress()))));
playerJoinPayload(player.getUniqueId(), jedisCluster, player.getRemoteAddress().getAddress());
}
}
}