mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-02-05 15:55:28 +01:00
Fix contract violations & add null checks which should close #515
This commit is contained in:
parent
f0dccbd594
commit
07ac8e41c5
@ -300,7 +300,10 @@ public final class LocalExpansionManager implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final long registered = classes.stream().map(this::register).filter(Optional::isPresent)
|
final long registered = classes.stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(this::register)
|
||||||
|
.filter(Optional::isPresent)
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
Msg.msg(sender,
|
Msg.msg(sender,
|
||||||
@ -321,11 +324,9 @@ public final class LocalExpansionManager implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CompletableFuture<@NotNull List<@NotNull Class<? extends PlaceholderExpansion>>> findExpansionsOnDisk() {
|
public CompletableFuture<@NotNull List<@Nullable Class<? extends PlaceholderExpansion>>> findExpansionsOnDisk() {
|
||||||
return Arrays.stream(folder.listFiles((dir, name) -> name.endsWith(".jar")))
|
return Arrays.stream(folder.listFiles((dir, name) -> name.endsWith(".jar")))
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.map(this::findExpansionInFile)
|
.map(this::findExpansionInFile)
|
||||||
.collect(Futures.collector());
|
.collect(Futures.collector());
|
||||||
}
|
}
|
||||||
@ -335,7 +336,14 @@ public final class LocalExpansionManager implements Listener {
|
|||||||
@NotNull final File file) {
|
@NotNull final File file) {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
return FileUtil.findClass(file, PlaceholderExpansion.class);
|
final Class<? extends PlaceholderExpansion> expansionClass = FileUtil.findClass(file, PlaceholderExpansion.class);
|
||||||
|
|
||||||
|
if (expansionClass == null) {
|
||||||
|
plugin.getLogger().severe("Failed to load Expansion: " + file.getName() + ", as it does not have" +
|
||||||
|
"an a class which extends PlaceholderExpansion.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return expansionClass;
|
||||||
} catch (final VerifyError ex) {
|
} catch (final VerifyError ex) {
|
||||||
plugin.getLogger().severe("Failed to load Expansion class " + file.getName() +
|
plugin.getLogger().severe("Failed to load Expansion class " + file.getName() +
|
||||||
" (Is a dependency missing?)");
|
" (Is a dependency missing?)");
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
|
|
||||||
package me.clip.placeholderapi.util;
|
package me.clip.placeholderapi.util;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -28,8 +31,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarInputStream;
|
import java.util.jar.JarInputStream;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class FileUtil {
|
public class FileUtil {
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ public class FileUtil {
|
|||||||
JarEntry entry;
|
JarEntry entry;
|
||||||
while ((entry = stream.getNextJarEntry()) != null) {
|
while ((entry = stream.getNextJarEntry()) != null) {
|
||||||
final String name = entry.getName();
|
final String name = entry.getName();
|
||||||
if (name == null || name.isEmpty() || !name.endsWith(".class")) {
|
if (name.isEmpty() || !name.endsWith(".class")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user