This commit is contained in:
loki 2026-03-01 22:43:37 +01:00
parent 547fe6d9bb
commit 8705cad578
118 changed files with 2714 additions and 4761 deletions

View file

@ -3,7 +3,7 @@ package dev.loki.loparkour.config;
import dev.loki.loparkour.LoParkour;
import dev.loki.loparkour.reward.Rewards;
import dev.loki.loparkour.schematic.Schematics;
import dev.efnilite.vilib.configupdater.ConfigUpdater;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -27,8 +27,9 @@ public enum Config {
/**
* The path to this file, incl. plugin folder.
* Not final — resolved lazily on first reload() call after plugin instance is set.
*/
public final File path;
public File path;
/**
* The name of this file, e.g. config.yml
*/
@ -45,21 +46,27 @@ public enum Config {
Config(String fileName, @Nullable List<String> ignoredSections) {
this.fileName = fileName;
this.ignoredSections = ignoredSections;
this.path = LoParkour.getInFolder(fileName);
if (!path.exists()) {
LoParkour.getPlugin().saveResource(fileName, false);
}
update();
load();
// path resolved lazily via getPath() — do NOT call LoParkour.getInFolder() here,
// because enum constants are initialized before onEnable() sets the instance.
this.path = null; // placeholder; real path resolved on first access
}
/**
* Reloads all config files.
* On first call (initialLoad=true) also resolves file paths and saves defaults.
*/
public static void reload(boolean initialLoad) {
for (Config config : values()) {
if (initialLoad) {
// Resolve path now that instance is guaranteed to be set
config.path = LoParkour.getInFolder(config.fileName);
if (!config.path.exists()) {
LoParkour.getPlugin().saveResource(config.fileName, false);
}
config.update();
}
config.load();
}
@ -76,6 +83,7 @@ public enum Config {
* Loads the file from disk.
*/
public void load() {
if (path == null) return; // not yet initialized, skip
this.fileConfiguration = YamlConfiguration.loadConfiguration(path);
}
@ -84,9 +92,10 @@ public enum Config {
*/
public void update() {
try {
ConfigUpdater.update(LoParkour.getPlugin(), fileName, path, ignoredSections);
// TODO: ConfigUpdater.update(LoParkour.getPlugin(), fileName, path, ignoredSections);
} catch (Exception ex) {
LoParkour.logging().stack("Error while trying to update config file", ex);
LoParkour.getPlugin().getLogger().log(java.util.logging.Level.SEVERE,
"Error while trying to update config file: " + fileName, ex);
}
}
@ -108,7 +117,6 @@ public enum Config {
return fileConfiguration.get(path);
}
/**
* @param path The path.
* @return The boolean value at path.

View file

@ -1,10 +1,14 @@
package dev.loki.loparkour.config;
import java.util.ArrayList;
import dev.loki.loparkour.util.Item;
import dev.loki.loparkour.LoParkour;
import dev.loki.loparkour.menu.ParkourOption;
import dev.loki.loparkour.player.ParkourUser;
import dev.efnilite.vilib.inventory.item.Item;
import dev.efnilite.vilib.util.Task;
import dev.lolib.scheduler.Scheduler;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
@ -44,7 +48,7 @@ public class Locales {
public static void init() {
Plugin plugin = LoParkour.getPlugin();
Task.create(plugin).async().execute(() -> {
Scheduler.get(plugin).runAsync(() -> {
locales.clear();
FileConfiguration embedded = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource("locales/en.yml"), StandardCharsets.UTF_8));
@ -86,9 +90,9 @@ public class Locales {
locales.put(locale, config);
});
} catch (Exception ex) {
LoParkour.logging().stack("Error while trying to read locale files", "restart/reload your server", ex);
LoParkour.getPlugin().getLogger().severe("Error while trying to read locale files - restart/reload your server - " + ex.getMessage());
}
}).run();
});
}
// validates whether a lang file contains all required keys.
@ -111,7 +115,7 @@ public class Locales {
try {
user.save(localPath);
} catch (IOException ex) {
LoParkour.logging().stack("Error while trying to save fixed config file %s".formatted(localPath), "delete this file and restart your server", ex);
LoParkour.getPlugin().getLogger().severe("Error while trying to save fixed config file %s - delete this file and restart your server - ".formatted(localPath) + ex.getMessage());
}
}
@ -244,7 +248,7 @@ public class Locales {
}
if (modelId != -1) {
item.modelId(modelId);
// TODO: item.setCustomModelData(modelId);
}
return item;

View file

@ -1,11 +1,17 @@
package dev.loki.loparkour.config;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import dev.loki.loparkour.util.ParticleData;
import dev.loki.loparkour.LoParkour;
import dev.loki.loparkour.api.Registry;
import dev.loki.loparkour.menu.ParkourOption;
import dev.loki.loparkour.style.RandomStyle;
import dev.loki.loparkour.style.Style;
import dev.efnilite.vilib.particle.ParticleData;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.configuration.file.FileConfiguration;
@ -83,7 +89,7 @@ public class Option {
POSSIBLE_LEADS = Config.CONFIG.getIntList("options.leads.amount");
for (int lead : new ArrayList<>(POSSIBLE_LEADS)) {
if (lead < 1 || lead > 128) {
LoParkour.logging().error("Invalid lead: %d. Should be above 1 and below 128.".formatted(lead));
LoParkour.getPlugin().getLogger().severe("Invalid lead: %d. Should be above 1 and below 128.".formatted(lead));
POSSIBLE_LEADS.remove((Object) lead);
}
}
@ -96,7 +102,7 @@ public class Option {
case "south" -> HEADING = BlockFace.SOUTH;
case "west" -> HEADING = BlockFace.WEST;
case "east" -> HEADING = BlockFace.EAST;
default -> LoParkour.logging().error("Invalid heading: %s".formatted(heading));
default -> LoParkour.getPlugin().getLogger().severe("Invalid heading: %s".formatted(heading));
}
// Scoring
@ -142,7 +148,7 @@ public class Option {
SOUND_TYPE = Sound.valueOf(value);
} catch (IllegalArgumentException ex) {
SOUND_TYPE = Sound.valueOf("BLOCK_NOTE_PLING");
LoParkour.logging().error("Invalid sound: %s".formatted(value));
LoParkour.getPlugin().getLogger().severe("Invalid sound: %s".formatted(value));
}
value = Config.CONFIG.getString("particles.particle-type");
@ -150,13 +156,13 @@ public class Option {
PARTICLE_TYPE = Particle.valueOf(value);
} catch (IllegalArgumentException ex) {
PARTICLE_TYPE = Particle.valueOf("SPELL_INSTANT");
LoParkour.logging().error("Invalid particle type: %s".formatted(value));
LoParkour.getPlugin().getLogger().severe("Invalid particle type: %s".formatted(value));
}
SOUND_PITCH = Config.CONFIG.getInt("particles.sound-pitch");
SOUND_VOLUME = Config.CONFIG.getInt("particles.sound-volume");
PARTICLE_SHAPE = ParticleShape.valueOf(Config.CONFIG.getString("particles.particle-shape").toUpperCase());
PARTICLE_DATA = new ParticleData<>(PARTICLE_TYPE, null, 10, 0, 0, 0, 0);
PARTICLE_DATA = new ParticleData<>(PARTICLE_TYPE, null, 10);
}
public enum ParticleShape {
@ -287,7 +293,7 @@ public class Option {
MIN_Y = 100;
MAX_Y = 200;
LoParkour.logging().stack("Provided minimum y is the same or larger than maximum y!", "check your generation.yml file");
LoParkour.getPlugin().getLogger().severe("Provided minimum y is the same or larger than maximum y! - check your generation.yml file");
}
}
@ -303,7 +309,7 @@ public class Option {
var material = Material.getMaterial(name.toUpperCase());
if (material == null) {
LoParkour.logging().error("Invalid material %s in style %s".formatted(name, style));
LoParkour.getPlugin().getLogger().severe("Invalid material %s in style %s".formatted(name, style));
return Material.STONE;
}