Clear cache if plugin doesn't load correctly

This commit is contained in:
libraryaddict 2024-11-14 23:54:15 +13:00
parent 5abc9b8fc1
commit c7f5201e00
2 changed files with 15 additions and 2 deletions

View File

@ -174,6 +174,8 @@ public class LibsDisguises extends JavaPlugin {
commandConfig.load();
}
} catch (Throwable throwable) {
ClassMappings.deleteMappingsCache(getDataFolder());
try {
if (isJenkins() && DisguiseConfig.isAutoUpdate()) {
getUpdateChecker().doUpdate();
@ -237,6 +239,8 @@ public class LibsDisguises extends JavaPlugin {
new MetricsInitalizer();
} catch (Throwable throwable) {
ClassMappings.deleteMappingsCache(getDataFolder());
try {
if (isJenkins() && DisguiseConfig.isAutoUpdate()) {
getUpdateChecker().doUpdate();

View File

@ -94,6 +94,14 @@ public class ClassMappings {
return "Built for: " + Bukkit.getVersion() + "\t" + LibsDisguises.getInstance().getDescription().getVersion();
}
private static File getFile(File dataFolder) {
return new File(dataFolder, "mappings_cache");
}
public static void deleteMappingsCache(File folder) {
getFile(folder).delete();
}
public static void saveMappingsCache(File dataFolder) {
synchronized (classLocations) {
if (!updatingCache) {
@ -103,7 +111,7 @@ public class ClassMappings {
updatingCache = false;
}
File mappingsCache = new File(dataFolder, "mappings_cache");
File mappingsCache = getFile(dataFolder);
try (BufferedWriter writer = new BufferedWriter(new FileWriter(mappingsCache))) {
writer.write(getVersion() + "\n");
@ -116,7 +124,8 @@ public class ClassMappings {
}
public static void loadMappingsCache(File dataFolder) {
File mappingsCache = new File(dataFolder, "mappings_cache");
File mappingsCache = getFile(dataFolder);
if (!mappingsCache.exists()) {
return;
}