13
0
geforkt von Mirrors/Velocity

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 { public PluginDescription loadCandidate(Path source) throws Exception {
Optional<SerializedPluginDescription> serialized = getSerializedPluginInfo(source); Optional<SerializedPluginDescription> serialized = getSerializedPluginInfo(source);
if (!serialized.isPresent()) { if (serialized.isEmpty()) {
throw new InvalidPluginException("Did not find a valid velocity-plugin.json."); 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"); 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( PluginClassLoader loader = AccessController.doPrivileged(
(PrivilegedAction<PluginClassLoader>) () -> new PluginClassLoader(new URL[]{pluginJarUrl})); (PrivilegedAction<PluginClassLoader>) () -> new PluginClassLoader(new URL[]{pluginJarUrl}));
loader.addToClassloaders(); loader.addToClassloaders();
JavaVelocityPluginDescriptionCandidate candidateInst = JavaVelocityPluginDescriptionCandidate candidateInst =
(JavaVelocityPluginDescriptionCandidate) candidate; (JavaVelocityPluginDescriptionCandidate) candidate;
Class mainClass = loader.loadClass(candidateInst.getMainClass()); Class<?> mainClass = loader.loadClass(candidateInst.getMainClass());
return createDescription(candidateInst, mainClass); return createDescription(candidateInst, mainClass);
} }
@Override @Override
public Module createModule(PluginContainer container) throws Exception { public Module createModule(PluginContainer container) {
PluginDescription description = container.getDescription(); PluginDescription description = container.getDescription();
if (!(description instanceof JavaVelocityPluginDescription)) { if (!(description instanceof JavaVelocityPluginDescription)) {
throw new IllegalArgumentException("Description provided isn't of the Java plugin loader"); 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; JavaVelocityPluginDescription javaDescription = (JavaVelocityPluginDescription) description;
Optional<Path> source = javaDescription.getSource(); Optional<Path> source = javaDescription.getSource();
if (!source.isPresent()) { if (source.isEmpty()) {
throw new IllegalArgumentException("No path in plugin description"); throw new IllegalArgumentException("No path in plugin description");
} }
return new VelocityPluginModule(server, javaDescription, container, baseDirectory); return new VelocityPluginModule(javaDescription, container, baseDirectory);
} }
@Override @Override
@ -184,7 +186,7 @@ public class JavaPluginLoader implements PluginLoader {
private VelocityPluginDescription createDescription( private VelocityPluginDescription createDescription(
JavaVelocityPluginDescriptionCandidate description, JavaVelocityPluginDescriptionCandidate description,
Class mainClass) { Class<?> mainClass) {
return new JavaVelocityPluginDescription( return new JavaVelocityPluginDescription(
description.getId(), description.getId(),
description.getName().orElse(null), 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.PluginContainer;
import com.velocitypowered.api.plugin.PluginDescription; import com.velocitypowered.api.plugin.PluginDescription;
import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
@ -32,14 +31,12 @@ import org.slf4j.LoggerFactory;
class VelocityPluginModule implements Module { class VelocityPluginModule implements Module {
private final ProxyServer server;
private final JavaVelocityPluginDescription description; private final JavaVelocityPluginDescription description;
private final PluginContainer pluginContainer; private final PluginContainer pluginContainer;
private final Path basePluginPath; private final Path basePluginPath;
VelocityPluginModule(ProxyServer server, JavaVelocityPluginDescription description, VelocityPluginModule(JavaVelocityPluginDescription description, PluginContainer pluginContainer,
PluginContainer pluginContainer, Path basePluginPath) { Path basePluginPath) {
this.server = server;
this.description = description; this.description = description;
this.pluginContainer = pluginContainer; this.pluginContainer = pluginContainer;
this.basePluginPath = basePluginPath; this.basePluginPath = basePluginPath;