Better detection for file changes when reloading
- Added file_deleted message
This commit is contained in:
parent
c2049503a7
commit
518ee782da
3 changed files with 24 additions and 13 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public enum Result {
|
|||
ALREADY_LOADED,
|
||||
ALREADY_ENABLED,
|
||||
ALREADY_DISABLED,
|
||||
FILE_CHANGED,
|
||||
FILE_DELETED,
|
||||
INVALID_DESCRIPTION,
|
||||
INVALID_PLUGIN,
|
||||
UNKNOWN_DEPENDENCY,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue