mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-23 04:28:01 +00:00
Properly scope exceptions
This commit is contained in:
parent
bb71dd674f
commit
92971fce96
@ -15,6 +15,7 @@ import lombok.NonNull;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -54,6 +55,7 @@ public class UUIDTranslator {
|
|||||||
|
|
||||||
// Okay, it wasn't locally cached. Let's try Redis.
|
// Okay, it wasn't locally cached. Let's try Redis.
|
||||||
Jedis jedis = plugin.getPool().getResource();
|
Jedis jedis = plugin.getPool().getResource();
|
||||||
|
try {
|
||||||
try {
|
try {
|
||||||
String stored = jedis.hget("uuids", player.toLowerCase());
|
String stored = jedis.hget("uuids", player.toLowerCase());
|
||||||
if (stored != null && UUID_PATTERN.matcher(stored).find()) {
|
if (stored != null && UUID_PATTERN.matcher(stored).find()) {
|
||||||
@ -65,21 +67,30 @@ public class UUIDTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// That didn't work. Let's ask Mojang.
|
// That didn't work. Let's ask Mojang.
|
||||||
for (Map.Entry<String, UUID> entry : new UUIDFetcher(Collections.singletonList(player)).call().entrySet()) {
|
Map<String, UUID> uuidMap1;
|
||||||
|
try {
|
||||||
|
uuidMap1 = new UUIDFetcher(Collections.singletonList(player)).call();
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID from Mojang for " + player, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, UUID> entry : uuidMap1.entrySet()) {
|
||||||
if (entry.getKey().equalsIgnoreCase(player)) {
|
if (entry.getKey().equalsIgnoreCase(player)) {
|
||||||
uuidMap.put(player, entry.getValue());
|
uuidMap.put(player, entry.getValue());
|
||||||
storeInfo(player, entry.getValue(), jedis);
|
storeInfo(player, entry.getValue(), jedis);
|
||||||
return entry.getValue();
|
return entry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (JedisException e) {
|
||||||
return null;
|
|
||||||
} catch (Exception e) {
|
|
||||||
plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID for " + player, e);
|
plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID for " + player, e);
|
||||||
return null;
|
// Go ahead and give them what we have.
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
plugin.getPool().returnResource(jedis);
|
plugin.getPool().returnResource(jedis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null; // Nope, game over!
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNameFromUuid(@NonNull UUID player) {
|
public String getNameFromUuid(@NonNull UUID player) {
|
||||||
@ -102,7 +113,12 @@ public class UUIDTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// That didn't work. Let's ask Mojang.
|
// That didn't work. Let's ask Mojang.
|
||||||
|
try {
|
||||||
name = new NameFetcher(Collections.singletonList(player)).call().get(player);
|
name = new NameFetcher(Collections.singletonList(player)).call().get(player);
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Unable to fetch name from Mojang for " + player, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
storeInfo(name, player, jedis);
|
storeInfo(name, player, jedis);
|
||||||
@ -110,9 +126,9 @@ public class UUIDTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (JedisException e) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "Unable to fetch name for " + player, e);
|
plugin.getLogger().log(Level.SEVERE, "Unable to fetch name for " + player, e);
|
||||||
return null;
|
return name;
|
||||||
} finally {
|
} finally {
|
||||||
plugin.getPool().returnResource(jedis);
|
plugin.getPool().returnResource(jedis);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user