diff --git a/CHANGELOG.md b/CHANGELOG.md index b368dfb13..a455e6c9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ #### Fixes * Fixed #3218 +* Fixed #3241 ## Release Candidate 28 (06 Sep 2021) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java index 73c879d22..56e978028 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java @@ -71,7 +71,7 @@ public class GitHubService { long period = TimeUnit.HOURS.toMillis(1); GitHubTask task = new GitHubTask(this); - plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, task, 80L, period); + plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, task, 30 * 20L, period); } /** @@ -103,8 +103,7 @@ public class GitHubService { contributors.put(name, contributor); } - @Nonnull - public Contributor addContributor(@Nonnull String minecraftName, @Nonnull String profileURL, @Nonnull String role, int commits) { + public @Nonnull Contributor addContributor(@Nonnull String minecraftName, @Nonnull String profileURL, @Nonnull String role, int commits) { Validate.notNull(minecraftName, "Minecraft username must not be null."); Validate.notNull(profileURL, "GitHub profile url must not be null."); Validate.notNull(role, "Role should not be null."); @@ -118,8 +117,7 @@ public class GitHubService { return contributor; } - @Nonnull - public Contributor addContributor(@Nonnull String username, @Nonnull String role, int commits) { + public @Nonnull Contributor addContributor(@Nonnull String username, @Nonnull String role, int commits) { Validate.notNull(username, "Username must not be null."); Validate.notNull(role, "Role should not be null."); Validate.isTrue(commits >= 0, "Commit count cannot be negative."); @@ -158,8 +156,7 @@ public class GitHubService { })); } - @Nonnull - protected Set getConnectors() { + protected @Nonnull Set getConnectors() { return connectors; } @@ -172,8 +169,7 @@ public class GitHubService { * * @return A {@link ConcurrentMap} containing all {@link Contributor Contributors} */ - @Nonnull - public ConcurrentMap getContributors() { + public @Nonnull ConcurrentMap getContributors() { return contributors; } @@ -205,12 +201,11 @@ public class GitHubService { } /** - * Returns the id of Slimefun's GitHub Repository. (e.g. "TheBusyBiscuit/Slimefun4"). + * Returns the id of Slimefun's GitHub Repository. (e.g. "Slimefun/Slimefun4"). * * @return The id of our GitHub Repository */ - @Nonnull - public String getRepository() { + public @Nonnull String getRepository() { return repository; } @@ -228,8 +223,7 @@ public class GitHubService { * * @return A {@link LocalDateTime} object representing the date and time of the latest commit */ - @Nonnull - public LocalDateTime getLastUpdate() { + public @Nonnull LocalDateTime getLastUpdate() { return lastUpdate; } @@ -263,8 +257,7 @@ public class GitHubService { * * @return The cached skin texture for that user (or null) */ - @Nullable - protected String getCachedTexture(@Nonnull String username) { + protected @Nullable String getCachedTexture(@Nonnull String username) { return texturesCache.getString(username); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java index 4e4397020..fb3647285 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java @@ -7,6 +7,8 @@ import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.logging.Level; import javax.annotation.Nonnull; @@ -105,13 +107,18 @@ class GitHubTask implements Runnable { } catch (IllegalArgumentException x) { // There cannot be a texture found because it is not a valid MC username contributor.setTexture(null); + } catch (InterruptedException x) { + Slimefun.logger().log(Level.WARNING, "The contributors thread was interrupted!"); + Thread.currentThread().interrupt(); } catch (Exception x) { // Too many requests - Slimefun.logger().log(Level.WARNING, "Attempted to connect to mojang.com, got this response: {0}: {1}", new Object[] { x.getClass().getSimpleName(), x.getMessage() }); - Slimefun.logger().log(Level.WARNING, "This usually means mojang.com is temporarily down or started to rate-limit this connection, this is not an error message!"); + Slimefun.logger().log(Level.WARNING, "Attempted to refresh skin cache, got this response: {0}: {1}", new Object[] { x.getClass().getSimpleName(), x.getMessage() }); + Slimefun.logger().log(Level.WARNING, "This usually means mojang.com is temporarily down or started to rate-limit this connection, nothing to worry about!"); - // Retry after 5 minutes if it was rate-limiting - if (x.getMessage().contains("429")) { + String msg = x.getMessage(); + + // Retry after 5 minutes if it was just rate-limiting + if (msg != null && msg.contains("429")) { Bukkit.getScheduler().runTaskLaterAsynchronously(Slimefun.instance(), this::grabTextures, 5 * 60 * 20L); } @@ -122,12 +129,14 @@ class GitHubTask implements Runnable { return 0; } - private @Nullable String pullTexture(@Nonnull Contributor contributor, @Nonnull Map skins) throws InterruptedException, ExecutionException { + private @Nullable String pullTexture(@Nonnull Contributor contributor, @Nonnull Map skins) throws InterruptedException, ExecutionException, TimeoutException { Optional uuid = contributor.getUniqueId(); if (!uuid.isPresent()) { CompletableFuture future = UUIDLookup.forUsername(Slimefun.instance(), contributor.getMinecraftName()); - uuid = Optional.ofNullable(future.get()); + + // Fixes #3241 - Do not wait for more than 30 seconds + uuid = Optional.ofNullable(future.get(30, TimeUnit.SECONDS)); uuid.ifPresent(contributor::setUniqueId); }