mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-23 04:28:01 +00:00
more changes
This commit is contained in:
parent
c04a911fbe
commit
9f05bd3438
@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*
|
*
|
||||||
* @since 0.3.3
|
* @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 RedisBungeePlugin<P> plugin;
|
||||||
private final Cache<UUID, String> serverCache = createCache();
|
private final Cache<UUID, String> serverCache = createCache();
|
||||||
private final Cache<UUID, String> proxyCache = 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 Cache<UUID, Long> lastOnlineCache = createCache();
|
||||||
private final Gson gson = new Gson();
|
private final Gson gson = new Gson();
|
||||||
|
|
||||||
public DataManager(RedisBungeePlugin<P> plugin) {
|
public AbstractDataManager(RedisBungeePlugin<P> plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +42,7 @@ public interface RedisBungeePlugin<P> extends EventsPlatform{
|
|||||||
|
|
||||||
Set<String> getLocalPlayersAsUuidStrings();
|
Set<String> getLocalPlayersAsUuidStrings();
|
||||||
|
|
||||||
DataManager<P, ?, ?, ?> getDataManager();
|
AbstractDataManager<P, ?, ?, ?> getDataManager();
|
||||||
|
|
||||||
Set<UUID> getPlayers();
|
Set<UUID> getPlayers();
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ public class RedisUtil {
|
|||||||
rsc.hdel("player:" + player, "server", "ip", "proxy");
|
rsc.hdel("player:" + player, "server", "ip", "proxy");
|
||||||
long timestamp = System.currentTimeMillis();
|
long timestamp = System.currentTimeMillis();
|
||||||
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
|
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
|
||||||
rsc.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
|
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||||
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), DataManager.DataManagerMessage.Action.LEAVE,
|
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
|
||||||
new DataManager.LogoutPayload(timestamp))));
|
new AbstractDataManager.LogoutPayload(timestamp))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanUpPlayer(String player, Pipeline rsc) {
|
public static void cleanUpPlayer(String player, Pipeline rsc) {
|
||||||
@ -27,9 +27,9 @@ public class RedisUtil {
|
|||||||
rsc.hdel("player:" + player, "server", "ip", "proxy");
|
rsc.hdel("player:" + player, "server", "ip", "proxy");
|
||||||
long timestamp = System.currentTimeMillis();
|
long timestamp = System.currentTimeMillis();
|
||||||
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
|
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
|
||||||
rsc.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
|
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||||
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), DataManager.DataManagerMessage.Action.LEAVE,
|
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
|
||||||
new DataManager.LogoutPayload(timestamp))));
|
new AbstractDataManager.LogoutPayload(timestamp))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRedisVersionRight(String redisVersion) {
|
public static boolean isRedisVersionRight(String redisVersion) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee;
|
package com.imaginarycode.minecraft.redisbungee;
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
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.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
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.api.plugin.Listener;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
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) {
|
public BungeeDataManager(RedisBungeePlugin<ProxiedPlayer> plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee;
|
package com.imaginarycode.minecraft.redisbungee;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
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.PendingConnection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import redis.clients.jedis.Pipeline;
|
import redis.clients.jedis.Pipeline;
|
||||||
@ -29,9 +29,9 @@ public class RBUtils {
|
|||||||
pipeline.hmset("player:" + connection.getUniqueId().toString(), playerData);
|
pipeline.hmset("player:" + connection.getUniqueId().toString(), playerData);
|
||||||
|
|
||||||
if (fireEvent) {
|
if (fireEvent) {
|
||||||
pipeline.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
|
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||||
connection.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), DataManager.DataManagerMessage.Action.JOIN,
|
connection.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
|
||||||
new DataManager.LoginPayload(connection.getAddress().getAddress()))));
|
new AbstractDataManager.LoginPayload(connection.getAddress().getAddress()))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataManager<ProxiedPlayer, ?, ?, ?> getDataManager() {
|
public AbstractDataManager<ProxiedPlayer, ?, ?, ?> getDataManager() {
|
||||||
return this.dataManager;
|
return this.dataManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,13 +7,12 @@ import com.google.common.io.ByteArrayDataInput;
|
|||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.imaginarycode.minecraft.redisbungee.internal.AbstractRedisBungeeListener;
|
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.internal.RedisBungeePlugin;
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||||
import com.imaginarycode.minecraft.redisbungee.internal.RedisUtil;
|
import com.imaginarycode.minecraft.redisbungee.internal.RedisUtil;
|
||||||
import com.imaginarycode.minecraft.redisbungee.internal.util.RedisCallable;
|
import com.imaginarycode.minecraft.redisbungee.internal.util.RedisCallable;
|
||||||
import net.md_5.bungee.api.AbstractReconnectHandler;
|
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.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.connection.Server;
|
import net.md_5.bungee.api.connection.Server;
|
||||||
@ -90,9 +89,9 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
|
|||||||
pipeline.sync();
|
pipeline.sync();
|
||||||
// the end of moved code.
|
// the end of moved code.
|
||||||
|
|
||||||
jedis.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage(
|
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage(
|
||||||
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), DataManager.DataManagerMessage.Action.JOIN,
|
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
|
||||||
new DataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
|
new AbstractDataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -121,9 +120,9 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
|
|||||||
@Override
|
@Override
|
||||||
protected Void call(Jedis jedis) {
|
protected Void call(Jedis jedis) {
|
||||||
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
|
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
|
||||||
jedis.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage(
|
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage(
|
||||||
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE,
|
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
|
||||||
new DataManager.ServerChangePayload(event.getServer().getInfo().getName(), currentServer))));
|
new AbstractDataManager.ServerChangePayload(event.getServer().getInfo().getName(), currentServer))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee;
|
package com.imaginarycode.minecraft.redisbungee;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.imaginarycode.minecraft.redisbungee.internal.DataManager;
|
import com.imaginarycode.minecraft.redisbungee.internal.AbstractDataManager;
|
||||||
import com.velocitypowered.api.proxy.InboundConnection;
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import redis.clients.jedis.Pipeline;
|
import redis.clients.jedis.Pipeline;
|
||||||
@ -29,9 +28,9 @@ public class RBUtils {
|
|||||||
pipeline.hmset("player:" + player.getUniqueId().toString(), playerData);
|
pipeline.hmset("player:" + player.getUniqueId().toString(), playerData);
|
||||||
|
|
||||||
if (fireEvent) {
|
if (fireEvent) {
|
||||||
pipeline.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
|
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||||
player.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), DataManager.DataManagerMessage.Action.JOIN,
|
player.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
|
||||||
new DataManager.LoginPayload(player.getRemoteAddress().getAddress()))));
|
new AbstractDataManager.LoginPayload(player.getRemoteAddress().getAddress()))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee;
|
package com.imaginarycode.minecraft.redisbungee;
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.internal.AbstractRedisBungeeListener;
|
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.internal.RedisBungeePlugin;
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||||
import com.imaginarycode.minecraft.redisbungee.internal.RedisUtil;
|
import com.imaginarycode.minecraft.redisbungee.internal.RedisUtil;
|
||||||
@ -83,9 +83,9 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
|
|||||||
pipeline.sync();
|
pipeline.sync();
|
||||||
// the end of moved code.
|
// the end of moved code.
|
||||||
|
|
||||||
jedis.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
|
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||||
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), DataManager.DataManagerMessage.Action.JOIN,
|
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
|
||||||
new DataManager.LoginPayload(event.getPlayer().getRemoteAddress().getAddress()))));
|
new AbstractDataManager.LoginPayload(event.getPlayer().getRemoteAddress().getAddress()))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -115,9 +115,9 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
|
|||||||
@Override
|
@Override
|
||||||
protected Void call(Jedis jedis) {
|
protected Void call(Jedis jedis) {
|
||||||
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getServerInfo().getName());
|
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getServerInfo().getName());
|
||||||
jedis.publish("redisbungee-data", gson.toJson(new DataManager.DataManagerMessage<>(
|
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
||||||
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE,
|
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
|
||||||
new DataManager.ServerChangePayload(event.getServer().getServerInfo().getName(), currentServer))));
|
new AbstractDataManager.ServerChangePayload(event.getServer().getServerInfo().getName(), currentServer))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -112,7 +112,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataManager<Player, ?, ?, ?> getDataManager() {
|
public AbstractDataManager<Player, ?, ?, ?> getDataManager() {
|
||||||
return this.dataManager;
|
return this.dataManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee;
|
package com.imaginarycode.minecraft.redisbungee;
|
||||||
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
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.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
@ -9,7 +9,7 @@ import com.velocitypowered.api.event.connection.PostLoginEvent;
|
|||||||
import com.velocitypowered.api.proxy.Player;
|
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) {
|
public VelocityDataManager(RedisBungeePlugin<Player> plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
Loading…
Reference in New Issue
Block a user