Fix critical bugs and improve code quality

Generator & Modes:
- Fix potential NPE in ParkourGenerator zone initialization
- Add null check in BlockPlacer.placeNormalBlock()
- Fix unsafe Map operations in CoopMode.score()
- Add session validation in RaceMode delayed reset
- Extract magic number to constant in SpeedrunMode (TICKS_PER_SECOND)
- Add world bounds checking in ElytraRingGenerator
- Fix map normalization in GeneratorProfileManager (handle zero sum)
- Complete schematic implementation in BlockPlacer

Storage & Database:
- CRITICAL: Fix connection leak in SQLConnectionManager
- Add proper try-with-resources for Connection in SQLQueryExecutor
- Deprecate unsafe prepareStatement() method
- Add documentation about connection management

Session & Player:
- Optimize muted users count calculation in SessionStateManager

All changes tested and verified with build + tests passing.
This commit is contained in:
loki 2026-04-08 16:54:42 +02:00
parent 46f7b794c6
commit 9864fd6e30
10 changed files with 63 additions and 38 deletions

View file

@ -139,7 +139,7 @@ public class CoopMode implements MultiMode {
// Track contributions for all players in session
for (ParkourPlayer pp : getPlayers()) {
contributions.merge(pp.getUUID(), 1, Integer::sum);
contributions.compute(pp.getUUID(), (uuid, count) -> (count == null ? 0 : count) + 1);
}
// Milestone every 50 points

View file

@ -130,10 +130,12 @@ public class RaceMode implements Mode {
// Save to leaderboard
registerScore(time, "1.0", targetScore);
// Return to lobby after 5 seconds — guarded against null session
// Return to lobby after 5 seconds — guarded against null/closed session
dev.lolib.scheduler.Scheduler.get(LoParkour.getPlugin())
.runLater(() -> {
if (!state.stopped) reset(false);
if (session != null && !state.stopped) {
reset(false);
}
}, 100L);
}

View file

@ -77,6 +77,8 @@ public class SpeedrunMode implements Mode {
private static class SpeedrunGenerator extends ParkourGenerator {
private static final int TICKS_PER_SECOND = 20;
/** Tracks scheduled tasks per block. Key = block, value = [warningTask, removalTask]. */
private final Map<Block, ScheduledTask[]> scheduledTasks = new HashMap<>();
@ -109,9 +111,9 @@ public class SpeedrunMode implements Mode {
double blockLifetime = Config.CONFIG.getDouble("modes.speedrun.block-lifetime");
double warningTime = Config.CONFIG.getDouble("modes.speedrun.warning-time");
// Convert seconds → ticks (20 ticks/s), minimum 1 tick
long removalTicks = Math.max(1, Math.round(blockLifetime * 20));
long warningTicks = Math.max(1, Math.round(warningTime * 20));
// Convert seconds → ticks, minimum 1 tick
long removalTicks = Math.max(1, Math.round(blockLifetime * TICKS_PER_SECOND));
long warningTicks = Math.max(1, Math.round(warningTime * TICKS_PER_SECOND));
ScheduledTask warningTask = Scheduler.get(LoParkour.getPlugin()).runLater(() -> {
if (block.getType() != Material.AIR) {

View file

@ -77,14 +77,26 @@ public class ElytraRingGenerator {
@NotNull
private Location constrainHeight(@NotNull Location pos, @NotNull Location origin) {
double maxHeight = origin.getY() + config.getMaxHeightAboveSpawn();
double minHeight = origin.getY() - 20; // Don't go too low
double minHeight = Math.max(
origin.getWorld().getMinHeight() + 10, // World minimum + safety margin
origin.getY() - 20 // Don't go too far below spawn
);
double worldMaxHeight = origin.getWorld().getMaxHeight() - 10; // Safety margin from world ceiling
// Constrain to configured limits
if (pos.getY() > maxHeight) {
pos.setY(maxHeight);
pos.setY(Math.min(maxHeight, worldMaxHeight));
} else if (pos.getY() < minHeight) {
pos.setY(minHeight);
}
// Final world bounds check
if (pos.getY() > worldMaxHeight) {
pos.setY(worldMaxHeight);
} else if (pos.getY() < origin.getWorld().getMinHeight()) {
pos.setY(origin.getWorld().getMinHeight() + 10);
}
return pos;
}