Skip to content

Commit 1b5c350

Browse files
Merge pull request #546 from Swofty-Developments/claude/fix-unoptimized-systems-01M2C1ufELKFRcKCVZLusbhL
Find and fix unoptimized or broken systems
2 parents b9c2a32 + 4149f29 commit 1b5c350

53 files changed

Lines changed: 744 additions & 346 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

anticheat/src/main/java/net/swofty/anticheat/event/SwoftyEventHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.swofty.anticheat.event;
22

3+
import org.tinylog.Logger;
4+
35
import java.lang.reflect.Method;
46
import java.util.ArrayList;
57
import java.util.HashMap;
@@ -30,7 +32,8 @@ public static void callEvent(Object event) {
3032
try {
3133
entry.method.invoke(entry.instance, event);
3234
} catch (Exception e) {
33-
e.printStackTrace();
35+
Logger.error(e, "Failed to invoke event listener method {} for event {}",
36+
entry.method.getName(), event.getClass().getSimpleName());
3437
}
3538
}
3639
}

anticheat/src/main/java/net/swofty/anticheat/loader/minestom/MinestomLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public void sendPacket(UUID uuid, SwoftyPacket packet) {
9090
try {
9191
player.sendPacket((SendablePacket) getPacketHandler(packet).buildLoaderPacket(uuid, packet));
9292
} catch (Exception e) {
93-
Logger.error("Error when attempting to send packet " + packet.getClass().getSimpleName() + " to " + uuid);
94-
e.printStackTrace();
93+
Logger.error(e, "Error when attempting to send packet {} to player {}",
94+
packet.getClass().getSimpleName(), uuid);
9595
}
9696
}
9797

commons/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ dependencies {
1818
implementation("org.yaml:snakeyaml:2.2")
1919
implementation(project(":packer"))
2020
implementation("org.mongodb:bson:4.11.2")
21+
implementation("org.tinylog:tinylog-api:2.7.0")
22+
implementation("org.tinylog:tinylog-impl:2.7.0")
2123

2224
compileOnly("net.minestom:minestom:2025.08.18-1.21.8") {
2325
exclude(group = "org.jboss.shrinkwrap.resolver", module = "shrinkwrap-resolver-depchain")

commons/src/main/java/net/swofty/commons/Configuration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.swofty.commons;
22

33
import org.json.JSONObject;
4+
import org.tinylog.Logger;
45

56
import java.io.File;
67
import java.nio.file.Files;
@@ -20,7 +21,7 @@ public static String get(String key) {
2021
JSONObject object = new JSONObject(s);
2122
return object.get(key).toString();
2223
} catch (Exception ex) {
23-
ex.printStackTrace();
24+
Logger.error(ex, "Failed to read configuration key: {}", key);
2425
}
2526

2627
return "null";
@@ -52,7 +53,7 @@ public static JSONObject getObject(String key) {
5253
JSONObject object = new JSONObject(s);
5354
return (JSONObject) object.get(key);
5455
} catch (Exception ex) {
55-
ex.printStackTrace();
56+
Logger.error(ex, "Failed to read configuration object for key: {}", key);
5657
}
5758

5859
return null;

commons/src/main/java/net/swofty/commons/item/reforge/ReforgeExpressionEvaluator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.swofty.commons.item.reforge;
22

3+
import org.tinylog.Logger;
4+
35
import java.util.Map;
46
import java.util.Stack;
57
import java.util.regex.Matcher;
@@ -17,8 +19,7 @@ public static double evaluate(String expression, Map<String, Double> variables)
1719
// Evaluate the mathematical expression
1820
return evaluateMathExpression(processedExpression);
1921
} catch (Exception e) {
20-
System.err.println("Error evaluating expression: " + expression);
21-
e.printStackTrace();
22+
Logger.error(e, "Error evaluating reforge expression: {}", expression);
2223
return 0.0;
2324
}
2425
}

