delete old addon system

This commit is contained in:
dfsek
2021-11-18 21:50:41 -07:00
parent 7bf1ba13c8
commit 1028ed0989
11 changed files with 0 additions and 322 deletions

View File

@@ -1,61 +0,0 @@
package com.dfsek.terra.api.addon;
import ca.solostudios.strata.Versions;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.addon.annotations.Addon;
import com.dfsek.terra.api.addon.annotations.Author;
import com.dfsek.terra.api.addon.annotations.Version;
/**
* Represents an entry point for an com.dfsek.terra.addon. Implementations must be annotated with {@link Addon}.
*/
//todo delete this
public abstract class TerraAddon implements BaseAddon {
/**
* Invoked immediately after an com.dfsek.terra.addon is loaded.
*/
public abstract void initialize();
/**
* Gets the version of this com.dfsek.terra.addon.
*
* @return Addon version.
*/
public final @NotNull ca.solostudios.strata.version.Version getVersion() {
Version version = getClass().getAnnotation(Version.class);
return Versions.getVersion(1, 2, 3);
}
/**
* Gets the author of this com.dfsek.terra.addon.
*
* @return Addon author.
*/
public final @NotNull String getAuthor() {
Author author = getClass().getAnnotation(Author.class);
return author == null ? "Anon Y. Mous" : author.value();
}
/**
* Gets the name (ID) of this com.dfsek.terra.addon.
*
* @return Addon ID.
*/
public final @NotNull String getName() {
Addon addon = getClass().getAnnotation(Addon.class);
if(addon == null)
throw new IllegalStateException(
"Addon annotation not present"); // This should never happen; the presence of this annotation is checked by the com
// .dfsek.terra.addon loader.
return addon.value();
}
@Override
public String getID() {
return getName();
}
}

View File

@@ -1,21 +0,0 @@
package com.dfsek.terra.api.addon.annotations;
import org.jetbrains.annotations.NotNull;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Specifies that the annotated class is an entry point for a Terra com.dfsek.terra.addon.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Addon {
/**
* @return The ID of the com.dfsek.terra.addon.
*/
@NotNull String value();
}

View File

@@ -1,21 +0,0 @@
package com.dfsek.terra.api.addon.annotations;
import org.jetbrains.annotations.NotNull;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Optional annotation that specifies the author of an com.dfsek.terra.addon.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Author {
/**
* @return Name of the com.dfsek.terra.addon author.
*/
@NotNull String value();
}

View File

@@ -1,21 +0,0 @@
package com.dfsek.terra.api.addon.annotations;
import org.jetbrains.annotations.NotNull;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Optional annotation that specifies dependencies of an com.dfsek.terra.addon.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Depends {
/**
* @return All addons this com.dfsek.terra.addon is dependent upon.
*/
@NotNull String[] value();
}

View File

@@ -1,21 +0,0 @@
package com.dfsek.terra.api.addon.annotations;
import org.jetbrains.annotations.NotNull;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Optional annotation that specifies the version of an com.dfsek.terra.addon.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Version {
/**
* @return Version of the com.dfsek.terra.addon.
*/
@NotNull String value();
}

View File

@@ -3,12 +3,10 @@ package com.dfsek.terra.api.config;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Set;
import ca.solostudios.strata.version.VersionRange;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.meta.RegistryFactory;
import com.dfsek.terra.api.registry.meta.RegistryHolder;

View File

@@ -1,17 +1,7 @@
package com.dfsek.terra.addon;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.addon.annotations.Addon;
public class AddonClassLoader extends URLClassLoader {
@@ -22,38 +12,4 @@ public class AddonClassLoader extends URLClassLoader {
public AddonClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent);
}
@SuppressWarnings("unchecked")
public static Set<Class<? extends TerraAddon>> fetchAddonClasses(File file, ClassLoader parent) throws IOException {
JarFile jarFile = new JarFile(file);
Enumeration<JarEntry> entries = jarFile.entries();
try(AddonClassLoader loader = new AddonClassLoader(new URL[]{ file.toURI().toURL() }, parent)) {
Set<Class<? extends TerraAddon>> set = new HashSet<>();
while(entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if(entry.isDirectory() || !entry.getName().endsWith(".class")) continue;
String className = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.');
try {
Class<?> clazz = loader.loadClass(className);
Addon addon = clazz.getAnnotation(Addon.class);
if(addon == null) continue;
if(!TerraAddon.class.isAssignableFrom(clazz))
throw new IllegalArgumentException("Addon class \"" + clazz + "\" must extend TerraAddon.");
set.add((Class<? extends TerraAddon>) clazz);
} catch(ClassNotFoundException e) {
throw new IllegalStateException(e); // this should literally never happen, if it does something is very wrong
}
}
return set;
}
}
}

