Skip to content

Commit

Permalink
Ensure autoloaders and loaded interfaces play nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaxydog committed Jun 12, 2024
1 parent a76b359 commit 370b47b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Fabric mod, add the following to your Gradle manifest:
```properties
# gradle.properties

lodestone_version = 1.1.1
lodestone_version = 1.1.2
```

```groovy
Expand Down
8 changes: 8 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ Ensure that `AutoLoader` instances are skipped if annotated with `IgnoreLoading`
## Internal Changes

- Properly handle `IgnoreLoading` for `AutoLoader` instances.

# Minor Patch 1.1.2

Ensure that `AutoLoader` instances play nicely when also implementing a `Loaded` interface.

## Internal Changes

- Check for instances of `AutoLoader` before checking for `Loaded` inheritance.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ yarn_mappings = 1.20.6+build.3
loader_version = 0.15.11

# Mod Properties
mod_version = 1.1.1
mod_version = 1.1.2
maven_group = dev.jaxydog.lodestone
archives_base_name = lodestone

Expand Down
28 changes: 13 additions & 15 deletions src/main/java/dev/jaxydog/lodestone/api/AutoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,22 @@ private <T extends Loaded> void iterate(Class<? extends T> type, BiConsumer<Fiel
if (types.isEmpty() || types.contains(type)) continue;
}

// Ensure the field is an instance of the given type.
if (!type.isAssignableFrom(field.getType())) {
// Make sure we invoke internal autoloader instances.
if (AutoLoader.class.isAssignableFrom(field.getType())) {
try {
((AutoLoader) field.get(null)).iterate(type, consumer);
} catch (IllegalAccessException | IllegalArgumentException exception) {
final String className = this.getClass().getSimpleName();
final String fieldName = field.getName();
final String message = exception.getLocalizedMessage();

this.logger.error("Unable to access loader '{}#{}': {}", className, fieldName, message);
}
// Make sure we invoke internal autoloader instances.
if (AutoLoader.class.isAssignableFrom(field.getType())) {
try {
((AutoLoader) field.get(null)).iterate(type, consumer);
} catch (IllegalAccessException | IllegalArgumentException exception) {
final String className = this.getClass().getSimpleName();
final String fieldName = field.getName();
final String message = exception.getLocalizedMessage();

this.logger.error("Unable to access loader '{}#{}': {}", className, fieldName, message);
}

continue;
}

// Ensure the field is an instance of the given type.
if (!type.isAssignableFrom(field.getType())) continue;

try {
consumer.accept(field, (T) field.get(null));
} catch (IllegalAccessException | IllegalArgumentException exception) {
Expand Down

0 comments on commit 370b47b

Please sign in to comment.