Skip to content

Commit

Permalink
Allow TraitInfo to have an arguments constructor if a supplier is given
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Nov 6, 2022
1 parent ecff976 commit b84d7d2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/net/citizensnpcs/api/trait/TraitInfo.java
Expand Up @@ -22,6 +22,16 @@ public TraitInfo asDefaultTrait() {
return this;
}

public void checkValid() {
if (supplier == null) {
try {
trait.getConstructor(new Class<?>[] {});
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Trait class must have a no-arguments constructor");
}
}
}

public Class<? extends Trait> getTraitClass() {
return trait;
}
Expand Down Expand Up @@ -75,11 +85,6 @@ public TraitInfo withSupplier(Supplier<? extends Trait> supplier) {
*/
public static TraitInfo create(Class<? extends Trait> trait) {
Preconditions.checkNotNull(trait);
try {
trait.getConstructor(new Class<?>[] {});
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Trait class must have a no-arguments constructor");
}
return new TraitInfo(trait);
}
}

0 comments on commit b84d7d2

Please sign in to comment.