View File

@@ -1,43 +0,0 @@
package com.dfsek.terra.addon;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.dfsek.terra.addon.exception.AddonLoadException;
public class AddonPool {
private final Map<String, PreLoadAddon> pool = new HashMap<>();
public void add(PreLoadAddon addon) throws AddonLoadException {
if(pool.containsKey(addon.getId())) {
String message = "Duplicate com.dfsek.terra.addon ID: " +
addon.getId() + "; original ID from file: " +
pool.get(addon.getId()).getFile().getAbsolutePath() +
", class: " +
pool.get(addon.getId()).getAddonClass().getCanonicalName() +
"Duplicate ID from file: " +
addon.getFile().getAbsolutePath() +
", class: " +
addon.getAddonClass().getCanonicalName();
throw new AddonLoadException(message);
}
pool.put(addon.getId(), addon);
}
public PreLoadAddon get(String id) {
return pool.get(id);
}
public void buildAll() throws AddonLoadException {
for(PreLoadAddon value : pool.values()) {
value.rebuildDependencies(this, value, true);
}
}
public Set<PreLoadAddon> getAddons() {
return new HashSet<>(pool.values());
}
}

View File

@@ -1,61 +0,0 @@
package com.dfsek.terra.addon;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.dfsek.terra.addon.exception.AddonLoadException;
import com.dfsek.terra.addon.exception.CircularDependencyException;
import com.dfsek.terra.addon.exception.DependencyMissingException;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.addon.annotations.Addon;
import com.dfsek.terra.api.addon.annotations.Depends;
public class PreLoadAddon {
private final List<PreLoadAddon> depends = new ArrayList<>();
private final Class<? extends TerraAddon> addonClass;
private final String id;
private final String[] dependencies;
private final File file;
public PreLoadAddon(Class<? extends TerraAddon> addonClass, File file) {
this.addonClass = addonClass;
this.id = addonClass.getAnnotation(Addon.class).value();
this.file = file;
Depends depends = addonClass.getAnnotation(Depends.class);
this.dependencies = depends == null ? new String[]{ } : depends.value();
}
public void rebuildDependencies(AddonPool pool, PreLoadAddon origin, boolean levelG1) throws AddonLoadException {
if(this.equals(origin) && !levelG1)
throw new CircularDependencyException(
"Detected circular dependency in addon \"" + id + "\", dependencies: " + Arrays.toString(dependencies));
for(String dependency : dependencies) {
PreLoadAddon preLoadAddon = pool.get(dependency);
if(preLoadAddon == null)
throw new DependencyMissingException(
"Dependency " + dependency + " was not found. Please install " + dependency + " to use " + id + ".");
depends.add(preLoadAddon);
preLoadAddon.rebuildDependencies(pool, origin, false);
}
}
public List<PreLoadAddon> getDepends() {
return depends;
}
public String getId() {
return id;
}
public Class<? extends TerraAddon> getAddonClass() {
return addonClass;
}
public File getFile() {
return file;
}
}

View File

@@ -1,24 +0,0 @@
package com.dfsek.terra.bukkit;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.addon.annotations.Addon;
import com.dfsek.terra.api.addon.annotations.Author;
import com.dfsek.terra.api.addon.annotations.Version;
@Addon("Terra-Bukkit")
@Version("1.0.0")
@Author("Terra")
final class BukkitAddon extends TerraAddon {
private final Platform platform;
public BukkitAddon(Platform platform) {
this.platform = platform;
}
@Override
public void initialize() {
}
}

View File

@@ -15,9 +15,6 @@ import net.minecraft.world.gen.feature.ConfiguredFeature;
import java.util.HashMap;
import java.util.Map;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.addon.annotations.Addon;
import com.dfsek.terra.api.addon.annotations.Author;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPostLoadEvent;
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;