mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2024-11-18 00:46:55 +01:00
updated local expansion to not catch potential linkage errors, and report them. closes #377
This commit is contained in:
parent
30ead2ae4b
commit
07cd344123
@ -229,13 +229,23 @@ public final class LocalExpansionManager implements Listener
|
||||
|
||||
public Optional<PlaceholderExpansion> register(@NotNull final Class<? extends PlaceholderExpansion> clazz)
|
||||
{
|
||||
final PlaceholderExpansion expansion = createExpansionInstance(clazz);
|
||||
if (expansion == null || !expansion.register())
|
||||
try
|
||||
{
|
||||
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)
|
||||
@ -347,13 +357,13 @@ public final class LocalExpansionManager implements Listener
|
||||
|
||||
|
||||
@Nullable
|
||||
public PlaceholderExpansion createExpansionInstance(@NotNull final Class<? extends PlaceholderExpansion> clazz)
|
||||
public PlaceholderExpansion createExpansionInstance(@NotNull final Class<? extends PlaceholderExpansion> clazz) throws LinkageError
|
||||
{
|
||||
try
|
||||
{
|
||||
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);
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user