Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Integrations: "fix" hook SkinRestorer
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Dec 27, 2023
1 parent f39f672 commit dd69bdc
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit dd69bdc

Please sign in to comment.