commons/src/main/java/net/swofty/commons/item/reforge/ReforgeLoader.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.swofty.commons.statistics.ItemStatistic;
66
import net.swofty.commons.statistics.ItemStatistics;
77
import org.jetbrains.annotations.Nullable;
8+
import org.tinylog.Logger;
89
import org.yaml.snakeyaml.Yaml;
910

1011
import java.io.File;
@@ -62,13 +63,11 @@ public static void loadAllReforges() {
6263
LOADED_REFORGES.put(reforge.getName().toLowerCase(), reforge);
6364
}
6465
} catch (Exception e) {
65-
System.err.println("Failed to load reforge from file: " + file.getName());
66-
e.printStackTrace();
66+
Logger.error(e, "Failed to load reforge from file: {}", file.getName());
6767
}
6868
}
6969
} catch (Exception e) {
70-
System.err.println("Failed to load reforges");
71-
e.printStackTrace();
70+
Logger.error(e, "Failed to load reforges from directory: {}", REFORGES_DIR.getPath());
7271
}
7372
}
7473

@@ -84,8 +83,7 @@ private static Reforge loadFromFile(File file) {
8483

8584
return parseReforge(config);
8685
} catch (Exception e) {
87-
System.err.println("Error loading reforge from file: " + file.getName());
88-
e.printStackTrace();
86+
Logger.error(e, "Error loading reforge from file: {}", file.getName());
8987
return null;
9088
}
9189
}
@@ -203,8 +201,7 @@ private static double evaluateExpression(String expression, int level, Map<Strin
203201

204202
return ReforgeExpressionEvaluator.evaluate(expression, context);
205203
} catch (Exception e) {
206-
System.err.println("Failed to evaluate expression: " + expression + " for level " + level);
207-
e.printStackTrace();
204+
Logger.error(e, "Failed to evaluate reforge expression '{}' for level {}", expression, level);
208205
return 0.0;
209206
}
210207
}

loader/src/main/java/net/swofty/loader/Hypixel.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.lang.reflect.InvocationTargetException;
3737
import java.util.*;
3838
import java.util.concurrent.CompletableFuture;
39+
import java.util.concurrent.TimeUnit;
3940
import java.util.concurrent.atomic.AtomicBoolean;
4041
import java.util.stream.Collectors;
4142
import java.net.InetAddress;
@@ -231,17 +232,12 @@ public void onFlag(UUID uuid, FlagType flagType) {
231232
}
232233
});
233234

234-
new Thread(() -> {
235-
try {
236-
Thread.sleep(100);
237-
} catch (InterruptedException e) {
238-
throw new RuntimeException(e);
239-
}
240-
241-
if (startServer.isDone()) return;
242-
Logger.error("Couldn't connect to proxy. Shutting down...");
243-
System.exit(0);
244-
}).start();
235+
CompletableFuture.delayedExecutor(100, TimeUnit.MILLISECONDS)
236+
.execute(() -> {
237+
if (startServer.isDone()) return;
238+
Logger.error("Couldn't connect to proxy. Shutting down...");
239+
System.exit(0);
240+
});
245241

246242
JSONObject registerMessage = new JSONObject()
247243
.put("type", serverType.name())
@@ -348,12 +344,9 @@ ToProxyChannels.PROXY_IS_ONLINE, new JSONObject(), (response) -> {
348344
});
349345
} catch (Exception e) {
350346
MinecraftServer.getConnectionManager().getOnlinePlayers().forEach(player -> player.kick("§cServer has lost connection to the proxy, please rejoin"));
351-
try {
352-
Thread.sleep(500);
353-
} catch (InterruptedException ex) {
354-
throw new RuntimeException(ex);
355-
}
356-
System.exit(0);
347+
CompletableFuture.delayedExecutor(500, TimeUnit.MILLISECONDS)
348+
.execute(() -> System.exit(0));
349+
return TaskSchedule.stop();
357350
}
358351

