Update dependencies and improve configuration management

- Updated LoLib dependency to version 3.0.0 in build.gradle.kts
- Added HikariCP and MySQL connector dependencies for improved database handling
- Enhanced jar minimization process to exclude JDBC pool and driver
- Refactored configuration management by introducing ConfigAccessor and ConfigLoader for better file handling and validation
- Removed deprecated GenerationOptions class and integrated its functionality into the new structure
- Improved command error handling and added cooldown hints for admin commands
This commit is contained in:
loki 2026-04-01 16:21:09 +02:00
parent 978f739045
commit 3100c53229
86 changed files with 4324 additions and 3248 deletions

View file

@ -1,9 +1,7 @@
package dev.loki.loparkour.world;
import dev.loki.loparkour.LoParkour;
import dev.loki.loparkour.config.Option;
import dev.loki.loparkour.session.Session;
import dev.loki.loparkour.util.Locations;
import org.bukkit.Location;
import java.util.HashMap;

View file

@ -1,15 +1,12 @@
package dev.loki.loparkour.world;
import dev.lolib.worlds.VoidGenerator;
import org.bukkit.Bukkit;
import dev.loki.loparkour.LoParkour;
import dev.loki.loparkour.config.Config;
import dev.lolib.worlds.VoidGenerator;
import org.bukkit.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
@ -25,6 +22,11 @@ public class World {
*/
public static void create() {
name = Config.CONFIG.getString("world.name");
if (!isValidWorldFolderName(name)) {
LoParkour.getPlugin().getLogger().severe(
"Invalid world.name in config (use only letters, digits, '_' and '-', no path separators).");
return;
}
var world = Bukkit.getWorld(name);
@ -56,8 +58,9 @@ public class World {
.environment(org.bukkit.World.Environment.NORMAL);
world = Bukkit.createWorld(creator);
} catch (Exception ex) {
LoParkour.getPlugin().getLogger().severe("Error while trying to create the parkour world - delete the parkour world folder and restart the server - " + ex.getMessage());
} catch (IllegalArgumentException | IllegalStateException ex) {
LoParkour.getPlugin().getLogger().severe(
"Error while trying to create the parkour world — check world.name — " + ex.getMessage());
}
}
@ -93,32 +96,63 @@ public class World {
}
LoParkour.log("Deleting world");
getWorld().getPlayers().forEach(player -> player.kickPlayer("Server is restarting"));
org.bukkit.World w = getWorld();
if (w != null) {
w.getPlayers().forEach(player -> player.kickPlayer("Server is restarting"));
}
deleteWorld();
}
private static void deleteWorld() {
if (!isValidWorldFolderName(name)) {
LoParkour.getPlugin().getLogger().severe("Refusing to delete world: invalid world name.");
return;
}
LoParkour.log("Deleting Spigot world");
File file = new File(name);
// world has already been deleted
if (!file.exists()) {
File folder = worldFolder();
if (!folder.exists()) {
return;
}
Bukkit.unloadWorld(name, false);
try (Stream<Path> files = Files.walk(file.toPath())) {
try (Stream<Path> files = Files.walk(folder.toPath())) {
files.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
} catch (Exception ex) {
LoParkour.getPlugin().getLogger().severe("Error while trying to delete the parkour world" + " - " + ex.getMessage());
} catch (IOException ex) {
LoParkour.getPlugin().getLogger().severe(
"Error while trying to delete the parkour world — " + ex.getMessage());
}
}
private static File worldFolder() {
return new File(Bukkit.getWorldContainer(), name);
}
/**
* Prevents path traversal and accidental deletion outside the server world container.
*/
static boolean isValidWorldFolderName(String n) {
if (n == null || n.isBlank() || n.length() > 64) {
return false;
}
if (n.contains("..") || n.contains("/") || n.contains("\\")) {
return false;
}
for (int i = 0; i < n.length(); i++) {
char c = n.charAt(i);
if (Character.isLetterOrDigit(c) || c == '_' || c == '-') {
continue;
}
return false;
}
return true;
}
/**
* @return the name of the parkour world.
*/