Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70a4a06d4f | ||
|
|
bbee18fd8a | ||
|
|
26ab9a327d | ||
|
|
0676f5fa33 | ||
|
|
051b95ad88 | ||
|
|
d786014cbc | ||
|
|
b62bb48bb6 | ||
|
|
b238a10209 | ||
|
|
251049f1f1 | ||
|
|
16d146dba0 |
@@ -29,10 +29,10 @@ public class ArrowUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(values.get(0) instanceof ItemStack)) {
|
||||
if (!(values.get(0).value() instanceof ItemStack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (ItemStack) values.get(0);
|
||||
return (ItemStack) values.get(0).value();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,14 @@ public class EcoLoadableJSONConfig extends EcoJSONConfigWrapper implements Loada
|
||||
plugin.getConfigHandler().addConfig(this);
|
||||
}
|
||||
|
||||
public void reloadFromFile() {
|
||||
try {
|
||||
init(this.configFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createFile() {
|
||||
String resourcePath = getResourcePath();
|
||||
@@ -108,9 +116,10 @@ public class EcoLoadableJSONConfig extends EcoJSONConfigWrapper implements Loada
|
||||
|
||||
@Override
|
||||
public void save() throws IOException {
|
||||
configFile.delete();
|
||||
if (configFile.delete()) {
|
||||
Files.write(configFile.toPath(), this.toPlaintext().getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void init(@NotNull final File file) throws FileNotFoundException {
|
||||
|
||||
@@ -5,7 +5,9 @@ import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.config.interfaces.LoadableConfig;
|
||||
import com.willfp.eco.core.config.updating.ConfigHandler;
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater;
|
||||
import com.willfp.eco.internal.config.json.EcoLoadableJSONConfig;
|
||||
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdateMethodException;
|
||||
import com.willfp.eco.internal.config.yaml.EcoLoadableYamlConfig;
|
||||
import com.willfp.eco.internal.config.yaml.EcoUpdatableYamlConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.reflections.Reflections;
|
||||
@@ -76,6 +78,12 @@ public class EcoConfigHandler extends PluginDependent<EcoPlugin> implements Conf
|
||||
if (config instanceof EcoUpdatableYamlConfig updatableYamlConfig) {
|
||||
updatableYamlConfig.update();
|
||||
}
|
||||
if (config instanceof EcoLoadableYamlConfig ecoLoadableYamlConfig) {
|
||||
ecoLoadableYamlConfig.reloadFromFile();
|
||||
}
|
||||
if (config instanceof EcoLoadableJSONConfig ecoLoadableJSONConfig) {
|
||||
ecoLoadableJSONConfig.reloadFromFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.willfp.eco.core.config.interfaces.LoadableConfig;
|
||||
import com.willfp.eco.core.config.interfaces.WrappedYamlConfiguration;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -49,9 +50,19 @@ public class EcoLoadableYamlConfig extends EcoYamlConfigWrapper<YamlConfiguratio
|
||||
}
|
||||
|
||||
this.configFile = new File(directory, this.name);
|
||||
|
||||
this.getPlugin().getConfigHandler().addConfig(this);
|
||||
init(YamlConfiguration.loadConfiguration(configFile));
|
||||
}
|
||||
|
||||
public void reloadFromFile() {
|
||||
try {
|
||||
this.getHandle().load(this.getConfigFile());
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createFile() {
|
||||
String resourcePath = getResourcePath();
|
||||
|
||||
@@ -30,6 +30,8 @@ public class EcoUpdatableYamlConfig extends EcoLoadableYamlConfig {
|
||||
this.updateBlacklist = new ArrayList<>(Arrays.asList(updateBlacklist));
|
||||
this.updateBlacklist.removeIf(String::isEmpty);
|
||||
|
||||
plugin.getConfigHandler().addConfig(this);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,12 @@ package com.willfp.eco.internal.extensions;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.config.yaml.YamlTransientConfig;
|
||||
import com.willfp.eco.core.extensions.Extension;
|
||||
import com.willfp.eco.core.extensions.ExtensionLoader;
|
||||
import com.willfp.eco.core.extensions.ExtensionMetadata;
|
||||
import com.willfp.eco.core.extensions.MalformedExtensionException;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -17,8 +18,6 @@ import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -50,12 +49,12 @@ public class EcoExtensionLoader extends PluginDependent<EcoPlugin> implements Ex
|
||||
try {
|
||||
loadExtension(extensionJar);
|
||||
} catch (MalformedExtensionException e) {
|
||||
this.getPlugin().getLogger().severe(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage());
|
||||
this.getPlugin().getLogger().warning(extensionJar.getName() + " caused an error!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadExtension(@NotNull final File extensionJar) {
|
||||
private void loadExtension(@NotNull final File extensionJar) throws MalformedExtensionException {
|
||||
URL url = null;
|
||||
try {
|
||||
url = extensionJar.toURI().toURL();
|
||||
@@ -71,22 +70,31 @@ public class EcoExtensionLoader extends PluginDependent<EcoPlugin> implements Ex
|
||||
throw new MalformedExtensionException("No extension.yml found in " + extensionJar.getName());
|
||||
}
|
||||
|
||||
YamlConfiguration extensionYml = YamlConfiguration.loadConfiguration(new InputStreamReader(ymlIn));
|
||||
Config extensionYml = new YamlTransientConfig(YamlConfiguration.loadConfiguration(new InputStreamReader(ymlIn)));
|
||||
|
||||
Set<String> keys = extensionYml.getKeys(false);
|
||||
ArrayList<String> required = new ArrayList<>(Arrays.asList("main", "name", "version"));
|
||||
required.removeAll(keys);
|
||||
if (!required.isEmpty()) {
|
||||
throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName() + " - Missing: " + String.join(", ", required));
|
||||
String mainClass = extensionYml.getStringOrNull("main");
|
||||
String name = extensionYml.getStringOrNull("name");
|
||||
String version = extensionYml.getStringOrNull("version");
|
||||
String author = extensionYml.getStringOrNull("author");
|
||||
|
||||
if (mainClass == null) {
|
||||
throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName());
|
||||
}
|
||||
|
||||
String mainClass = extensionYml.getString("main");
|
||||
String name = extensionYml.getString("name");
|
||||
String version = extensionYml.getString("version");
|
||||
String author = extensionYml.getString("author");
|
||||
Validate.notNull(name, "Name is missing!");
|
||||
Validate.notNull(version, "Version is missing!");
|
||||
Validate.notNull(author, "Author is missing!");
|
||||
if (name == null) {
|
||||
this.getPlugin().getLogger().warning(extensionJar.getName() + " doesn't have a name!");
|
||||
name = "Unnamed Extension " + extensionJar.getName();
|
||||
}
|
||||
|
||||
if (version == null) {
|
||||
this.getPlugin().getLogger().warning(extensionJar.getName() + " doesn't have a version!");
|
||||
version = "1.0.0";
|
||||
}
|
||||
|
||||
if (author == null) {
|
||||
this.getPlugin().getLogger().warning(extensionJar.getName() + " doesn't have an author!");
|
||||
author = "Unnamed Author";
|
||||
}
|
||||
|
||||
ExtensionMetadata metadata = new ExtensionMetadata(version, name, author);
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
version = 6.0.2
|
||||
version = 6.0.6
|
||||
plugin-name = eco
|
||||
Reference in New Issue
Block a user