mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 08:25:31 +00:00
more specific duplicate ID message
This commit is contained in:
parent
58162027a9
commit
ce3c0f105e
@ -11,8 +11,18 @@ public class AddonPool {
|
||||
private final Map<String, PreLoadAddon> pool = new HashMap<>();
|
||||
|
||||
public void add(PreLoadAddon addon) throws AddonLoadException {
|
||||
if(pool.containsKey(addon.getId()))
|
||||
throw new AddonLoadException("Duplicate addon ID: " + addon.getId());
|
||||
if(pool.containsKey(addon.getId())) {
|
||||
String message = "Duplicate 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);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.dfsek.terra.api.addons.TerraAddon;
|
||||
import com.dfsek.terra.api.addons.annotations.Addon;
|
||||
import com.dfsek.terra.api.addons.annotations.Depends;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -16,10 +17,12 @@ public class PreLoadAddon {
|
||||
private final Class<? extends TerraAddon> addonClass;
|
||||
private final String id;
|
||||
private final String[] dependencies;
|
||||
private final File file;
|
||||
|
||||
public PreLoadAddon(Class<? extends TerraAddon> addonClass) {
|
||||
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();
|
||||
}
|
||||
@ -48,4 +51,8 @@ public class PreLoadAddon {
|
||||
public Class<? extends TerraAddon> getAddonClass() {
|
||||
return addonClass;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class AddonRegistry extends OpenRegistry<TerraAddon> {
|
||||
for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) {
|
||||
main.logger().info("Loading Addon(s) from: " + jar.getName());
|
||||
for(Class<? extends TerraAddon> addonClass : AddonClassLoader.fetchAddonClasses(jar)) {
|
||||
pool.add(new PreLoadAddon(addonClass));
|
||||
pool.add(new PreLoadAddon(addonClass, jar));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user