From 289996088bf8c7ab2fd59bfb90bbdcffd95d01f8 Mon Sep 17 00:00:00 2001 From: Console Date: Tue, 10 Sep 2024 11:48:51 +0200 Subject: [PATCH 1/2] Fixed null when fetching server id. --- .../minecraft/redisbungee/api/PlayerDataManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java b/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java index 4a25d24d..7e137784 100644 --- a/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java +++ b/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java @@ -267,7 +267,9 @@ protected Multimap serversToPlayersBuilder(Object o) { public Multimap doPooledPipeline(Pipeline pipeline) { HashMap> responses = new HashMap<>(); for (UUID uuid : uuids) { - responses.put(uuid, pipeline.hget("redis-bungee::" + networkId + "::player::" + uuid + "::data", "server")); + Response server = pipeline.hget("redis-bungee::" + networkId + "::player::" + uuid + "::data", "server"); + if (server != null) + responses.put(uuid, pipeline.hget("redis-bungee::" + networkId + "::player::" + uuid + "::data", "server")); } pipeline.sync(); responses.forEach((uuid, response) -> { From e5dc4772d8aa39b005daa70c79cc33e45c05a9a9 Mon Sep 17 00:00:00 2001 From: Console Date: Tue, 10 Sep 2024 12:04:35 +0200 Subject: [PATCH 2/2] Made the code more efficient / performance. --- .../redisbungee/api/PlayerDataManager.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java b/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java index 7e137784..2ce1a265 100644 --- a/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java +++ b/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java @@ -29,10 +29,7 @@ import redis.clients.jedis.UnifiedJedis; import java.net.InetAddress; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.concurrent.TimeUnit; public abstract class PlayerDataManager { @@ -267,9 +264,9 @@ protected Multimap serversToPlayersBuilder(Object o) { public Multimap doPooledPipeline(Pipeline pipeline) { HashMap> responses = new HashMap<>(); for (UUID uuid : uuids) { - Response server = pipeline.hget("redis-bungee::" + networkId + "::player::" + uuid + "::data", "server"); - if (server != null) - responses.put(uuid, pipeline.hget("redis-bungee::" + networkId + "::player::" + uuid + "::data", "server")); + Optional.ofNullable(pipeline.hget("redis-bungee::" + networkId + "::player::" + uuid + "::data", "server")).ifPresent(stringResponse -> { + responses.put(uuid, stringResponse); + }); } pipeline.sync(); responses.forEach((uuid, response) -> { @@ -285,13 +282,14 @@ public Multimap doPooledPipeline(Pipeline pipeline) { public Multimap clusterPipeline(ClusterPipeline pipeline) { HashMap> responses = new HashMap<>(); for (UUID uuid : uuids) { - responses.put(uuid, pipeline.hget("redis-bungee::" + networkId + "::player::" + uuid + "::data", "server")); + Optional.ofNullable(pipeline.hget("redis-bungee::" + networkId + "::player::" + uuid + "::data", "server")).ifPresent(stringResponse -> { + responses.put(uuid, stringResponse); + }); } pipeline.sync(); responses.forEach((uuid, response) -> { String key = response.get(); if (key == null) return; - builder.put(key, uuid); }); return builder.build();