Skip to content
This repository was archived by the owner on Aug 13, 2023. It is now read-only.

Commit f3ac032

Browse files
author
Lumaa
committed
optimizations
1 parent 1bf661d commit f3ac032

File tree

4 files changed

+0
-198
lines changed

4 files changed

+0
-198
lines changed
Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,29 @@
11
package com.lumaa.libu;
22

33
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;
74
import net.fabricmc.api.ClientModInitializer;
85
import net.fabricmc.api.EnvType;
96
import net.fabricmc.api.Environment;
107
import net.fabricmc.loader.api.FabricLoader;
11-
import net.minecraft.client.MinecraftClient;
12-
import net.minecraft.text.Text;
138
import org.slf4j.Logger;
149
import org.slf4j.LoggerFactory;
1510

16-
import java.io.IOException;
17-
import java.util.ArrayList;
18-
1911
@Environment(EnvType.CLIENT)
2012
public class LibuLibClient implements ClientModInitializer {
2113
public static final Logger logger = LoggerFactory.getLogger("libu");
2214
private static final String ID = "libu";
2315

24-
private static ArrayList<UpdateChecker> updates = new ArrayList<UpdateChecker>();
2516
private static final String versionId = FabricLoader.getInstance()
2617
.getModContainer("libu")
2718
.orElseThrow()
2819
.getMetadata()
2920
.getVersion()
3021
.getFriendlyString();
31-
public static final UpdateChecker updateChecker = new UpdateChecker(new ModrinthMod("LibuLib", "libu", versionId));
32-
private static boolean updateDisplayed = false;
3322

3423
@Override
3524
public void onInitializeClient() {
3625
logger.info("[LibuLib] Awakened");
3726

3827
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;
12228
}
12329
}
Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,26 @@
11
package com.lumaa.libu;
22

33
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.util.BetterText;
7-
import com.lumaa.libu.util.Color;
84
import net.fabricmc.api.DedicatedServerModInitializer;
95
import net.fabricmc.api.EnvType;
106
import net.fabricmc.api.Environment;
117
import net.fabricmc.loader.api.FabricLoader;
12-
import net.minecraft.server.network.ServerPlayerEntity;
138
import org.slf4j.Logger;
149
import org.slf4j.LoggerFactory;
1510

16-
import java.io.IOException;
17-
import java.util.ArrayList;
18-
1911
@Environment(EnvType.SERVER)
2012
public class LibuLibServer implements DedicatedServerModInitializer {
2113
private static final Logger logger = LoggerFactory.getLogger("libu");
2214

23-
private static ArrayList<UpdateChecker> updates = new ArrayList<>();
2415
private static final String versionId = FabricLoader.getInstance()
2516
.getModContainer("libu")
2617
.orElseThrow()
2718
.getMetadata()
2819
.getVersion()
2920
.getFriendlyString();
30-
public static final UpdateChecker updateChecker = new UpdateChecker(new ModrinthMod("LibuLib", "libu", versionId));
3121

3222
@Override
3323
public void onInitializeServer() {
3424
ModItems.registerAll();
35-
36-
try {
37-
updateChecker.findLatestVersion();
38-
updates.add(updateChecker); // add independently to avoid log
39-
} catch (IOException e) {
40-
e.printStackTrace();
41-
}
42-
}
43-
44-
/**
45-
* Add an update to the update queue
46-
* @param update An {@link UpdateChecker}
47-
*/
48-
public static void addUpdate(UpdateChecker update) {
49-
if (updates != null && !updates.contains(update)) {
50-
updates.add(update);
51-
logger.info("[LibuLib] Found compatibility with " + update.getMod().name);
52-
}
53-
}
54-
55-
/**
56-
* Prints all the required updates if there are
57-
*/
58-
public static void printUpdates() {
59-
if (updates.size() > 0) {
60-
updates.forEach(update -> {
61-
if (!update.getString("version_number").equals(update.getMod().versionId) && !update.isShown()) {
62-
if (update.getMod().versionId.toLowerCase().trim().equals("dev")) {
63-
update.setShown(true);
64-
logger.info(update.getMod().name + "'s Developer version prevented an update message.");
65-
} else {
66-
update.setShown(true);
67-
logger.warn("%s requires an update for version %s!".formatted(update.getString(update.getMod().name), update.getString("version_number")));
68-
}
69-
}
70-
});
71-
} else {
72-
logger.error("[LibuLib] No mods in UpdateChecker list");
73-
}
74-
}
75-
76-
/**
77-
* Send a message to a player all the required updates if there are
78-
*/
79-
public static void sendUpdates(ServerPlayerEntity player) {
80-
if (updates.size() > 0) {
81-
updates.forEach(update -> {
82-
if (!update.getString("version_number").equals(update.getMod().versionId) && !update.isShown()) {
83-
if (update.getMod().versionId.toLowerCase().trim().equals("dev")) {
84-
update.setShown(true);
85-
player.sendMessageToClient(new BetterText("[LibuLib] This server uses a developer version of %s.".formatted(update.getMod().name), BetterText.TextType.LITERAL).withColor(Color.brand), false);
86-
} else {
87-
update.setShown(true);
88-
player.sendMessageToClient(new BetterText("[LibuLib] This server uses an outdated version of %s.".formatted(update.getMod().name), BetterText.TextType.LITERAL).withColor(Color.brand), false);
89-
}
90-
}
91-
});
92-
} else {
93-
logger.error("[LibuLib] No mods in UpdateChecker list");
94-
}
9525
}
9626
}

src/main/java/com/lumaa/libu/events/LibuServerTickEvents.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main/java/com/lumaa/libu/events/ServerConnectionEvents.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)