Skip to content

Commit

Permalink
Add more detailed error messages to /skin and a timeout of 15 seconds (
Browse files Browse the repository at this point in the history
  • Loading branch information
OptimisticDeving authored Aug 1, 2024
1 parent 6fc8d11 commit e20467b
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pw.kaboom.extras.modules.player.skin;

import com.google.gson.Gson;
import java.lang.InterruptedException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
Expand All @@ -10,8 +11,12 @@
import java.util.UUID;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -58,8 +63,22 @@ public static void applySkin(final Player player, final String name,
final SkinData skinData;

try {
skinData = getSkinData(name).get();
} catch (Exception e) {
skinData = getSkinData(name).get(15, TimeUnit.SECONDS);
} catch (InterruptedException e) {
if (!shouldSendMessage) {
return;
}

player.sendMessage(Component.text("Skin fetching was interrupted"));
return;
} catch (TimeoutException e) {
if (!shouldSendMessage) {
return;
}

player.sendMessage(Component.text("Took too long to fetch skin"));
return;
} catch (ExecutionException | CompletionException e) {
if(!shouldSendMessage) {
return;
}
Expand Down

0 comments on commit e20467b

Please sign in to comment.