2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-12-23 10:38:01 +00:00

more changes

This commit is contained in:
mohammed jasem alaajel 2022-07-08 02:39:05 +04:00
parent c04a911fbe
commit 9f05bd3438
11 changed files with 37 additions and 39 deletions

View File

@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit;
*
* @since 0.3.3
*/
public abstract class DataManager<P, PL, PD, PS> {
public abstract class AbstractDataManager<P, PL, PD, PS> {
private final RedisBungeePlugin<P> plugin;
private final Cache<UUID, String> serverCache = createCache();
private final Cache<UUID, String> proxyCache = createCache();
@ -31,7 +31,7 @@ public abstract class DataManager<P, PL, PD, PS> {
private final Cache<UUID, Long> lastOnlineCache = createCache();
private final Gson gson = new Gson();
public DataManager(RedisBungeePlugin<P> plugin) {
public AbstractDataManager(RedisBungeePlugin<P> plugin) {
this.plugin = plugin;
}

View File

@ -42,7 +42,7 @@ public interface RedisBungeePlugin<P> extends EventsPlatform{
Set<String> getLocalPlayersAsUuidStrings();
DataManager<P, ?, ?, ?> getDataManager();
AbstractDataManager<P, ?, ?, ?> getDataManager();
Set<UUID> getPlayers();

View File

@ -17,9 +17,9 @@ public class RedisUtil {
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 DataManager.DataManagerMessage<>(
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), DataManager.DataManagerMessage.Action.LEAVE,
new DataManager.LogoutPayload(timestamp))));
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
new AbstractDataManager.LogoutPayload(timestamp))));
}
public static void cleanUpPlayer(String player, Pipeline rsc) {
@ -27,9 +27,9 @@ public class RedisUtil {
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 DataManager.DataManagerMessage<>(
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), DataManager.DataManagerMessage.Action.LEAVE,
new DataManager.LogoutPayload(timestamp))));
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
new AbstractDataManager.LogoutPayload(timestamp))));
}
public static boolean isRedisVersionRight(String redisVersion) {

View File

@ -1,7 +1,7 @@
package com.imaginarycode.minecraft.redisbungee;
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import com.imaginarycode.minecraft.redisbungee.internal.DataManager;
import com.imaginarycode.minecraft.redisbungee.internal.AbstractDataManager;
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
@ -9,7 +9,7 @@ import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
public class BungeeDataManager extends DataManager<ProxiedPlayer, PostLoginEvent, PlayerDisconnectEvent, PubSubMessageEvent> implements Listener {
public class BungeeDataManager extends AbstractDataManager<ProxiedPlayer, PostLoginEvent, PlayerDisconnectEvent, PubSubMessageEvent> implements Listener {
public BungeeDataManager(RedisBungeePlugin<ProxiedPlayer> plugin) {
super(plugin);

View File

@ -1,7 +1,7 @@
package com.imaginarycode.minecraft.redisbungee;
import com.google.gson.Gson;
import com.imaginarycode.minecraft.redisbungee.internal.DataManager;
import com.imaginarycode.minecraft.redisbungee.internal.AbstractDataManager;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import redis.clients.jedis.Pipeline;
@ -29,9 +29,9 @@ public class RBUtils {
pipeline.hmset("player:" + connection.getUniqueId().toString(), playerData);
if (fireEvent) {
pipeline.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
connection.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), DataManager.DataManagerMessage.Action.JOIN,
new DataManager.LoginPayload(connection.getAddress().getAddress()))));
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
connection.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(connection.getAddress().getAddress()))));
}
}

View File

@ -95,7 +95,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
}
@Override
public DataManager<ProxiedPlayer, ?, ?, ?> getDataManager() {
public AbstractDataManager<ProxiedPlayer, ?, ?, ?> getDataManager() {
return this.dataManager;
}

View File

@ -7,13 +7,12 @@ import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.imaginarycode.minecraft.redisbungee.internal.AbstractRedisBungeeListener;
import com.imaginarycode.minecraft.redisbungee.internal.DataManager;
import com.imaginarycode.minecraft.redisbungee.internal.AbstractDataManager;
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import com.imaginarycode.minecraft.redisbungee.internal.RedisUtil;
import com.imaginarycode.minecraft.redisbungee.internal.util.RedisCallable;
import net.md_5.bungee.api.AbstractReconnectHandler;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
@ -90,9 +89,9 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
pipeline.sync();
// the end of moved code.
jedis.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), DataManager.DataManagerMessage.Action.JOIN,
new DataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
return null;
}
});
@ -121,9 +120,9 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
@Override
protected Void call(Jedis jedis) {
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
jedis.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE,
new DataManager.ServerChangePayload(event.getServer().getInfo().getName(), currentServer))));
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(event.getServer().getInfo().getName(), currentServer))));
return null;
}
});

View File

@ -1,8 +1,7 @@
package com.imaginarycode.minecraft.redisbungee;
import com.google.gson.Gson;
import com.imaginarycode.minecraft.redisbungee.internal.DataManager;
import com.velocitypowered.api.proxy.InboundConnection;
import com.imaginarycode.minecraft.redisbungee.internal.AbstractDataManager;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import redis.clients.jedis.Pipeline;
@ -29,9 +28,9 @@ public class RBUtils {
pipeline.hmset("player:" + player.getUniqueId().toString(), playerData);
if (fireEvent) {
pipeline.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
player.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), DataManager.DataManagerMessage.Action.JOIN,
new DataManager.LoginPayload(player.getRemoteAddress().getAddress()))));
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
player.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(player.getRemoteAddress().getAddress()))));
}
}

View File

@ -1,7 +1,7 @@
package com.imaginarycode.minecraft.redisbungee;
import com.imaginarycode.minecraft.redisbungee.internal.AbstractRedisBungeeListener;
import com.imaginarycode.minecraft.redisbungee.internal.DataManager;
import com.imaginarycode.minecraft.redisbungee.internal.AbstractDataManager;
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import com.imaginarycode.minecraft.redisbungee.internal.RedisUtil;
@ -83,9 +83,9 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
pipeline.sync();
// the end of moved code.
jedis.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), DataManager.DataManagerMessage.Action.JOIN,
new DataManager.LoginPayload(event.getPlayer().getRemoteAddress().getAddress()))));
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(event.getPlayer().getRemoteAddress().getAddress()))));
return null;
}
});
@ -115,9 +115,9 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
@Override
protected Void call(Jedis jedis) {
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getServerInfo().getName());
jedis.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE,
new DataManager.ServerChangePayload(event.getServer().getServerInfo().getName(), currentServer))));
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(event.getServer().getServerInfo().getName(), currentServer))));
return null;
}
});

View File

@ -112,7 +112,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
}
@Override
public DataManager<Player, ?, ?, ?> getDataManager() {
public AbstractDataManager<Player, ?, ?, ?> getDataManager() {
return this.dataManager;
}

View File

@ -1,7 +1,7 @@
package com.imaginarycode.minecraft.redisbungee;
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import com.imaginarycode.minecraft.redisbungee.internal.DataManager;
import com.imaginarycode.minecraft.redisbungee.internal.AbstractDataManager;
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent;
@ -9,7 +9,7 @@ import com.velocitypowered.api.event.connection.PostLoginEvent;
import com.velocitypowered.api.proxy.Player;
public class VelocityDataManager extends DataManager<Player, PostLoginEvent, DisconnectEvent, PubSubMessageEvent> {
public class VelocityDataManager extends AbstractDataManager<Player, PostLoginEvent, DisconnectEvent, PubSubMessageEvent> {
public VelocityDataManager(RedisBungeePlugin<Player> plugin) {
super(plugin);