package com.io.yutian.thewarskyblocklib.config; import org.bukkit.configuration.ConfigurationSection; import java.io.File; import java.util.HashMap; import java.util.Map; public class FileConfig { private File file; private ConfigurationSection section; protected Map valueMap = new HashMap<>(); public FileConfig(File file, ConfigurationSection section) { this.file = file; this.section = section; load(); } public Object getValue(String key) { return valueMap.get(key); } public Object getValue(String[] keys) { for (String key : keys) { if (hasKey(key)) { return getValue(key); } } return null; } public T getValue(String[] keys, Class type) { for (String key : keys) { if (hasKey(key, type)) { return (T) getValue(key); } } return null; } public boolean hasKey(String key) { return valueMap.containsKey(key); } public boolean hasKey(String[] keys) { for (String key : keys) { if (hasKey(key)) { return true; } } return false; } public boolean hasKey(String key, Class type) { if (!valueMap.containsKey(key)) { return false; } Object value = getValue(key); return type.isInstance(value); } public boolean hasKey(String[] keys, Class type) { for (String key : keys) { if (hasKey(key, type)) { return true; } } return false; } private void load() { valueMap.clear(); for (String key : section.getKeys(false)) { Object value = section.get(key); valueMap.put(key, value); } } public File getFile() { return file; } public ConfigurationSection getSection() { return section; } }