forked from TuxCoding/FastLogin
Use Optionals for nullable values
This commit is contained in:
@@ -28,10 +28,6 @@ public class CommonUtil {
|
||||
}
|
||||
|
||||
public static UUID parseId(String withoutDashes) {
|
||||
if (withoutDashes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return UUID.fromString(withoutDashes.substring(0, 8)
|
||||
+ '-' + withoutDashes.substring(8, 12)
|
||||
+ '-' + withoutDashes.substring(12, 16)
|
||||
|
||||
+7
-6
@@ -24,6 +24,7 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
@@ -58,7 +59,7 @@ public class MojangApiConnector {
|
||||
protected final Logger logger;
|
||||
|
||||
public MojangApiConnector(Logger logger, Collection<String> localAddresses, int rateLimit
|
||||
, List<HostAndPort> proxies) {
|
||||
, Iterable<HostAndPort> proxies) {
|
||||
this.logger = logger;
|
||||
this.rateLimit = Math.max(rateLimit, 600);
|
||||
this.sslFactory = buildAddresses(logger, localAddresses);
|
||||
@@ -74,10 +75,10 @@ public class MojangApiConnector {
|
||||
/**
|
||||
* @return null on non-premium
|
||||
*/
|
||||
public UUID getPremiumUUID(String playerName) {
|
||||
public Optional<UUID> getPremiumUUID(String playerName) {
|
||||
if (!validNameMatcher.matcher(playerName).matches()) {
|
||||
//check if it's a valid player name
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -87,7 +88,7 @@ public class MojangApiConnector {
|
||||
if (proxies.hasNext()) {
|
||||
connection = getConnection(UUID_LINK + playerName, proxies.next());
|
||||
} else {
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -98,7 +99,7 @@ public class MojangApiConnector {
|
||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line = reader.readLine();
|
||||
return getUUIDFromJson(line);
|
||||
return Optional.of(getUUIDFromJson(line));
|
||||
}
|
||||
} else if (connection.getResponseCode() == RATE_LIMIT_CODE) {
|
||||
logger.info("RATE_LIMIT REACHED");
|
||||
@@ -112,7 +113,7 @@ public class MojangApiConnector {
|
||||
logger.log(Level.SEVERE, "Failed to check if player has a paid account", ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public boolean hasJoinedServer(LoginSession session, String serverId, InetSocketAddress ip) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.github.games647.fastlogin.core.shared;
|
||||
import com.github.games647.fastlogin.core.PlayerProfile;
|
||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -38,13 +39,13 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
||||
return;
|
||||
}
|
||||
|
||||
UUID premiumUUID = null;
|
||||
Optional<UUID> premiumUUID = Optional.empty();
|
||||
if (config.get("nameChangeCheck", false) || config.get("autoRegister", false)) {
|
||||
premiumUUID = core.getApiConnector().getPremiumUUID(username);
|
||||
}
|
||||
|
||||
if (premiumUUID == null
|
||||
|| (!checkNameChange(source, username, premiumUUID)
|
||||
if (!premiumUUID.isPresent()
|
||||
|| (!checkNameChange(source, username, premiumUUID.get())
|
||||
&& !checkPremiumName(source, username, profile))) {
|
||||
//nothing detected the player as premium -> start a cracked session
|
||||
if (core.getConfig().get("switchMode", false)) {
|
||||
|
||||
Reference in New Issue
Block a user