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

12 Commits

Author SHA1 Message Date
0f0f707ef7 bump version 2023-03-17 12:23:46 +04:00
441a12bb36 fix error being thrown getServerFor in Bungeecord/Velocity in the api closes #64
when plugins messing around with proxy internals (eg: limboapi) the field server in redis data of the player set to null which can become problematic for velocity due checking of null in velocity but i applied the same stuff to the bungeecord version aswell and document it in the javadocs
2023-03-17 12:15:10 +04:00
冰砚炽
0534970368 Fix PlayerList not returning server name when it is not ALL (#62) 2023-01-31 12:40:06 +04:00
20f9143ea5 bump version 2022-12-31 07:26:05 +04:00
1a2459b64e deprecated NameFetcher api 2022-12-31 07:23:35 +04:00
AlessioDP
c3888c8f65 Fix NullPointerException due plugin instance for jedis tasks in UUIDTranslator/AbstractDataManager (#57) 2022-12-25 06:26:53 +04:00
c8362a44ec add config option to restore old kick behavior pre 0.9.0 2022-11-27 12:29:13 +04:00
31e461a11c change url of big uuid cache 2022-11-27 12:10:29 +04:00
a9ea04c2c0 missed location were it wasn't using the constant 2022-11-24 01:41:47 +04:00
ddfc689c2d expose CachedUUIDEntry Class 2022-11-16 11:32:20 +04:00
ae6961ef24 bump version 2022-11-16 08:22:57 +04:00
8318bcd1bf update some logs in configloader 2022-11-16 08:22:30 +04:00
22 changed files with 173 additions and 80 deletions

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>RedisBungee</artifactId> <artifactId>RedisBungee</artifactId>
<groupId>com.imaginarycode.minecraft</groupId> <groupId>com.imaginarycode.minecraft</groupId>
<version>0.9.0-SNAPSHOT</version> <version>0.10.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -20,6 +20,7 @@ import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummone
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisPooledSummoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisPooledSummoner;
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster; import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPool;
@@ -81,8 +82,9 @@ public abstract class AbstractRedisBungeeAPI {
* as well, and will return local information on them. * as well, and will return local information on them.
* *
* @param player a player uuid * @param player a player uuid
* @return a String name for the server the player is on. * @return a String name for the server the player is on. Can be Null if plugins is doing weird stuff to the proxy internals
*/ */
@Nullable
public final String getServerNameFor(@NonNull UUID player) { public final String getServerNameFor(@NonNull UUID player) {
return plugin.getDataManager().getServer(player); return plugin.getDataManager().getServer(player);
} }

View File

@@ -59,7 +59,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
return plugin.isPlayerOnAServer(player) ? plugin.getPlayerServerName(player) : null; return plugin.isPlayerOnAServer(player) ? plugin.getPlayerServerName(player) : null;
try { try {
return serverCache.get(uuid, new RedisTask<String>(plugin.getAbstractRedisBungeeApi()) { return serverCache.get(uuid, new RedisTask<String>(plugin) {
@Override @Override
public String unifiedJedisTask(UnifiedJedis unifiedJedis) { public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
return Objects.requireNonNull(unifiedJedis.hget("player:" + uuid, "server"), "user not found"); return Objects.requireNonNull(unifiedJedis.hget("player:" + uuid, "server"), "user not found");
@@ -82,7 +82,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
return plugin.getConfiguration().getProxyId(); return plugin.getConfiguration().getProxyId();
try { try {
return proxyCache.get(uuid, new RedisTask<String>(plugin.getAbstractRedisBungeeApi()) { return proxyCache.get(uuid, new RedisTask<String>(plugin) {
@Override @Override
public String unifiedJedisTask(UnifiedJedis unifiedJedis) { public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
return Objects.requireNonNull(unifiedJedis.hget("player:" + uuid, "proxy"), "user not found"); return Objects.requireNonNull(unifiedJedis.hget("player:" + uuid, "proxy"), "user not found");
@@ -103,7 +103,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
return plugin.getPlayerIp(player); return plugin.getPlayerIp(player);
try { try {
return ipCache.get(uuid, new RedisTask<InetAddress>(plugin.getAbstractRedisBungeeApi()) { return ipCache.get(uuid, new RedisTask<InetAddress>(plugin) {
@Override @Override
public InetAddress unifiedJedisTask(UnifiedJedis unifiedJedis) { public InetAddress unifiedJedisTask(UnifiedJedis unifiedJedis) {
String result = unifiedJedis.hget("player:" + uuid, "ip"); String result = unifiedJedis.hget("player:" + uuid, "ip");
@@ -127,7 +127,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
return 0; return 0;
try { try {
return lastOnlineCache.get(uuid, new RedisTask<Long>(plugin.getAbstractRedisBungeeApi()) { return lastOnlineCache.get(uuid, new RedisTask<Long>(plugin) {
@Override @Override
public Long unifiedJedisTask(UnifiedJedis unifiedJedis) { public Long unifiedJedisTask(UnifiedJedis unifiedJedis) {

View File

@@ -67,7 +67,7 @@ public interface RedisBungeePlugin<P> extends EventsPlatform {
String v = stringStringEntry.getValue(); String v = stringStringEntry.getValue();
long heartbeatTime = Long.parseLong(v); long heartbeatTime = Long.parseLong(v);
if (heartbeatTime + 30 >= redisTime) { if (heartbeatTime + RedisUtil.PROXY_TIMEOUT >= redisTime) {
total = total + unifiedJedis.scard("proxy:" + k + ":usersOnline"); total = total + unifiedJedis.scard("proxy:" + k + ":usersOnline");
} }
} }

View File

@@ -52,7 +52,8 @@ public interface ConfigLoader {
final boolean useSSL = node.getNode("useSSL").getBoolean(false); final boolean useSSL = node.getNode("useSSL").getBoolean(false);
final boolean overrideBungeeCommands = node.getNode("override-bungee-commands").getBoolean(false); final boolean overrideBungeeCommands = node.getNode("override-bungee-commands").getBoolean(false);
final boolean registerLegacyCommands = node.getNode("register-legacy-commands").getBoolean(false); final boolean registerLegacyCommands = node.getNode("register-legacy-commands").getBoolean(false);
String redisPassword = node.getNode("redis-password").getString(null); final boolean restoreOldKickBehavior = node.getNode("disable-kick-when-online").getBoolean(false);
String redisPassword = node.getNode("redis-password").getString("");
String proxyId = node.getNode("proxy-id").getString("test-1"); String proxyId = node.getNode("proxy-id").getString("test-1");
final int maxConnections = node.getNode("max-redis-connections").getInt(10); final int maxConnections = node.getNode("max-redis-connections").getInt(10);
List<String> exemptAddresses; List<String> exemptAddresses;
@@ -63,15 +64,12 @@ public interface ConfigLoader {
} }
// check redis password // check redis password
if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) { if ((redisPassword.isEmpty() || redisPassword.equals("none"))) {
redisPassword = null; redisPassword = null;
plugin.logWarn("INSECURE setup was detected Please set password for your redis instance."); plugin.logWarn("password is empty");
} }
if (redisPassword == null) { if (useSSL) {
plugin.logWarn("INSECURE setup was detected Please set password for your redis instance."); plugin.logInfo("Using ssl");
}
if (!useSSL) {
plugin.logWarn("INSECURE setup was detected Please setup ssl for your redis instance.");
} }
// Configuration sanity checks. // Configuration sanity checks.
if (proxyId == null || proxyId.isEmpty()) { if (proxyId == null || proxyId.isEmpty()) {
@@ -84,7 +82,7 @@ public interface ConfigLoader {
} else { } else {
plugin.logInfo("Loaded proxy id " + proxyId); plugin.logInfo("Loaded proxy id " + proxyId);
} }
RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands, getMessagesFromPath(createMessagesFile(dataFolder))); RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands, getMessagesFromPath(createMessagesFile(dataFolder)), restoreOldKickBehavior);
Summoner<?> summoner; Summoner<?> summoner;
RedisBungeeMode redisBungeeMode; RedisBungeeMode redisBungeeMode;
if (node.getNode("cluster-mode-enabled").getBoolean(false)) { if (node.getNode("cluster-mode-enabled").getBoolean(false)) {
@@ -137,6 +135,7 @@ public interface ConfigLoader {
ConfigurationNode node = yamlConfigurationFileLoader.load(); ConfigurationNode node = yamlConfigurationFileLoader.load();
HashMap<RedisBungeeConfiguration.MessageType, String> messages = new HashMap<>(); HashMap<RedisBungeeConfiguration.MessageType, String> messages = new HashMap<>();
messages.put(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION, node.getNode("logged-in-other-location").getString("§cLogged in from another location.")); messages.put(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION, node.getNode("logged-in-other-location").getString("§cLogged in from another location."));
messages.put(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN, node.getNode("already-logged-in").getString("§cYou are already logged in!"));
return ImmutableMap.copyOf(messages); return ImmutableMap.copyOf(messages);
} }
@@ -178,8 +177,6 @@ public interface ConfigLoader {
Path oldConfigPath = dataFolder.resolve("config.yml"); Path oldConfigPath = dataFolder.resolve("config.yml");
Files.move(oldConfigPath, oldConfigFolder.resolve(UUID.randomUUID() + "_config.yml")); Files.move(oldConfigPath, oldConfigFolder.resolve(UUID.randomUUID() + "_config.yml"));
createConfigFile(dataFolder); createConfigFile(dataFolder);
} }
} }

View File

@@ -22,19 +22,20 @@ import java.util.List;
public class RedisBungeeConfiguration { public class RedisBungeeConfiguration {
public enum MessageType { public enum MessageType {
LOGGED_IN_OTHER_LOCATION LOGGED_IN_OTHER_LOCATION,
ALREADY_LOGGED_IN
} }
private final ImmutableMap<MessageType, String> messages; private final ImmutableMap<MessageType, String> messages;
public static final int CONFIG_VERSION = 1; public static final int CONFIG_VERSION = 1;
private final String proxyId; private final String proxyId;
private final List<InetAddress> exemptAddresses; private final List<InetAddress> exemptAddresses;
private final boolean registerLegacyCommands; private final boolean registerLegacyCommands;
private final boolean overrideBungeeCommands; private final boolean overrideBungeeCommands;
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands, ImmutableMap<MessageType, String> messages) { private final boolean restoreOldKickBehavior;
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands, ImmutableMap<MessageType, String> messages, boolean restoreOldKickBehavior) {
this.proxyId = proxyId; this.proxyId = proxyId;
this.messages = messages; this.messages = messages;
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder(); ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
@@ -44,8 +45,8 @@ public class RedisBungeeConfiguration {
this.exemptAddresses = addressBuilder.build(); this.exemptAddresses = addressBuilder.build();
this.registerLegacyCommands = registerLegacyCommands; this.registerLegacyCommands = registerLegacyCommands;
this.overrideBungeeCommands = overrideBungeeCommands; this.overrideBungeeCommands = overrideBungeeCommands;
this.restoreOldKickBehavior = restoreOldKickBehavior;
} }
public String getProxyId() { public String getProxyId() {
return proxyId; return proxyId;
} }
@@ -65,4 +66,8 @@ public class RedisBungeeConfiguration {
public ImmutableMap<MessageType, String> getMessages() { public ImmutableMap<MessageType, String> getMessages() {
return messages; return messages;
} }
public boolean restoreOldKickBehavior() {
return restoreOldKickBehavior;
}
} }

View File

@@ -40,7 +40,7 @@ public class InitialUtils {
} }
long uuidCacheSize = unifiedJedis.hlen("uuid-cache"); long uuidCacheSize = unifiedJedis.hlen("uuid-cache");
if (uuidCacheSize > 750000) { if (uuidCacheSize > 750000) {
plugin.logInfo("Looks like you have a really big UUID cache! Run https://www.spigotmc.org/resources/redisbungeecleaner.8505/ as soon as possible."); plugin.logInfo("Looks like you have a really big UUID cache! Run https://github.com/ProxioDev/Brains");
} }
break; break;
} }

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2013-present RedisBungee contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
import java.util.Calendar;
import java.util.UUID;
public class CachedUUIDEntry {
private final String name;
private final UUID uuid;
private final Calendar expiry;
public CachedUUIDEntry(String name, UUID uuid, Calendar expiry) {
this.name = name;
this.uuid = uuid;
this.expiry = expiry;
}
public String getName() {
return name;
}
public UUID getUuid() {
return uuid;
}
public Calendar getExpiry() {
return expiry;
}
public boolean expired() {
return Calendar.getInstance().after(expiry);
}
}

View File

@@ -1,3 +1,13 @@
/*
* Copyright (c) 2013-present RedisBungee contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.imaginarycode.minecraft.redisbungee.api.util.uuid; package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
import com.google.gson.Gson; import com.google.gson.Gson;
@@ -11,32 +21,38 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@Deprecated
public class NameFetcher { public class NameFetcher {
private static OkHttpClient httpClient; private static OkHttpClient httpClient;
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
@Deprecated
public static void setHttpClient(OkHttpClient httpClient) { public static void setHttpClient(OkHttpClient httpClient) {
NameFetcher.httpClient = httpClient; throw new UnsupportedOperationException("Due mojang disabled the Names API NameFetcher no longer functions and has been disabled");
// NameFetcher.httpClient = httpClient;
} }
@Deprecated
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException { public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException {
String url = "https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "") + "/names"; throw new UnsupportedOperationException("Due mojang disabled the Names API NameFetcher no longer functions and has been disabled");
Request request = new Request.Builder().url(url).get().build(); // String url = "https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "") + "/names";
ResponseBody body = httpClient.newCall(request).execute().body(); // Request request = new Request.Builder().url(url).get().build();
String response = body.string(); // ResponseBody body = httpClient.newCall(request).execute().body();
body.close(); // String response = body.string();
// body.close();
Type listType = new TypeToken<List<Name>>() { //
}.getType(); // Type listType = new TypeToken<List<Name>>() {
List<Name> names = gson.fromJson(response, listType); // }.getType();
// List<Name> names = gson.fromJson(response, listType);
List<String> humanNames = new ArrayList<>(); //
for (Name name : names) { // List<String> humanNames = new ArrayList<>();
humanNames.add(name.name); // for (Name name : names) {
} // humanNames.add(name.name);
return humanNames; // }
// return humanNames;
} }
@Deprecated
public static class Name { public static class Name {
private String name; private String name;
private long changedToAt; private long changedToAt;

View File

@@ -1,3 +1,13 @@
/*
* Copyright (c) 2013-present RedisBungee contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.imaginarycode.minecraft.redisbungee.api.util.uuid; package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;

View File

@@ -1,3 +1,13 @@
/*
* Copyright (c) 2013-present RedisBungee contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.imaginarycode.minecraft.redisbungee.api.util.uuid; package com.imaginarycode.minecraft.redisbungee.api.util.uuid;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
@@ -70,7 +80,7 @@ public final class UUIDTranslator {
if (!plugin.isOnlineMode()) { if (!plugin.isOnlineMode()) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player).getBytes(Charsets.UTF_8)); return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player).getBytes(Charsets.UTF_8));
} }
RedisTask<UUID> redisTask = new RedisTask<UUID>(plugin.getAbstractRedisBungeeApi()) { RedisTask<UUID> redisTask = new RedisTask<UUID>(plugin) {
@Override @Override
public UUID unifiedJedisTask(UnifiedJedis unifiedJedis) { public UUID unifiedJedisTask(UnifiedJedis unifiedJedis) {
String stored = unifiedJedis.hget("uuid-cache", player.toLowerCase()); String stored = unifiedJedis.hget("uuid-cache", player.toLowerCase());
@@ -135,7 +145,7 @@ public final class UUIDTranslator {
uuidToNameMap.remove(player); uuidToNameMap.remove(player);
} }
RedisTask<String> redisTask = new RedisTask<String>(plugin.getAbstractRedisBungeeApi()) { RedisTask<String> redisTask = new RedisTask<String>(plugin) {
@Override @Override
public String unifiedJedisTask(UnifiedJedis unifiedJedis) { public String unifiedJedisTask(UnifiedJedis unifiedJedis) {
String stored = unifiedJedis.hget("uuid-cache", player.toString()); String stored = unifiedJedis.hget("uuid-cache", player.toString());
@@ -160,10 +170,14 @@ public final class UUIDTranslator {
return null; return null;
// That didn't work. Let's ask Mojang. This call may fail, because Mojang is insane. // That didn't work. Let's ask Mojang. This call may fail, because Mojang is insane.
//
// UPDATE: Mojang has removed the API somewhere in september/2022 due privacy issues
// this is expected to fail now, so we will keep logging it until we figure out something or remove name fetching completely
// Name fetching class was deprecated as result
String name; String name;
try { try {
List<String> nameHist = NameFetcher.nameHistoryFromUuid(player); plugin.logFatal("Due Mojang removing the naming API, we were unable to fetch player names.");
name = Iterables.getLast(nameHist, null); name = Iterables.getLast(NameFetcher.nameHistoryFromUuid(player));
} catch (Exception e) { } catch (Exception e) {
plugin.logFatal("Unable to fetch name from Mojang for " + player); plugin.logFatal("Unable to fetch name from Mojang for " + player);
return null; return null;
@@ -194,31 +208,5 @@ public final class UUIDTranslator {
unifiedJedis.hset("uuid-cache", ImmutableMap.of(name.toLowerCase(), json, uuid.toString(), json)); unifiedJedis.hset("uuid-cache", ImmutableMap.of(name.toLowerCase(), json, uuid.toString(), json));
} }
private static class CachedUUIDEntry {
private final String name;
private final UUID uuid;
private final Calendar expiry;
public CachedUUIDEntry(String name, UUID uuid, Calendar expiry) {
this.name = name;
this.uuid = uuid;
this.expiry = expiry;
}
public String getName() {
return name;
}
public UUID getUuid() {
return uuid;
}
public Calendar getExpiry() {
return expiry;
}
public boolean expired() {
return Calendar.getInstance().after(expiry);
}
}
} }

View File

@@ -68,5 +68,10 @@ override-bungee-commands: false
# restart scripts. # restart scripts.
exempt-ip-addresses: [] exempt-ip-addresses: []
# restore old login when online behavior before 0.9.0 update
# uncomment to enable it
# disable-kick-when-online: true
# Config version DO NOT CHANGE!!!! # Config version DO NOT CHANGE!!!!
config-version: 1 config-version: 1

View File

@@ -1 +1,2 @@
logged-in-other-location: "§cYou logged in from another location!" logged-in-other-location: "§cYou logged in from another location!"
already-logged-in: "§cYou are already logged in!"

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>RedisBungee</artifactId> <artifactId>RedisBungee</artifactId>
<groupId>com.imaginarycode.minecraft</groupId> <groupId>com.imaginarycode.minecraft</groupId>
<version>0.9.0-SNAPSHOT</version> <version>0.10.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -222,7 +222,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
httpClient = new OkHttpClient(); httpClient = new OkHttpClient();
Dispatcher dispatcher = new Dispatcher(getExecutorService()); Dispatcher dispatcher = new Dispatcher(getExecutorService());
httpClient.setDispatcher(dispatcher); httpClient.setDispatcher(dispatcher);
NameFetcher.setHttpClient(httpClient); //NameFetcher.setHttpClient(httpClient);
UUIDFetcher.setHttpClient(httpClient); UUIDFetcher.setHttpClient(httpClient);
InitialUtils.checkRedisVersion(this); InitialUtils.checkRedisVersion(this);
// check if this proxy is recovering from a crash and start heart the beat. // check if this proxy is recovering from a crash and start heart the beat.

View File

@@ -14,6 +14,7 @@ import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.UUID; import java.util.UUID;
@@ -43,8 +44,11 @@ public class RedisBungeeAPI extends AbstractRedisBungeeAPI {
* @return {@link ServerInfo} Can be null if proxy can't find it. * @return {@link ServerInfo} Can be null if proxy can't find it.
* @see #getServerNameFor(UUID) * @see #getServerNameFor(UUID)
*/ */
@Nullable
public final ServerInfo getServerFor(@NonNull UUID player) { public final ServerInfo getServerFor(@NonNull UUID player) {
return ((Plugin) this.plugin).getProxy().getServerInfo(this.getServerNameFor(player)); String serverName = this.getServerNameFor(player);
if (serverName == null) return null;
return ((Plugin) this.plugin).getProxy().getServerInfo(serverName);
} }
/** /**

View File

@@ -58,7 +58,15 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
if (event.isCancelled()) { if (event.isCancelled()) {
return null; return null;
} }
if (api.isPlayerOnline(event.getConnection().getUniqueId())) { if (plugin.getConfiguration().restoreOldKickBehavior()) {
for (String s : plugin.getProxiesIds()) {
if (unifiedJedis.sismember("proxy:" + s + ":usersOnline", event.getConnection().getUniqueId().toString())) {
event.setCancelled(true);
event.setCancelReason(plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN));
return null;
}
}
} else if (api.isPlayerOnline(event.getConnection().getUniqueId())) {
PlayerUtils.setKickedOtherLocation(event.getConnection().getUniqueId().toString(), unifiedJedis); PlayerUtils.setKickedOtherLocation(event.getConnection().getUniqueId().toString(), unifiedJedis);
api.kickPlayer(event.getConnection().getUniqueId(), plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION)); api.kickPlayer(event.getConnection().getUniqueId(), plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION));
} }
@@ -148,6 +156,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
out.writeUTF("ALL"); out.writeUTF("ALL");
original = plugin.getPlayers(); original = plugin.getPlayers();
} else { } else {
out.writeUTF(type);
try { try {
original = plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type); original = plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type);
} catch (IllegalArgumentException ignored) { } catch (IllegalArgumentException ignored) {

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>RedisBungee</artifactId> <artifactId>RedisBungee</artifactId>
<groupId>com.imaginarycode.minecraft</groupId> <groupId>com.imaginarycode.minecraft</groupId>
<version>0.9.0-SNAPSHOT</version> <version>0.10.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -14,6 +14,7 @@ import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.api.proxy.server.ServerInfo;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.UUID; import java.util.UUID;
@@ -44,8 +45,11 @@ public class RedisBungeeAPI extends AbstractRedisBungeeAPI {
* @return {@link ServerInfo} Can be null if proxy can't find it. * @return {@link ServerInfo} Can be null if proxy can't find it.
* @see #getServerNameFor(UUID) * @see #getServerNameFor(UUID)
*/ */
@Nullable
public final ServerInfo getServerFor(@NonNull UUID player) { public final ServerInfo getServerFor(@NonNull UUID player) {
return ((RedisBungeeVelocityPlugin) this.plugin).getProxy().getServer(this.getServerNameFor(player)).map((RegisteredServer::getServerInfo)).orElse(null); String serverName = this.getServerNameFor(player);
if (serverName == null) return null;
return ((RedisBungeeVelocityPlugin) this.plugin).getProxy().getServer(serverName).map((RegisteredServer::getServerInfo)).orElse(null);
} }
/** /**

View File

@@ -65,7 +65,16 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
if (!event.getResult().isAllowed()) { if (!event.getResult().isAllowed()) {
return null; return null;
} }
if (api.isPlayerOnline(event.getPlayer().getUniqueId())) { if (plugin.getConfiguration().restoreOldKickBehavior()) {
for (String s : plugin.getProxiesIds()) {
if (unifiedJedis.sismember("proxy:" + s + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
event.setResult(ResultedEvent.ComponentResult.denied(serializer.deserialize(plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN))));
return null;
}
}
} else if (api.isPlayerOnline(event.getPlayer().getUniqueId())) {
PlayerUtils.setKickedOtherLocation(event.getPlayer().getUniqueId().toString(), unifiedJedis); PlayerUtils.setKickedOtherLocation(event.getPlayer().getUniqueId().toString(), unifiedJedis);
api.kickPlayer(event.getPlayer().getUniqueId(), plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION)); api.kickPlayer(event.getPlayer().getUniqueId(), plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION));
} }
@@ -156,6 +165,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
out.writeUTF("ALL"); out.writeUTF("ALL");
original = plugin.getPlayers(); original = plugin.getPlayers();
} else { } else {
out.writeUTF(type);
try { try {
original = plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type); original = plugin.getAbstractRedisBungeeApi().getPlayersOnServer(type);
} catch (IllegalArgumentException ignored) { } catch (IllegalArgumentException ignored) {

View File

@@ -109,7 +109,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, Con
this.httpClient = new OkHttpClient(); this.httpClient = new OkHttpClient();
Dispatcher dispatcher = new Dispatcher(Executors.newFixedThreadPool(6)); Dispatcher dispatcher = new Dispatcher(Executors.newFixedThreadPool(6));
this.httpClient.setDispatcher(dispatcher); this.httpClient.setDispatcher(dispatcher);
NameFetcher.setHttpClient(httpClient); //NameFetcher.setHttpClient(httpClient);
UUIDFetcher.setHttpClient(httpClient); UUIDFetcher.setHttpClient(httpClient);
} }

View File

@@ -7,7 +7,7 @@
<groupId>com.imaginarycode.minecraft</groupId> <groupId>com.imaginarycode.minecraft</groupId>
<artifactId>RedisBungee</artifactId> <artifactId>RedisBungee</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>0.9.0-SNAPSHOT</version> <version>0.10.2-SNAPSHOT</version>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>