Better detection for file changes when reloading

- Added file_deleted message
This commit is contained in:
Frank van der Heijden 2020-06-27 11:47:20 +02:00
parent c2049503a7
commit 518ee782da
No known key found for this signature in database
GPG key ID: 26DA56488D314D11
3 changed files with 24 additions and 13 deletions

View file

@ -175,19 +175,11 @@ public class PluginManager {
CloseableResult result = unloadPlugin(plugin);
if (result.getResult() != Result.SUCCESS) return result;
File pluginFile;
try {
pluginFile = RPlugin.getPluginFile(plugin);
} catch (InvocationTargetException | IllegalAccessException ex) {
ex.printStackTrace();
return result.set(Result.ERROR);
}
File pluginFile = getPluginFile(plugin.getName());
if (pluginFile == null) return result.set(Result.FILE_DELETED);
LoadResult loadResult = loadPlugin(pluginFile);
if (!loadResult.isSuccess()) {
Result r = loadResult.getResult();
return result.set((r == Result.NOT_EXISTS) ? Result.FILE_CHANGED : r);
}
if (!loadResult.isSuccess()) return result.set(loadResult.getResult());
return result.set(enablePlugin(loadResult.getPlugin()));
}
@ -294,4 +286,23 @@ public class PluginManager {
if (loader == null) return null;
return loader.getPluginDescription(file);
}
/**
* Attempts to retrieve the plugin file by plugin name.
* @param pluginName The plugin name.
* @return The file, or null if invalid or not found.
*/
public static File getPluginFile(String pluginName) {
for (File file : ServerUtils.getInstance().getJars()) {
PluginDescriptionFile descriptionFile;
try {
descriptionFile = getPluginDescription(file);
} catch (InvalidDescriptionException ex) {
return null;
}
if (descriptionFile == null) return null;
if (descriptionFile.getName().equals(pluginName)) return file;
}
return null;
}
}

View file

@ -9,7 +9,7 @@ public enum Result {
ALREADY_LOADED,
ALREADY_ENABLED,
ALREADY_DISABLED,
FILE_CHANGED,
FILE_DELETED,
INVALID_DESCRIPTION,
INVALID_PLUGIN,
UNKNOWN_DEPENDENCY,