From 901b136fa81dc84d9957acd12797d031a2a28ca2 Mon Sep 17 00:00:00 2001 From: OptimisticDeving <173472493+OptimisticDeving@users.noreply.github.com> Date: Sun, 23 Jun 2024 15:56:41 +0000 Subject: [PATCH] Add more detailed error messages to /skin and a timeout of 15 seconds --- .../modules/player/skin/SkinManager.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/modules/player/skin/SkinManager.java b/src/main/java/pw/kaboom/extras/modules/player/skin/SkinManager.java index 51d271b..299b34d 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/skin/SkinManager.java +++ b/src/main/java/pw/kaboom/extras/modules/player/skin/SkinManager.java @@ -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; @@ -10,8 +11,12 @@ import java.util.List; 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; @@ -58,8 +63,22 @@ public final class SkinManager { 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; }