From fd5a42f39dff16c96629c68bd529bf22d7d1587d Mon Sep 17 00:00:00 2001 From: rozhur Date: Fri, 11 Aug 2023 19:34:05 +0500 Subject: [PATCH] Package refactoring --- .../org/zhdev/config/BukkitYamlConfig.java | 83 ------------------- io/src/main/java/org/zhdev/config/Config.java | 41 --------- 2 files changed, 124 deletions(-) delete mode 100644 bukkit/src/main/java/org/zhdev/config/BukkitYamlConfig.java delete mode 100644 io/src/main/java/org/zhdev/config/Config.java diff --git a/bukkit/src/main/java/org/zhdev/config/BukkitYamlConfig.java b/bukkit/src/main/java/org/zhdev/config/BukkitYamlConfig.java deleted file mode 100644 index a6af133..0000000 --- a/bukkit/src/main/java/org/zhdev/config/BukkitYamlConfig.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.zhdev.config; - -import org.bukkit.configuration.serialization.ConfigurationSerializable; -import org.bukkit.configuration.serialization.ConfigurationSerialization; -import org.bukkit.plugin.Plugin; -import org.yaml.snakeyaml.nodes.Node; -import org.zhdev.util.ResourceUtils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.LinkedHashMap; -import java.util.Map; - -public class BukkitYamlConfig extends YamlConfig implements BukkitConfig { - public BukkitYamlConfig(String key) { - super(key); - } - - public BukkitYamlConfig() {} - - @Override - protected Object constructHandle(Node keyNode, Node valueNode, String key, Object value) { - if (value instanceof Map) { - Map raw = (Map) valueNode; - if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { - Map map = new LinkedHashMap<>(raw.size()); - for (Map.Entry entry : raw.entrySet()) { - map.put(String.valueOf(entry.getKey()), entry.getValue()); - } - return ConfigurationSerialization.deserializeObject(map); - } - } - return super.constructHandle(keyNode, valueNode, key, value); - } - - @Override - protected Node representHandle(String key, Object value) { - if (value instanceof ConfigurationSerializable) { - ConfigurationSerializable serializable = (ConfigurationSerializable) value; - Map values = new LinkedHashMap<>(); - values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass())); - values.putAll(serializable.serialize()); - return REPRESENTER.represent(values); - } - return super.representHandle(key, value); - } - - @Override - public File load(Plugin plugin, String path) throws ConfigException { - ClassLoader classLoader = plugin.getClass().getClassLoader(); - InputStream stream = ResourceUtils.getResource(path, classLoader); - if (stream != null) { - load(stream); - } - - File file = load(plugin.getDataFolder().getPath() + File.separatorChar + path); - if (file.length() == 0) { - ResourceUtils.saveResource(path, file, classLoader); - try { - load(file); - } catch (IOException e) { - throw new ConfigException(e); - } - } - return file; - } - - @Override - public File load(Plugin plugin) throws ConfigException { - return load(plugin, key); - } - - @Override - public File saveIfEmpty(Plugin plugin, String path) throws ConfigException { - return saveIfEmpty(plugin.getDataFolder().getPath() + File.separatorChar + path); - } - - @Override - public File saveIfEmpty(Plugin plugin) throws ConfigException { - return saveIfEmpty(plugin, key); - } -} diff --git a/io/src/main/java/org/zhdev/config/Config.java b/io/src/main/java/org/zhdev/config/Config.java deleted file mode 100644 index c6671e8..0000000 --- a/io/src/main/java/org/zhdev/config/Config.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.zhdev.config; - -import java.io.*; - -public interface Config extends ConfigSection { - String DEFAULT_KEY = "config.yml"; - - String getKey(); - - String[] getHeaderComments(); - - String[] getEndComments(); - - void setHeaderComments(String... headerComments); - - void setEndComments(String... endComments); - - void load(Reader reader); - - void load(InputStream stream) throws IOException, ConfigException; - - void load(File file) throws IOException, ConfigException; - - File load(String path) throws ConfigException; - - File load() throws ConfigException; - - void save(Writer writer); - - void save(OutputStream stream) throws IOException, ConfigException; - - void save(File file) throws IOException, ConfigException; - - File save(String path) throws ConfigException; - - File save() throws ConfigException; - - File saveIfEmpty(String path) throws ConfigException; - - File saveIfEmpty() throws ConfigException; -}