359352
scheduler.scheduleTask(() -> {

packer/src/main/java/net/swofty/packer/SkyBlockPacker.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public static void main(String[] args) {
3939
FileUtils.deleteDirectory(values.outputDirectory());
4040
FileUtils.copyDirectory(values.vanillaPack(), values.outputDirectory());
4141
} catch (IOException e) {
42-
System.out.println("Failed to copy vanilla pack to output directory");
42+
System.err.println("Failed to copy vanilla pack to output directory");
43+
System.err.println("From: " + values.vanillaPack() + " To: " + values.outputDirectory());
4344
e.printStackTrace();
4445
return;
4546
}
@@ -50,7 +51,8 @@ public static void main(String[] args) {
5051
try {
5152
LangModifier.modifyLangFile(values.outputDirectory());
5253
} catch (IOException e) {
53-
System.out.println("Failed to modify lang file");
54+
System.err.println("Failed to modify lang file");
55+
System.err.println("Directory: " + values.outputDirectory());
5456
e.printStackTrace();
5557
return;
5658
}
@@ -60,7 +62,8 @@ public static void main(String[] args) {
6062
try {
6163
FileUtils.copyDirectory(values.textureCategory(), values.outputDirectory() + "/assets/skyblock/textures/");
6264
} catch (IOException e) {
63-
System.out.println("Failed to move textures into custom");
65+
System.err.println("Failed to move textures into custom");
66+
System.err.println("From: " + values.textureCategory() + " To: " + values.outputDirectory() + "/assets/skyblock/textures/");
6467
e.printStackTrace();
6568
return;
6669
}
@@ -77,7 +80,8 @@ public static void main(String[] args) {
7780

7881
Files.write(new File(values.outputDirectory() + "/assets/minecraft/font/default.json").toPath(), defaultJson.getBytes());
7982
} catch (IOException e) {
80-
System.out.println("Failed to override default.json with our textures");
83+
System.err.println("Failed to override default.json with our textures");
84+
System.err.println("Directory: " + values.outputDirectory());
8185
e.printStackTrace();
8286
return;
8387
}

proxy.api/src/main/java/net/swofty/proxyapi/ProxyService.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import net.swofty.commons.protocol.ProtocolObject;
55
import net.swofty.commons.protocol.objects.PingProtocolObject;
66
import net.swofty.proxyapi.redis.ServerOutboundMessage;
7+
import org.tinylog.Logger;
78

89
import java.util.concurrent.CompletableFuture;
10+
import java.util.concurrent.TimeUnit;
911
import java.util.concurrent.atomic.AtomicBoolean;
1012

1113
public record ProxyService(ServiceType type) {
@@ -19,17 +21,12 @@ public CompletableFuture<Boolean> isOnline() {
1921
hasReceivedResponse.set(true);
2022
});
2123

22-
Thread.startVirtualThread(() -> {
23-
try {
24-
Thread.sleep(50);
25-
} catch (InterruptedException e) {
26-
e.printStackTrace();
27-
}
28-
29-
if (!hasReceivedResponse.get()) {
30-
future.complete(false);
31-
}
32-
});
24+
CompletableFuture.delayedExecutor(50, TimeUnit.MILLISECONDS)
25+
.execute(() -> {
26+
if (!hasReceivedResponse.get()) {
27+
future.complete(false);
28+
}
29+
});
3330

3431
return future;
3532
}

service.api/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ dependencies {
3131
implementation("com.sparkjava:spark-core:2.9.4")
3232
implementation("org.mongodb:bson:4.11.2")
3333
implementation("org.mongodb:mongodb-driver-sync:4.11.2")
34+
implementation("org.tinylog:tinylog-api:2.7.0")
35+
implementation("org.tinylog:tinylog-impl:2.7.0")
3436
compileOnly("org.jetbrains:annotations:24.1.0")
3537
}
3638

0 commit comments

Comments
 (0)