From e6c178aae7567d6980afdf6018af13b6dfa1cbe6 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 27 Sep 2018 15:52:31 -0400 Subject: [PATCH] Cleaned up Java plugin loader --- .../proxy/plugin/loader/JavaPluginLoader.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java index 09d1df949..c67a18bd2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java @@ -43,21 +43,18 @@ public class JavaPluginLoader implements PluginLoader { throw new InvalidPluginException("Did not find a valid velocity-info.json."); } + SerializedPluginDescription pd = serialized.get(); + if (!PluginDescription.ID_PATTERN.matcher(pd.getId()).matches()) { + throw new InvalidPluginException("Plugin ID '" + pd.getId() + "' must match pattern " + + PluginDescription.ID_PATTERN.pattern()); + } + PluginClassLoader loader = new PluginClassLoader( new URL[] {source.toUri().toURL() } ); - Class mainClass = loader.loadClass(serialized.get().getMain()); - VelocityPluginDescription description = createDescription(serialized.get(), source, mainClass); - - String pluginId = description.getId(); - Pattern pattern = PluginDescription.ID_PATTERN; - - if (!pattern.matcher(pluginId).matches()) { - throw new InvalidPluginException("Plugin ID '" + pluginId + "' must match pattern " + pattern.pattern()); - } - - return description; + Class mainClass = loader.loadClass(pd.getMain()); + return createDescription(pd, source, mainClass); } @Override