TCheckpoint
This commit is contained in:
parent
2845cc512f
commit
c5b686aeb5
55 changed files with 453 additions and 213 deletions
|
|
@ -2,89 +2,29 @@ package org.gsdistance.grimmsServer.Config;
|
|||
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
import java.util.List;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ActiveConfig {
|
||||
public static boolean module_Jobs = true;
|
||||
public static boolean module_Factions = true;
|
||||
public static boolean module_Market = true;
|
||||
public static boolean module_Leaderboard = true;
|
||||
public static String[] disabledCommands = new String[]{};
|
||||
public static boolean module_Chat = true;
|
||||
public static boolean module_Homes = true;
|
||||
public static boolean module_Leveling = true;
|
||||
public static boolean module_Titles = true;
|
||||
public static boolean module_Relics = true;
|
||||
public static boolean module_Events = true;
|
||||
public static boolean module_Utils = true;
|
||||
public static boolean module_Ranks = true;
|
||||
public static boolean joinMessage = true;
|
||||
public static boolean module_Dimensions = true;
|
||||
private static final Map<ConfigKey, Object> configValues = new HashMap<>();
|
||||
|
||||
public static void updateConfig(boolean module_Jobs, boolean module_Factions, boolean module_Market, boolean module_Leaderboard, List<String> disabledCommands, boolean module_Chat, boolean module_Homes, boolean module_Leveling, boolean module_Titles, boolean module_Relics, boolean module_Events, boolean module_Utils, boolean module_Ranks, boolean joinMessage, boolean module_Dimensions) {
|
||||
ActiveConfig.module_Jobs = module_Jobs;
|
||||
ActiveConfig.module_Factions = module_Factions;
|
||||
ActiveConfig.module_Market = module_Market;
|
||||
ActiveConfig.module_Leaderboard = module_Leaderboard;
|
||||
ActiveConfig.disabledCommands = disabledCommands.toArray(new String[0]);
|
||||
ActiveConfig.module_Chat = module_Chat;
|
||||
ActiveConfig.module_Homes = module_Homes;
|
||||
ActiveConfig.module_Leveling = module_Leveling;
|
||||
ActiveConfig.module_Titles = module_Titles;
|
||||
ActiveConfig.module_Relics = module_Relics;
|
||||
ActiveConfig.module_Events = module_Events;
|
||||
ActiveConfig.module_Utils = module_Utils;
|
||||
ActiveConfig.module_Ranks = module_Ranks;
|
||||
ActiveConfig.joinMessage = joinMessage;
|
||||
ActiveConfig.module_Dimensions = module_Dimensions;
|
||||
public static void setConfigValue(ConfigKey key, Object value) {
|
||||
configValues.put(key, value);
|
||||
}
|
||||
|
||||
// Log the status of each module
|
||||
if (!module_Jobs) {
|
||||
GrimmsServer.logger.info("Jobs module is disabled by config.");
|
||||
}
|
||||
if (!module_Factions) {
|
||||
GrimmsServer.logger.info("Factions module is disabled by config.");
|
||||
}
|
||||
if (!module_Market) {
|
||||
GrimmsServer.logger.info("Market module is disabled by config.");
|
||||
}
|
||||
if (!module_Leaderboard) {
|
||||
GrimmsServer.logger.info("Leaderboard module is disabled by config.");
|
||||
}
|
||||
if (!module_Chat) {
|
||||
GrimmsServer.logger.info("Chat module is disabled by config.");
|
||||
}
|
||||
if (!module_Homes) {
|
||||
GrimmsServer.logger.info("Homes module is disabled by config.");
|
||||
}
|
||||
if (!module_Leveling) {
|
||||
GrimmsServer.logger.info("Leveling module is disabled by config.");
|
||||
}
|
||||
if (!module_Titles) {
|
||||
GrimmsServer.logger.info("Titles module is disabled by config.");
|
||||
}
|
||||
if (!module_Relics) {
|
||||
GrimmsServer.logger.info("Relics module is disabled by config.");
|
||||
}
|
||||
if (!module_Events) {
|
||||
GrimmsServer.logger.info("Events module is disabled by config.");
|
||||
}
|
||||
if (!module_Utils) {
|
||||
GrimmsServer.logger.info("Utils module is disabled by config.");
|
||||
}
|
||||
if (disabledCommands.isEmpty()) {
|
||||
GrimmsServer.logger.info("No commands are disabled by config.");
|
||||
} else {
|
||||
GrimmsServer.logger.info("Disabled commands: " + String.join(", ", disabledCommands));
|
||||
}
|
||||
if (!module_Ranks) {
|
||||
GrimmsServer.logger.info("Ranks module is disabled by config.");
|
||||
}
|
||||
if (!joinMessage) {
|
||||
GrimmsServer.logger.info("Join message is disabled by config.");
|
||||
}
|
||||
if (!module_Dimensions) {
|
||||
GrimmsServer.logger.info("Dimensions module is disabled by config.");
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getConfigValue(ConfigKey key, Class<T> ignoredType) {
|
||||
try {
|
||||
return (T) configValues.getOrDefault(key, key.getDefaultValue());
|
||||
} catch (ClassCastException e) {
|
||||
GrimmsServer.logger.warning("Config value for " + key.getKey() + " is not of type " + ignoredType.getSimpleName() + ". Message: " + e.getMessage());
|
||||
try {
|
||||
return ignoredType.getDeclaredConstructor().newInstance();
|
||||
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException | InstantiationException ex) {
|
||||
GrimmsServer.logger.warning("Failed to instantiate default value for " + key.getKey() + ". Message: " + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package org.gsdistance.grimmsServer.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public enum ConfigKey {
|
||||
MODULE_JOBS("module_Jobs", true),
|
||||
MODULE_FACTIONS("module_Factions", true),
|
||||
MODULE_MARKET("module_Market", true),
|
||||
MODULE_LEADERBOARD("module_Leaderboard", true),
|
||||
DISABLED_COMMANDS("disabledCommands", new ArrayList<String>()),
|
||||
MODULE_CHAT("module_Chat", true),
|
||||
MODULE_HOMES("module_Homes", true),
|
||||
MODULE_LEVELING("module_Leveling", true),
|
||||
MODULE_TITLES("module_Titles", true),
|
||||
MODULE_RELICS("module_Relics", true),
|
||||
MODULE_EVENTS("module_Events", true),
|
||||
MODULE_UTILS("module_Utils", true),
|
||||
MODULE_RANKS("module_Ranks", true),
|
||||
JOIN_MESSAGE("joinMessage", true),
|
||||
MODULE_DIMENSIONS("module_Dimensions", true),
|
||||
DISABLED_DIMENSIONS("disabledDimensions", new ArrayList<String>()),
|
||||
FORCE_DISABLE_BC("forceDisableBroadcasts", false);
|
||||
|
||||
private final String key;
|
||||
private final Object defaultValue;
|
||||
|
||||
ConfigKey(String key, Object defaultValue) {
|
||||
this.key = key;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Object getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
package org.gsdistance.grimmsServer.Config;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigLoader {
|
||||
private static FileConfiguration config;
|
||||
|
|
@ -20,28 +20,18 @@ public class ConfigLoader {
|
|||
}
|
||||
|
||||
public static void loadConfigFromFile() {
|
||||
Stopwatch sw = Stopwatch.createStarted();
|
||||
GrimmsServer.logger.info("Loading GrimmsServer config...");
|
||||
if (config == null) {
|
||||
GrimmsServer.logger.warning("Config somehow not initialized.");
|
||||
GrimmsServer.logger.warning("Config somehow not initialized. (" + sw.stop() + ")");
|
||||
return;
|
||||
}
|
||||
ActiveConfig.updateConfig(
|
||||
config.getBoolean("module_Jobs", true),
|
||||
config.getBoolean("module_Factions", true),
|
||||
config.getBoolean("module_Market", true),
|
||||
config.getBoolean("module_Leaderboard", true),
|
||||
config.getStringList("disabledCommands"),
|
||||
config.getBoolean("module_Chat", true),
|
||||
config.getBoolean("module_Homes", true),
|
||||
config.getBoolean("module_Leveling", true),
|
||||
config.getBoolean("module_Titles", true),
|
||||
config.getBoolean("module_Relics", true),
|
||||
config.getBoolean("module_Events", true),
|
||||
config.getBoolean("module_Utils", true),
|
||||
config.getBoolean("module_Ranks", true),
|
||||
config.getBoolean("joinMessage", true),
|
||||
config.getBoolean("module_Dimensions", true)
|
||||
);
|
||||
GrimmsServer.logger.info("GrimmsServer config loaded successfully.");
|
||||
|
||||
for (ConfigKey key : ConfigKey.values()) {
|
||||
Object value = config.get(key.getKey(), key.getDefaultValue());
|
||||
ActiveConfig.setConfigValue(key, value);
|
||||
}
|
||||
|
||||
GrimmsServer.logger.info("GrimmsServer config loaded successfully. (" + sw.stop() + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue