refactor addon loader to new module

This commit is contained in:
dfsek
2021-06-29 19:34:54 -07:00
parent 9880f488e5
commit 22c97ca390
18 changed files with 33 additions and 33 deletions

View File

@@ -7,11 +7,11 @@ import com.dfsek.terra.api.addon.annotations.Version;
import org.jetbrains.annotations.NotNull;
/**
* Represents an entry point for an addon. Implementations must be annotated with {@link Addon}.
* Represents an entry point for an com.dfsek.terra.addon. Implementations must be annotated with {@link Addon}.
*/
public abstract class TerraAddon {
/**
* Gets the version of this addon.
* Gets the version of this com.dfsek.terra.addon.
*
* @return Addon version.
*/
@@ -21,7 +21,7 @@ public abstract class TerraAddon {
}
/**
* Gets the author of this addon.
* Gets the author of this com.dfsek.terra.addon.
*
* @return Addon author.
*/
@@ -31,19 +31,19 @@ public abstract class TerraAddon {
}
/**
* Gets the name (ID) of this addon.
* 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 addon loader.
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();
}
/**
* Invoked immediately after an addon is loaded.
* Invoked immediately after an com.dfsek.terra.addon is loaded.
*/
public abstract void initialize();
}

View File

@@ -8,13 +8,13 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Specifies that the annotated class is an entry point for a Terra addon.
* 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 addon.
* @return The ID of the com.dfsek.terra.addon.
*/
@NotNull String value();
}

View File

@@ -8,13 +8,13 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Optional annotation that specifies the author of an addon.
* 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 addon author.
* @return Name of the com.dfsek.terra.addon author.
*/
@NotNull String value();
}

View File

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

View File

@@ -8,13 +8,13 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Optional annotation that specifies the version of an addon.
* 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 addon.
* @return Version of the com.dfsek.terra.addon.
*/
@NotNull String value();
}

View File

@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
/**
* Specifies that an event handler is to handle all {@link PackEvent}s, regardless of whether the pack
* depends on the addon's listener.
* depends on the com.dfsek.terra.addon's listener.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)

View File

@@ -6,8 +6,8 @@ import com.dfsek.terra.api.event.annotations.Global;
/**
* An event with functionality directly linked to a {@link ConfigPack}.
* <p>
* PackEvents are only invoked when the pack specifies the addon in its
* {@code addon} key (or when the listener is annotated {@link Global}).
* PackEvents are only invoked when the pack specifies the com.dfsek.terra.addon in its
* {@code com.dfsek.terra.addon} key (or when the listener is annotated {@link Global}).
*/
@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
public interface PackEvent extends Event {

View File

@@ -34,7 +34,7 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
public boolean add(String identifier, TerraAddon addon) {
if(contains(identifier)) throw new IllegalArgumentException("Addon " + identifier + " is already registered.");
addon.initialize();
main.logger().info("Loaded addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor());
main.logger().info("Loaded com.dfsek.terra.addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor());
return super.add(identifier, addon);
}
@@ -88,15 +88,15 @@ public class AddonRegistry extends OpenRegistryImpl<TerraAddon> {
pluginInjector.inject(loadedAddon);
loggerInjector.inject(loadedAddon);
} catch(InstantiationException | IllegalAccessException | InvocationTargetException | InjectionException e) {
throw new AddonLoadException("Failed to load addon \" + " + addon.getId() + "\": ", e);
throw new AddonLoadException("Failed to load com.dfsek.terra.addon \" + " + addon.getId() + "\": ", e);
}
try {
addChecked(loadedAddon.getName(), loadedAddon);
} catch(DuplicateEntryException e) {
valid = false;
main.logger().severe("Duplicate addon ID; addon with ID " + loadedAddon.getName() + " is already loaded.");
main.logger().severe("Existing addon class: " + get(loadedAddon.getName()).getClass().getCanonicalName());
main.logger().severe("Duplicate addon class: " + addonClass.getCanonicalName());
main.logger().severe("Duplicate com.dfsek.terra.addon ID; com.dfsek.terra.addon with ID " + loadedAddon.getName() + " is already loaded.");
main.logger().severe("Existing com.dfsek.terra.addon class: " + get(loadedAddon.getName()).getClass().getCanonicalName());
main.logger().severe("Duplicate com.dfsek.terra.addon class: " + addonClass.getCanonicalName());
}
}
} catch(AddonLoadException | IOException e) {

View File

@@ -12,7 +12,7 @@ public class AddonPool {
public void add(PreLoadAddon addon) throws AddonLoadException {
if(pool.containsKey(addon.getId())) {
String message = "Duplicate addon ID: " +
String message = "Duplicate com.dfsek.terra.addon ID: " +
addon.getId() + "; original ID from file: " +
pool.get(addon.getId()).getFile().getAbsolutePath() +
", class: " +

View File

@@ -1,8 +1,8 @@
package com.dfsek.terra.addon;
import com.dfsek.terra.addon.exception.DependencyMissingException;
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;
@@ -33,7 +33,7 @@ public class PreLoadAddon {
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));
throw new CircularDependencyException("Detected circular dependency in com.dfsek.terra.addon \"" + id + "\", dependencies: " + Arrays.toString(dependencies));
for(String dependency : dependencies) {
PreLoadAddon preLoadAddon = pool.get(dependency);

View File

@@ -129,10 +129,10 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
public void setHandle(WorldHandle handle) {
getLogger().warning("|-------------------------------------------------------|");
getLogger().warning("A third-party addon has injected a custom WorldHandle!");
getLogger().warning("If you encounter issues, try *without* the addon before");
getLogger().warning("reporting to Terra. Report issues with the addon to the");
getLogger().warning("addon's maintainers!");
getLogger().warning("A third-party com.dfsek.terra.addon has injected a custom WorldHandle!");
getLogger().warning("If you encounter issues, try *without* the com.dfsek.terra.addon before");
getLogger().warning("reporting to Terra. Report issues with the com.dfsek.terra.addon to the");
getLogger().warning("com.dfsek.terra.addon's maintainers!");
getLogger().warning("|-------------------------------------------------------|");
this.handle = handle;
}
@@ -183,7 +183,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
if(config.isDebugProfiler()) profiler.start();
if(!addonRegistry.loadAll()) {
getLogger().severe("Failed to load addons. Please correct addon installations to continue.");
getLogger().severe("Failed to load addons. Please correct com.dfsek.terra.addon installations to continue.");
Bukkit.getPluginManager().disablePlugin(this);
return;
}

View File

@@ -26,7 +26,7 @@ public class TerraListener implements EventListener {
String id = BukkitAdapter.TREE_TRANSFORMER.translate(value);
event.getPack().getRegistry(Tree.class).add(id, new BukkitTree(value, main));
event.getPack().getRegistry(Tree.class).get(id); // Platform trees should never be marked "dead"
} catch(DuplicateEntryException ignore) { // If another addon has already registered trees, do nothing.
} catch(DuplicateEntryException ignore) { // If another com.dfsek.terra.addon has already registered trees, do nothing.
}
}
}

View File

@@ -258,7 +258,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
if(config.isDebugProfiler()) profiler.start();
if(!addonRegistry.loadAll()) {
throw new IllegalStateException("Failed to load addons. Please correct addon installations to continue.");
throw new IllegalStateException("Failed to load addons. Please correct com.dfsek.terra.addon installations to continue.");
}
logger.info("Loaded addons.");

View File

@@ -162,7 +162,7 @@ public class TerraForgePlugin implements TerraPlugin {
logger.info("Initializing Terra...");
if(!addonRegistry.loadAll()) {
throw new IllegalStateException("Failed to load addons. Please correct addon installations to continue.");
throw new IllegalStateException("Failed to load addons. Please correct com.dfsek.terra.addon installations to continue.");
}
logger.info("Loaded addons.");