Skip to content

Commit

Permalink
Clear cache if plugin doesn't load correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
libraryaddict committed Nov 14, 2024
1 parent 5abc9b8 commit c7f5201
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ public void onLoad() {
commandConfig.load();
}
} catch (Throwable throwable) {
ClassMappings.deleteMappingsCache(getDataFolder());

try {
if (isJenkins() && DisguiseConfig.isAutoUpdate()) {
getUpdateChecker().doUpdate();
Expand Down Expand Up @@ -237,6 +239,8 @@ public void onEnable() {

new MetricsInitalizer();
} catch (Throwable throwable) {
ClassMappings.deleteMappingsCache(getDataFolder());

try {
if (isJenkins() && DisguiseConfig.isAutoUpdate()) {
getUpdateChecker().doUpdate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ private static String getVersion() {
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) {
Expand All @@ -103,7 +111,7 @@ public static void saveMappingsCache(File dataFolder) {
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");

Expand All @@ -116,7 +124,8 @@ public static void saveMappingsCache(File dataFolder) {
}

public static void loadMappingsCache(File dataFolder) {
File mappingsCache = new File(dataFolder, "mappings_cache");
File mappingsCache = getFile(dataFolder);

if (!mappingsCache.exists()) {
return;
}
Expand Down

0 comments on commit c7f5201

Please sign in to comment.