2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2026-04-08 16:10:26 +00:00

implement last server connect on join, closes #84

This commit is contained in:
2023-09-10 21:13:53 +04:00
parent e897a60976
commit e70a6e305c
4 changed files with 74 additions and 28 deletions

View File

@@ -38,6 +38,7 @@ public abstract class PlayerDataManager<P, LE, DE, PS extends IPubSubMessageEven
protected final RedisBungeePlugin<P> plugin;
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<UUID, Long> lastOnlineCache = Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build(this::getLastOnlineFromRedis);
@@ -68,6 +69,7 @@ public abstract class PlayerDataManager<P, LE, DE, PS extends IPubSubMessageEven
protected void handleNetworkPlayerServerChange(IPlayerChangedServerNetworkEvent event) {
this.serverCache.invalidate(event.getUuid());
this.lastServerCache.invalidate(event.getUuid());
}
protected void handleNetworkPlayerQuit(IPlayerLeftNetworkEvent event) {
@@ -190,6 +192,10 @@ public abstract class PlayerDataManager<P, LE, DE, PS extends IPubSubMessageEven
return unifiedJedis.hget("redis-bungee::player::" + uuid + "::data", "server");
}
protected String getLastServerFromRedis(UUID uuid) {
return unifiedJedis.hget("redis-bungee::player::" + uuid + "::data", "last-server");
}
protected InetAddress getIpAddressFromRedis(UUID uuid) {
String ip = unifiedJedis.hget("redis-bungee::player::" + uuid + "::data", "ip");
if (ip == null) return null;
@@ -202,6 +208,9 @@ public abstract class PlayerDataManager<P, LE, DE, PS extends IPubSubMessageEven
return Long.parseLong(unixString);
}
public String getLastServerFor(UUID uuid) {
return this.lastServerCache.get(uuid);
}
public String getServerFor(UUID uuid) {
return this.serverCache.get(uuid);
}

View File

@@ -4,13 +4,12 @@
# example:
# Format:
# message_id:
# <2 char language code>: "MiniMessage color and your text."
# lets assume we want to add arabic language.
# logged-in-other-location:
# en: "<color:red>You logged in from another location!"
# ar: "<color:red>لقد اتصلت من مكان اخر"
# errors:
# logged-in-other-location:
# en: "<color:red>You logged in from another location!"
# ar: "<color:red>لقد اتصلت من مكان اخر"
# Prefix if ever used.
@@ -26,9 +25,15 @@ default-language: en
# https://minecraft.fandom.com/wiki/Language
use-client-language: true
messages:
logged-in-other-location:
en: "<color:red>You logged in from another location!"
already-logged-in:
en: "<color:red>You are already logged in!"
server-not-found:
en: "<color:red>unable to connect you to the last server, because server %s was not found."
server-found:
en: "<color:green>Connecting you to %s..."
logged-in-other-location:
en: "<color:red>You logged in from another location!"
already-logged-in:
en: "<color:red>You are already logged in!"
# commands: