From b99335e5b26162a7e9836ad1f4f8c2ce88567e1d Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Sun, 27 Dec 2020 18:47:48 +0100 Subject: [PATCH] First step at fixing #515 and for #516 --- .../manager/LocalExpansionManager.java | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java b/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java index 6ec3153..19cf234 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java +++ b/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java @@ -22,27 +22,11 @@ package me.clip.placeholderapi.expansion.manager; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; -import java.io.File; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReentrantLock; -import java.util.logging.Level; import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.events.ExpansionRegisterEvent; import me.clip.placeholderapi.events.ExpansionUnregisterEvent; import me.clip.placeholderapi.events.ExpansionsLoadedEvent; -import me.clip.placeholderapi.expansion.Cacheable; -import me.clip.placeholderapi.expansion.Cleanable; -import me.clip.placeholderapi.expansion.Configurable; -import me.clip.placeholderapi.expansion.PlaceholderExpansion; -import me.clip.placeholderapi.expansion.Taskable; -import me.clip.placeholderapi.expansion.VersionSpecific; +import me.clip.placeholderapi.expansion.*; import me.clip.placeholderapi.expansion.cloud.CloudExpansion; import me.clip.placeholderapi.util.FileUtil; import me.clip.placeholderapi.util.Futures; @@ -61,6 +45,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; +import java.io.File; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; +import java.util.logging.Level; + public final class LocalExpansionManager implements Listener { @NotNull @@ -167,9 +159,9 @@ public final class LocalExpansionManager implements Listener { 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()); + plugin.getLogger().severe("Failed to load Expansion class " + clazz.getSimpleName() + + " (Is a dependency missing?)"); + plugin.getLogger().severe("Cause: " + ex.getClass().getSimpleName() + " " + ex.getMessage()); } return Optional.empty(); @@ -218,9 +210,8 @@ public final class LocalExpansionManager implements Listener { if (expansion instanceof VersionSpecific) { VersionSpecific nms = (VersionSpecific) expansion; if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) { - plugin.getLogger().info( - "Your server version is not compatible with expansion: " + expansion.getIdentifier() - + " version: " + expansion.getVersion()); + plugin.getLogger().warning("Your server version is not compatible with expansion " + + expansion.getIdentifier() + " " + expansion.getVersion()); return false; } } @@ -334,6 +325,7 @@ public final class LocalExpansionManager implements Listener { @NotNull public CompletableFuture<@NotNull List<@NotNull Class>> findExpansionsOnDisk() { return Arrays.stream(folder.listFiles((dir, name) -> name.endsWith(".jar"))) + .filter(Objects::nonNull) .map(this::findExpansionInFile) .collect(Futures.collector()); } @@ -345,9 +337,9 @@ public final class LocalExpansionManager implements Listener { try { return FileUtil.findClass(file, PlaceholderExpansion.class); } catch (final VerifyError ex) { - plugin.getLogger().severe("expansion file " + file.getName() + " is outdated: \n" + - "Failed to load due to a [" + ex.getClass().getSimpleName() + "], attempted to use" + ex - .getMessage().substring(ex.getMessage().lastIndexOf(' '))); + plugin.getLogger().severe("Failed to load Expansion class " + file.getName() + + " (Is a dependency missing?)"); + plugin.getLogger().severe("Cause: " + ex.getClass().getSimpleName() + " " + ex.getMessage()); return null; } catch (final Exception ex) { throw new CompletionException(ex); @@ -365,10 +357,13 @@ public final class LocalExpansionManager implements Listener { if (ex.getCause() instanceof LinkageError) { throw ((LinkageError) ex.getCause()); } - - plugin.getLogger() - .log(Level.SEVERE, "Failed to load placeholder expansion from class: " + clazz.getName(), - ex); + + /* Currently causes an exception when clazz is null due to an expansion not having any. + * + *plugin.getLogger() + * .log(Level.SEVERE, "Failed to load placeholder expansion from class: " + clazz.getName(), + * ex); + */ return null; } }