Skip to content

Commit

Permalink
Separated errors when module file does not exist and when it's not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Aug 19, 2022
1 parent b63455c commit 6482d64
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Expand Up @@ -86,11 +86,11 @@ public void execute(SuperiorSkyblockPlugin plugin, CommandSender sender, String[
File moduleFile = new File(plugin.getDataFolder(), "modules/" + args[2] + ".jar");
try {
pluginModule = plugin.getModules().registerModule(moduleFile);
Message.MODULE_LOADED_SUCCESS.send(sender, pluginModule.getName());
} catch (Exception ex) {
Message.MODULE_LOADED_FAILURE.send(sender, args[2]);
ex.printStackTrace();
PluginDebugger.debug(ex);
return;
}
} else {
if (pluginModule.isInitialized()) {
Expand All @@ -99,9 +99,11 @@ public void execute(SuperiorSkyblockPlugin plugin, CommandSender sender, String[
}

plugin.getModules().registerModule(pluginModule);
Message.MODULE_LOADED_SUCCESS.send(sender, pluginModule.getName());
}

plugin.getModules().enableModule(pluginModule);
Message.MODULE_LOADED_SUCCESS.send(sender, pluginModule.getName());

break;
case "unload":
if (pluginModule == null) {
Expand Down
Expand Up @@ -56,7 +56,10 @@ public void registerModule(PluginModule pluginModule) {

@Override
public PluginModule registerModule(File moduleFile) throws IOException, ReflectiveOperationException {
if (!moduleFile.exists() || !moduleFile.getName().endsWith(".jar"))
if (!moduleFile.exists())
throw new IllegalArgumentException("The given file does not exist.");

if (!moduleFile.getName().endsWith(".jar"))
throw new IllegalArgumentException("The given file is not a valid jar file.");

String moduleName = moduleFile.getName().replace(".jar", "");
Expand Down

0 comments on commit 6482d64

Please sign in to comment.