From dd69bdcbbcf79596622b09bb9f2ca13b2b119539 Mon Sep 17 00:00:00 2001 From: TheFaser Date: Wed, 27 Dec 2023 14:25:00 +0500 Subject: [PATCH] Integrations: "fix" hook SkinRestorer --- .../module/integrations/FSkinsRestorer.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/flectone/chat/module/integrations/FSkinsRestorer.java b/src/main/java/net/flectone/chat/module/integrations/FSkinsRestorer.java index 25bba7b..77ae550 100644 --- a/src/main/java/net/flectone/chat/module/integrations/FSkinsRestorer.java +++ b/src/main/java/net/flectone/chat/module/integrations/FSkinsRestorer.java @@ -7,13 +7,14 @@ import net.skinsrestorer.api.exception.DataRequestException; import net.skinsrestorer.api.property.SkinProperty; import net.skinsrestorer.api.storage.PlayerStorage; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Optional; -public class FSkinsRestorer implements FIntegration{ +public class FSkinsRestorer implements FIntegration { private SkinsRestorer skinsRestorer; @@ -23,13 +24,30 @@ public FSkinsRestorer() { @Override public void init() { + firstHook(); + } + + private void firstHook() { try { skinsRestorer = SkinsRestorerProvider.get(); - } catch (IllegalStateException e) { - FlectoneChat.warning("SkinsRestorerAPI is not initialized yet. This is due to proxy"); + FlectoneChat.info("SkinsRestorer detected and hooked"); + } catch (Exception e) { + FlectoneChat.warning("SkinsRestorer is not initialized yet. This is due to proxy. The second hook attempt will be in 10 seconds"); + secondHook(); } } + private void secondHook() { + Bukkit.getScheduler().runTaskLaterAsynchronously(FlectoneChat.getPlugin(), () -> { + try { + skinsRestorer = SkinsRestorerProvider.get(); + FlectoneChat.info("SkinsRestorer detected and hooked"); + } catch (Exception e) { + FlectoneChat.warning("SkinsRestorer is not initialized after all"); + } + }, 200L); + } + @Nullable public String getTextureId(@NotNull Player player) { if (skinsRestorer == null) return null;