66import com .google .gson .JsonParser ;
77import com .google .gson .JsonPrimitive ;
88import lombok .*;
9- import okhttp3 .OkHttpClient ;
109import okhttp3 .Request ;
1110import okhttp3 .Response ;
1211import org .apache .commons .codec .digest .DigestUtils ;
1312import org .bukkit .configuration .file .YamlConfiguration ;
1413import org .jetbrains .annotations .NotNull ;
1514import org .jetbrains .annotations .Nullable ;
1615import org .maxgamer .quickshop .QuickShop ;
16+ import org .maxgamer .quickshop .util .HttpUtil ;
1717import org .maxgamer .quickshop .util .JsonUtil ;
1818import org .maxgamer .quickshop .util .Util ;
1919import org .maxgamer .quickshop .util .language .text .distributions .Distribution ;
@@ -36,14 +36,10 @@ public class CrowdinOTA implements Distribution {
3636 .recordStats ()
3737 .build ();
3838 private final QuickShop plugin ;
39- private final OkHttpClient client ;
4039
4140 public CrowdinOTA (QuickShop plugin ) {
4241 this .plugin = plugin ;
4342 Util .getCacheFolder ().mkdirs ();
44- this .client = new OkHttpClient .Builder ()
45- .cache (new okhttp3 .Cache (new File (Util .getCacheFolder (), "okhttp" ), 50L * 1024L * 1024L ))
46- .build ();
4743
4844 }
4945 /**
@@ -67,7 +63,7 @@ public String getManifestJson() {
6763 if (requestCachePool .getIfPresent (url ) != null ) {
6864 return requestCachePool .getIfPresent (url );
6965 }
70- try (Response response = client .newCall (new Request .Builder ().get ().url (url ).build ()).execute ()) {
66+ try (Response response = HttpUtil . instance (). getClient () .newCall (new Request .Builder ().get ().url (url ).build ()).execute ()) {
7167 val body = response .body ();
7268 if (body == null ) {
7369 return null ;
@@ -176,7 +172,7 @@ public String getFile(String fileCrowdinPath, String crowdinLocale, boolean forc
176172 if (forceFlush || data == null || localeTimestamp != manifest .getTimestamp ()) {
177173 String url = CROWDIN_OTA_HOST + "content" + fileCrowdinPath .replace ("%locale%" , crowdinLocale );
178174 Util .debugLog ("Reading data from remote server: " + url );
179- try (Response response = client .newCall (new Request .Builder ().get ().url (url ).build ()).execute ()) {
175+ try (Response response = HttpUtil . instance (). getClient () .newCall (new Request .Builder ().get ().url (url ).build ()).execute ()) {
180176 val body = response .body ();
181177 if (body == null ) {
182178 throw new OTAException (response .code (), "" ); // Returns empty string (failed to getting content)
0 commit comments