|
18 | 18 | import java.util.ArrayList; |
19 | 19 | import java.util.List; |
20 | 20 | import java.util.Objects; |
| 21 | +import java.util.concurrent.ExecutionException; |
| 22 | +import java.util.concurrent.ExecutorService; |
| 23 | +import java.util.concurrent.Executors; |
| 24 | +import java.util.concurrent.Future; |
21 | 25 | import java.util.stream.Collectors; |
22 | 26 | import java.util.stream.Stream; |
23 | 27 |
|
@@ -63,14 +67,31 @@ public static void init(Path minecraftPath, String minecraftVersion, String load |
63 | 67 | List<ResourcePack> languagePacks = new ArrayList<>(); |
64 | 68 | boolean convertNotNeed = assets.downloads.size() == 1 && assets.downloads.get(0).targetVersion.equals(minecraftVersion); |
65 | 69 | String applyFileName = assets.downloads.get(0).fileName; |
66 | | - for (GameAssetDetail.AssetDownloadDetail it : assets.downloads) { |
67 | | - FileUtil.setTemporaryDirPath(Paths.get(localStorage, "." + MOD_ID, it.targetVersion)); |
68 | | - ResourcePack languagePack = new ResourcePack(it.fileName, convertNotNeed); |
69 | | - languagePack.checkUpdate(it.fileUrl, it.md5Url); |
70 | | - languagePacks.add(languagePack); |
| 70 | + ExecutorService executor = Executors.newFixedThreadPool(assets.downloads.size()); |
| 71 | + try { |
| 72 | + List<Future<?>> futures = new ArrayList<>(); |
| 73 | + for (GameAssetDetail.AssetDownloadDetail it : assets.downloads) { |
| 74 | + futures.add(executor.submit(() -> { |
| 75 | + FileUtil.setTemporaryDirPath(Paths.get(localStorage, "." + MOD_ID, it.targetVersion)); |
| 76 | + ResourcePack languagePack = new ResourcePack(it.fileName, convertNotNeed); |
| 77 | + try { |
| 78 | + languagePack.checkUpdate(it.fileUrl, it.md5Url); |
| 79 | + } catch (Exception e) { |
| 80 | + Log.debug(String.format("Error while checking update for resource pack: %s", e)); |
| 81 | + } |
| 82 | + languagePacks.add(languagePack); |
| 83 | + })); |
| 84 | + } |
| 85 | + for (Future<?> future : futures) { |
| 86 | + try { |
| 87 | + future.get(); |
| 88 | + } catch (InterruptedException | ExecutionException e) { |
| 89 | + Log.debug(String.format("Error while updating resource pack: %s", e)); |
| 90 | + } |
| 91 | + } |
| 92 | + } finally { |
| 93 | + executor.shutdown(); |
71 | 94 | } |
72 | | - |
73 | | - //Convert resourcepack |
74 | 95 | if (!convertNotNeed) { |
75 | 96 | FileUtil.setTemporaryDirPath(Paths.get(localStorage, "." + MOD_ID, minecraftVersion)); |
76 | 97 | applyFileName = assets.covertFileName; |
|
0 commit comments