use of com.github.games647.craftapi.resolver.RateLimitException in project FastLogin by games647.
the class FloodgateManagement method run.
@Override
public void run() {
core.getPlugin().getLog().info("Player {} is connecting through Geyser Floodgate.", username);
// check if the Bedrock player is linked to a Java account
isLinked = floodgatePlayer.getLinkedPlayer() != null;
// if that's the case, players will be logged in via plugin messages
if (core.getStorage() == null) {
return;
}
profile = core.getStorage().loadProfile(username);
AuthPlugin<P> authPlugin = core.getAuthPluginHook();
try {
// maybe Bungee without auth plugin
if (authPlugin == null) {
if (profile != null) {
isRegistered = profile.isPremium();
} else {
isRegistered = false;
}
} else {
isRegistered = authPlugin.isRegistered(username);
}
} catch (Exception ex) {
core.getPlugin().getLog().error("An error has occured while checking if player {} is registered", username, ex);
return;
}
// decide if checks should be made for conflicting Java player names
if (isNameCheckRequired()) {
// check for conflicting Premium Java name
Optional<Profile> premiumUUID = Optional.empty();
try {
premiumUUID = core.getResolver().findProfile(username);
} catch (IOException | RateLimitException e) {
core.getPlugin().getLog().error("Could not check whether Floodgate Player {}'s name conflicts a premium Java account's name.", username, e);
return;
}
// stop execution if player's name is conflicting
if (premiumUUID.isPresent()) {
return;
}
}
if (!isRegistered && !isAutoAuthAllowed(autoRegisterFloodgate)) {
return;
}
// logging in from bedrock for a second time threw an error with UUID
if (profile == null) {
profile = new StoredProfile(getUUID(player), username, true, getAddress(player).toString());
}
// start Bukkit/Bungee specific tasks
startLogin();
}
use of com.github.games647.craftapi.resolver.RateLimitException in project CraftAPI by games647.
the class MojangResolver method findProfile.
@Override
public Optional<Profile> findProfile(String name) throws IOException, RateLimitException {
Optional<Profile> optProfile = cache.getByName(name);
if (optProfile.isPresent() || !validNamePredicate.test(name)) {
return optProfile;
}
String url = UUID_URL + name;
HttpURLConnection conn = getConnection(url);
int responseCode = conn.getResponseCode();
if (responseCode == RateLimitException.RATE_LIMIT_RESPONSE_CODE) {
if (conn.usingProxy()) {
throw new RateLimitException();
}
conn = getProxyConnection(url);
responseCode = conn.getResponseCode();
}
if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
return Optional.empty();
}
// todo: print errorstream on IOException
Profile profile = readJson(conn.getInputStream(), Profile.class);
cache.add(profile);
return Optional.of(profile);
}
Aggregations