updated local expansion to not catch potential linkage errors, and report them. closes #377

This commit is contained in:
Sxtanna 2020-07-25 23:55:17 -04:00
parent 30ead2ae4b
commit 07cd344123

View File

@ -229,13 +229,23 @@ public final class LocalExpansionManager implements Listener
public Optional<PlaceholderExpansion> register(@NotNull final Class<? extends PlaceholderExpansion> clazz) public Optional<PlaceholderExpansion> register(@NotNull final Class<? extends PlaceholderExpansion> clazz)
{ {
final PlaceholderExpansion expansion = createExpansionInstance(clazz); try
if (expansion == null || !expansion.register())
{ {
return Optional.empty(); final PlaceholderExpansion expansion = createExpansionInstance(clazz);
if (expansion == null || !expansion.register())
{
return Optional.empty();
}
return Optional.of(expansion);
}
catch (final LinkageError ex)
{
plugin.getLogger().severe("expansion class " + clazz.getSimpleName() + " is outdated: \n" +
"Failed to load due to a [" + ex.getClass().getSimpleName() + "], attempted to use " + ex.getMessage());
} }
return Optional.of(expansion); return Optional.empty();
} }
public boolean unregister(@NotNull final PlaceholderExpansion expansion) public boolean unregister(@NotNull final PlaceholderExpansion expansion)
@ -347,13 +357,13 @@ public final class LocalExpansionManager implements Listener
@Nullable @Nullable
public PlaceholderExpansion createExpansionInstance(@NotNull final Class<? extends PlaceholderExpansion> clazz) public PlaceholderExpansion createExpansionInstance(@NotNull final Class<? extends PlaceholderExpansion> clazz) throws LinkageError
{ {
try try
{ {
return clazz.getDeclaredConstructor().newInstance(); return clazz.getDeclaredConstructor().newInstance();
} }
catch (final Throwable ex) catch (final Exception ex)
{ {
plugin.getLogger().log(Level.SEVERE, "Failed to load placeholder expansion from class: " + clazz.getName(), ex); plugin.getLogger().log(Level.SEVERE, "Failed to load placeholder expansion from class: " + clazz.getName(), ex);
return null; return null;