1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
TheBusyBiscuit 2021-09-09 13:54:48 +02:00
parent 68e32cb358
commit 79c6c139c6
3 changed files with 25 additions and 22 deletions

View File

@ -37,6 +37,7 @@
#### Fixes #### Fixes
* Fixed #3218 * Fixed #3218
* Fixed #3241
## Release Candidate 28 (06 Sep 2021) ## Release Candidate 28 (06 Sep 2021)

View File

@ -71,7 +71,7 @@ public class GitHubService {
long period = TimeUnit.HOURS.toMillis(1); long period = TimeUnit.HOURS.toMillis(1);
GitHubTask task = new GitHubTask(this); 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); contributors.put(name, contributor);
} }
@Nonnull public @Nonnull Contributor addContributor(@Nonnull String minecraftName, @Nonnull String profileURL, @Nonnull String role, int commits) {
public Contributor addContributor(@Nonnull String minecraftName, @Nonnull String profileURL, @Nonnull String role, int commits) {
Validate.notNull(minecraftName, "Minecraft username must not be null."); Validate.notNull(minecraftName, "Minecraft username must not be null.");
Validate.notNull(profileURL, "GitHub profile url must not be null."); Validate.notNull(profileURL, "GitHub profile url must not be null.");
Validate.notNull(role, "Role should not be null."); Validate.notNull(role, "Role should not be null.");
@ -118,8 +117,7 @@ public class GitHubService {
return contributor; return contributor;
} }
@Nonnull public @Nonnull Contributor addContributor(@Nonnull String username, @Nonnull String role, int commits) {
public Contributor addContributor(@Nonnull String username, @Nonnull String role, int commits) {
Validate.notNull(username, "Username must not be null."); Validate.notNull(username, "Username must not be null.");
Validate.notNull(role, "Role should not be null."); Validate.notNull(role, "Role should not be null.");
Validate.isTrue(commits >= 0, "Commit count cannot be negative."); Validate.isTrue(commits >= 0, "Commit count cannot be negative.");
@ -158,8 +156,7 @@ public class GitHubService {
})); }));
} }
@Nonnull protected @Nonnull Set<GitHubConnector> getConnectors() {
protected Set<GitHubConnector> getConnectors() {
return connectors; return connectors;
} }
@ -172,8 +169,7 @@ public class GitHubService {
* *
* @return A {@link ConcurrentMap} containing all {@link Contributor Contributors} * @return A {@link ConcurrentMap} containing all {@link Contributor Contributors}
*/ */
@Nonnull public @Nonnull ConcurrentMap<String, Contributor> getContributors() {
public ConcurrentMap<String, Contributor> getContributors() {
return contributors; 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 * @return The id of our GitHub Repository
*/ */
@Nonnull public @Nonnull String getRepository() {
public String getRepository() {
return repository; return repository;
} }
@ -228,8 +223,7 @@ public class GitHubService {
* *
* @return A {@link LocalDateTime} object representing the date and time of the latest commit * @return A {@link LocalDateTime} object representing the date and time of the latest commit
*/ */
@Nonnull public @Nonnull LocalDateTime getLastUpdate() {
public LocalDateTime getLastUpdate() {
return lastUpdate; return lastUpdate;
} }
@ -263,8 +257,7 @@ public class GitHubService {
* *
* @return The cached skin texture for that user (or null) * @return The cached skin texture for that user (or null)
*/ */
@Nullable protected @Nullable String getCachedTexture(@Nonnull String username) {
protected String getCachedTexture(@Nonnull String username) {
return texturesCache.getString(username); return texturesCache.getString(username);
} }
} }

View File

@ -7,6 +7,8 @@ import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level; import java.util.logging.Level;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -105,13 +107,18 @@ class GitHubTask implements Runnable {
} catch (IllegalArgumentException x) { } catch (IllegalArgumentException x) {
// There cannot be a texture found because it is not a valid MC username // There cannot be a texture found because it is not a valid MC username
contributor.setTexture(null); contributor.setTexture(null);
} catch (InterruptedException x) {
Slimefun.logger().log(Level.WARNING, "The contributors thread was interrupted!");
Thread.currentThread().interrupt();
} catch (Exception x) { } catch (Exception x) {
// Too many requests // 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, "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, this is not an error message!"); 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 String msg = x.getMessage();
if (x.getMessage().contains("429")) {
// 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); Bukkit.getScheduler().runTaskLaterAsynchronously(Slimefun.instance(), this::grabTextures, 5 * 60 * 20L);
} }
@ -122,12 +129,14 @@ class GitHubTask implements Runnable {
return 0; return 0;
} }
private @Nullable String pullTexture(@Nonnull Contributor contributor, @Nonnull Map<String, String> skins) throws InterruptedException, ExecutionException { private @Nullable String pullTexture(@Nonnull Contributor contributor, @Nonnull Map<String, String> skins) throws InterruptedException, ExecutionException, TimeoutException {
Optional<UUID> uuid = contributor.getUniqueId(); Optional<UUID> uuid = contributor.getUniqueId();
if (!uuid.isPresent()) { if (!uuid.isPresent()) {
CompletableFuture<UUID> future = UUIDLookup.forUsername(Slimefun.instance(), contributor.getMinecraftName()); CompletableFuture<UUID> 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); uuid.ifPresent(contributor::setUniqueId);
} }