Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2025-01-11 23:51:22 +01:00
Clean up JavaPluginLoader and VelocityPluginModule (#1140)
Dieser Commit ist enthalten in:
Ursprung
28acf9eac1
Commit
897ff81915
@ -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),
|
||||
|
@ -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;
|
||||
|
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren