|
1 | 1 | package com.lumaa.libu; |
2 | 2 |
|
3 | 3 | import com.lumaa.libu.items.ModItems; |
4 | | -import com.lumaa.libu.update.ModrinthMod; |
5 | | -import com.lumaa.libu.update.UpdateChecker; |
6 | | -import com.lumaa.libu.update.UpdateScreen; |
7 | 4 | import net.fabricmc.api.ClientModInitializer; |
8 | 5 | import net.fabricmc.api.EnvType; |
9 | 6 | import net.fabricmc.api.Environment; |
10 | 7 | import net.fabricmc.loader.api.FabricLoader; |
11 | | -import net.minecraft.client.MinecraftClient; |
12 | | -import net.minecraft.text.Text; |
13 | 8 | import org.slf4j.Logger; |
14 | 9 | import org.slf4j.LoggerFactory; |
15 | 10 |
|
16 | | -import java.io.IOException; |
17 | | -import java.util.ArrayList; |
18 | | - |
19 | 11 | @Environment(EnvType.CLIENT) |
20 | 12 | public class LibuLibClient implements ClientModInitializer { |
21 | 13 | public static final Logger logger = LoggerFactory.getLogger("libu"); |
22 | 14 | private static final String ID = "libu"; |
23 | 15 |
|
24 | | - private static ArrayList<UpdateChecker> updates = new ArrayList<UpdateChecker>(); |
25 | 16 | private static final String versionId = FabricLoader.getInstance() |
26 | 17 | .getModContainer("libu") |
27 | 18 | .orElseThrow() |
28 | 19 | .getMetadata() |
29 | 20 | .getVersion() |
30 | 21 | .getFriendlyString(); |
31 | | - public static final UpdateChecker updateChecker = new UpdateChecker(new ModrinthMod("LibuLib", "libu", versionId)); |
32 | | - private static boolean updateDisplayed = false; |
33 | 22 |
|
34 | 23 | @Override |
35 | 24 | public void onInitializeClient() { |
36 | 25 | logger.info("[LibuLib] Awakened"); |
37 | 26 |
|
38 | 27 | ModItems.registerAll(); |
39 | | - |
40 | | - try { |
41 | | - updateChecker.findLatestVersion(); |
42 | | - updates.add(updateChecker); // add independently to avoid log |
43 | | - } catch (IOException e) { |
44 | | - e.printStackTrace(); |
45 | | - } |
46 | | - } |
47 | | - |
48 | | - public static ArrayList<UpdateChecker> getUpdates() { |
49 | | - return updates; |
50 | | - } |
51 | | - |
52 | | - /** |
53 | | - * Add an update to the update queue |
54 | | - * @param update An {@link UpdateChecker} |
55 | | - */ |
56 | | - public static void addUpdate(UpdateChecker update) { |
57 | | - if (updates != null && !updates.contains(update)) { |
58 | | - LibuLibClient.updates.add(update); |
59 | | - LibuLibClient.logger.info("[LibuLib] Found compatibility with " + update.getMod().name); |
60 | | - } |
61 | | - } |
62 | | - |
63 | | - /** |
64 | | - * Displays using {@link UpdateScreen} all the required updates if there are |
65 | | - * @see LibuLibClient#addUpdate(UpdateChecker) |
66 | | - * @see LibuLibClient#displayUpdates() |
67 | | - */ |
68 | | - public static void displayUpdates() { |
69 | | - updateDisplayed = true; |
70 | | - if (getUpdates().size() > 0) { |
71 | | - getUpdates().forEach(update -> { |
72 | | - try { |
73 | | - if (!update.getString("version_number").equals(update.getMod().versionId) && !update.isShown()) { |
74 | | - MinecraftClient client = MinecraftClient.getInstance(); |
75 | | - if (update.getMod().versionId.toLowerCase().trim().equals("dev")) { |
76 | | - update.setShown(true); |
77 | | - logger.info(update.getMod().name + "'s Developer version prevented an update."); |
78 | | - } else { |
79 | | - update.setShown(true); |
80 | | - client.setScreen(new UpdateScreen(client.currentScreen, update.getMod(), Text.translatable("update.libulib.title", update.getMod().name), Text.translatable("update.libulib.description", update.getMod().name, update.getMod().versionId, update.getString("version_number"), update.getMod().name))); |
81 | | - } |
82 | | - } |
83 | | - } catch (IOException e) { |
84 | | - e.printStackTrace(); |
85 | | - } |
86 | | - }); |
87 | | - } else { |
88 | | - logger.error("[LibuLib] No mods in UpdateChecker list"); |
89 | | - } |
90 | | - } |
91 | | - |
92 | | - /** |
93 | | - * Prints all the required updates if there are |
94 | | - * @see LibuLibClient#addUpdate(UpdateChecker) |
95 | | - * @see LibuLibClient#displayUpdates() |
96 | | - */ |
97 | | - public static void printUpdates() { |
98 | | - updateDisplayed = true; |
99 | | - if (getUpdates().size() > 0) { |
100 | | - getUpdates().forEach(update -> { |
101 | | - if (!update.getString("version_number").equals(update.getMod().versionId) && !update.isShown()) { |
102 | | - if (update.getMod().versionId.toLowerCase().trim().equals("dev")) { |
103 | | - update.setShown(true); |
104 | | - logger.info(update.getMod().name + "'s Developer version prevented an update."); |
105 | | - } else { |
106 | | - update.setShown(true); |
107 | | - logger.warn("%s requires an update for version %s!".formatted(update.getString(update.getMod().name), update.getString("version_number"))); |
108 | | - } |
109 | | - } |
110 | | - }); |
111 | | - } else { |
112 | | - logger.error("[LibuLib] No mods in UpdateChecker list"); |
113 | | - } |
114 | | - } |
115 | | - |
116 | | - /** |
117 | | - * Returns a boolean if the {@link LibuLibClient#displayUpdates()} has been called before or not |
118 | | - * @return Boolean if updates were displayed |
119 | | - */ |
120 | | - public static boolean hasUpdateDisplayed() { |
121 | | - return updateDisplayed; |
122 | 28 | } |
123 | 29 | } |
0 commit comments