Introduces `KeyStorage` for handling keys and their persistence. Added `Key` subcommand to allow players to receive their keys. Updated configuration files and messages to support the new feature.
66 lines
2.1 KiB
Java
66 lines
2.1 KiB
Java
package com.alttd.playerutils.config;
|
|
|
|
import com.alttd.playerutils.util.Logger;
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import java.io.File;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
public class Config extends AbstractConfig{
|
|
|
|
static Config config;
|
|
private Logger logger;
|
|
|
|
Config(Logger logger) {
|
|
super(
|
|
new File(File.separator
|
|
+ "mnt" + File.separator
|
|
+ "configs" + File.separator
|
|
+ "PlayerUtils"),
|
|
"config.yml", logger);
|
|
this.logger = logger;
|
|
}
|
|
|
|
public static void reload(Logger logger) {
|
|
logger.info("Reloading config");
|
|
config = new Config(logger);
|
|
config.readConfig(Config.class, null);
|
|
}
|
|
|
|
public static class SETTINGS {
|
|
private static final String prefix = "settings.";
|
|
public static boolean DEBUG = false;
|
|
public static boolean WARNINGS = true;
|
|
|
|
@SuppressWarnings("unused")
|
|
private static void load() {
|
|
DEBUG = config.getBoolean(prefix, "debug", DEBUG);
|
|
WARNINGS = config.getBoolean(prefix, "warnings", WARNINGS);
|
|
}
|
|
}
|
|
|
|
public static class KEY {
|
|
private static final String prefix = "key.";
|
|
public static HashMap<String, Integer> CRATES = new HashMap<>();
|
|
|
|
@SuppressWarnings("unused")
|
|
private static void load() {
|
|
CRATES.clear();
|
|
ConfigurationSection configurationSection = config.getConfigurationSection(prefix.substring(0, prefix.length() - 1));
|
|
if (configurationSection == null) {
|
|
config.logger.warning("No keys configured, adding default");
|
|
config.set(prefix, "dailyvotecrate", 0);
|
|
config.set(prefix, "weeklyvotecrate", 0);
|
|
config.set(prefix, "questcrate", 0);
|
|
return;
|
|
}
|
|
Set<String> keys = configurationSection.getKeys(false);
|
|
for (String key : keys) {
|
|
CRATES.put(key, config.getInt(prefix, key, 0));
|
|
}
|
|
}
|
|
}
|
|
}
|