3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-09-29 06:30:16 +02:00

Clean up JavaPluginLoader and VelocityPluginModule (#1140)

Dieser Commit ist enthalten in:
Alexander Städing 2024-01-04 17:04:25 +01:00 committet von GitHub
Ursprung 28acf9eac1
Commit 897ff81915
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 11 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -63,7 +63,7 @@ public class JavaPluginLoader implements PluginLoader {
public PluginDescription loadCandidate(Path source) throws Exception {
Optional<SerializedPluginDescription> serialized = getSerializedPluginInfo(source);
if (!serialized.isPresent()) {
if (serialized.isEmpty()) {
throw new InvalidPluginException("Did not find a valid velocity-plugin.json.");
}
@ -81,19 +81,21 @@ public class JavaPluginLoader implements PluginLoader {
throw new IllegalArgumentException("Description provided isn't of the Java plugin loader");
}
URL pluginJarUrl = candidate.getSource().get().toUri().toURL();
URL pluginJarUrl = candidate.getSource().orElseThrow(
() -> new InvalidPluginException("Description provided does not have a source path")
).toUri().toURL();
PluginClassLoader loader = AccessController.doPrivileged(
(PrivilegedAction<PluginClassLoader>) () -> new PluginClassLoader(new URL[]{pluginJarUrl}));
loader.addToClassloaders();
JavaVelocityPluginDescriptionCandidate candidateInst =
(JavaVelocityPluginDescriptionCandidate) candidate;
Class mainClass = loader.loadClass(candidateInst.getMainClass());
Class<?> mainClass = loader.loadClass(candidateInst.getMainClass());
return createDescription(candidateInst, mainClass);
}
@Override
public Module createModule(PluginContainer container) throws Exception {
public Module createModule(PluginContainer container) {
PluginDescription description = container.getDescription();
if (!(description instanceof JavaVelocityPluginDescription)) {
throw new IllegalArgumentException("Description provided isn't of the Java plugin loader");
@ -102,11 +104,11 @@ public class JavaPluginLoader implements PluginLoader {
JavaVelocityPluginDescription javaDescription = (JavaVelocityPluginDescription) description;
Optional<Path> source = javaDescription.getSource();
if (!source.isPresent()) {
if (source.isEmpty()) {
throw new IllegalArgumentException("No path in plugin description");
}
return new VelocityPluginModule(server, javaDescription, container, baseDirectory);
return new VelocityPluginModule(javaDescription, container, baseDirectory);
}
@Override
@ -184,7 +186,7 @@ public class JavaPluginLoader implements PluginLoader {
private VelocityPluginDescription createDescription(
JavaVelocityPluginDescriptionCandidate description,
Class mainClass) {
Class<?> mainClass) {
return new JavaVelocityPluginDescription(
description.getId(),
description.getName().orElse(null),

Datei anzeigen

@ -23,7 +23,6 @@ import com.google.inject.Scopes;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.PluginDescription;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import java.nio.file.Path;
import java.util.concurrent.ExecutorService;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
@ -32,14 +31,12 @@ import org.slf4j.LoggerFactory;
class VelocityPluginModule implements Module {
private final ProxyServer server;
private final JavaVelocityPluginDescription description;
private final PluginContainer pluginContainer;
private final Path basePluginPath;
VelocityPluginModule(ProxyServer server, JavaVelocityPluginDescription description,
PluginContainer pluginContainer, Path basePluginPath) {
this.server = server;
VelocityPluginModule(JavaVelocityPluginDescription description, PluginContainer pluginContainer,
Path basePluginPath) {
this.description = description;
this.pluginContainer = pluginContainer;
this.basePluginPath = basePluginPath;