|
|
|
@@ -3,11 +3,12 @@ package com.willfp.eco.internal.extensions;
|
|
|
|
|
|
|
|
|
|
|
|
import com.willfp.eco.core.EcoPlugin;
|
|
|
|
import com.willfp.eco.core.EcoPlugin;
|
|
|
|
import com.willfp.eco.core.PluginDependent;
|
|
|
|
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.Extension;
|
|
|
|
import com.willfp.eco.core.extensions.ExtensionLoader;
|
|
|
|
import com.willfp.eco.core.extensions.ExtensionLoader;
|
|
|
|
import com.willfp.eco.core.extensions.ExtensionMetadata;
|
|
|
|
import com.willfp.eco.core.extensions.ExtensionMetadata;
|
|
|
|
import com.willfp.eco.core.extensions.MalformedExtensionException;
|
|
|
|
import com.willfp.eco.core.extensions.MalformedExtensionException;
|
|
|
|
import org.apache.commons.lang.Validate;
|
|
|
|
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -17,8 +18,6 @@ import java.io.InputStreamReader;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLClassLoader;
|
|
|
|
import java.net.URLClassLoader;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -50,12 +49,12 @@ public class EcoExtensionLoader extends PluginDependent<EcoPlugin> implements Ex
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
loadExtension(extensionJar);
|
|
|
|
loadExtension(extensionJar);
|
|
|
|
} catch (MalformedExtensionException e) {
|
|
|
|
} 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;
|
|
|
|
URL url = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
url = extensionJar.toURI().toURL();
|
|
|
|
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());
|
|
|
|
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);
|
|
|
|
String mainClass = extensionYml.getStringOrNull("main");
|
|
|
|
ArrayList<String> required = new ArrayList<>(Arrays.asList("main", "name", "version"));
|
|
|
|
String name = extensionYml.getStringOrNull("name");
|
|
|
|
required.removeAll(keys);
|
|
|
|
String version = extensionYml.getStringOrNull("version");
|
|
|
|
if (!required.isEmpty()) {
|
|
|
|
String author = extensionYml.getStringOrNull("author");
|
|
|
|
throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName() + " - Missing: " + String.join(", ", required));
|
|
|
|
|
|
|
|
|
|
|
|
if (mainClass == null) {
|
|
|
|
|
|
|
|
throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String mainClass = extensionYml.getString("main");
|
|
|
|
if (name == null) {
|
|
|
|
String name = extensionYml.getString("name");
|
|
|
|
this.getPlugin().getLogger().warning(extensionJar.getName() + " doesn't have a name!");
|
|
|
|
String version = extensionYml.getString("version");
|
|
|
|
name = "Unnamed Extension " + extensionJar.getName();
|
|
|
|
String author = extensionYml.getString("author");
|
|
|
|
}
|
|
|
|
Validate.notNull(name, "Name is missing!");
|
|
|
|
|
|
|
|
Validate.notNull(version, "Version is missing!");
|
|
|
|
if (version == null) {
|
|
|
|
Validate.notNull(author, "Author is missing!");
|
|
|
|
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);
|
|
|
|
ExtensionMetadata metadata = new ExtensionMetadata(version, name, author);
|
|
|
|
|
|
|
|
|
|
|
|
|