aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLéo Kosman <leo.kosman@proton.me>2024-08-24 18:37:21 +0200
committerLéo Kosman <leo.kosman@proton.me>2024-08-24 18:37:21 +0200
commit06027e9cd2b71a9606fb38dbde261cc629a68cc1 (patch)
treedff72ec2c10976920df24b690f0305b03e28db93
parent7f60288c07c356616fdee270ece7b2a625dcfdd1 (diff)
perf: do not recycle timer task because somehow it's actually better ? idk anymore
-rw-r--r--src/main/java/world/anhgelus/molehunt/Game.java25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/main/java/world/anhgelus/molehunt/Game.java b/src/main/java/world/anhgelus/molehunt/Game.java
index b8d7136..300b4c2 100644
--- a/src/main/java/world/anhgelus/molehunt/Game.java
+++ b/src/main/java/world/anhgelus/molehunt/Game.java
@@ -21,18 +21,6 @@ public class Game {
public final int defaultTime = Molehunt.CONFIG.getGameDuration()*60;
private int remaining = defaultTime;
- private Timer borderTimeOffsetTimer = new Timer();
- private final TimerTask borderTimeOffsetTask = new TimerTask() {
- @Override
- public void run() {
- final var worldBorder = server.getOverworld().getWorldBorder();
- worldBorder.interpolateSize(
- Molehunt.CONFIG.getInitialWorldSize(),
- Molehunt.CONFIG.getFinalWorldSize(),
- (long) (Molehunt.CONFIG.getGameDuration() - Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset()) * 60);
- }
- };
-
private final MinecraftServer server;
private final List<ServerPlayerEntity> moles = new ArrayList<>();
@@ -72,7 +60,16 @@ public class Game {
final var worldBorder = server.getOverworld().getWorldBorder();
worldBorder.setSize(Molehunt.CONFIG.getInitialWorldSize());
if (Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset() < Molehunt.CONFIG.getGameDuration()) {
- borderTimeOffsetTimer.schedule(borderTimeOffsetTask, (long) Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset() * 60 * 1000);
+ timer.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ final var worldBorder = server.getOverworld().getWorldBorder();
+ worldBorder.interpolateSize(
+ Molehunt.CONFIG.getInitialWorldSize(),
+ Molehunt.CONFIG.getFinalWorldSize(),
+ (long) (Molehunt.CONFIG.getGameDuration() - Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset()) * 60);
+ }
+ }, (long) Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset() * 60 * 1000);
}
final var title = new TitleS2CPacket(Text.translatable("molehunt.game.start.suspense"));
@@ -135,8 +132,6 @@ public class Game {
timer.cancel();
timer = new Timer();
- borderTimeOffsetTask.cancel();
-
final var worldBorder = server.getOverworld().getWorldBorder();
// Stops the border shrinking.
worldBorder.setSize(worldBorder.getSize());