Backups are now created of bad factions.json and players.json files if they fail to load due to a JSON parse error; same as we already do for bad conf.json
This commit is contained in:
		@@ -3,9 +3,12 @@ package com.massivecraft.factions.zcore.persist;
 | 
				
			|||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
import java.lang.reflect.Type;
 | 
					import java.lang.reflect.Type;
 | 
				
			||||||
import java.util.*;
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					import java.util.logging.Level;
 | 
				
			||||||
import java.util.Map.Entry;
 | 
					import java.util.Map.Entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import org.bukkit.craftbukkit.libs.com.google.gson.Gson;
 | 
					import org.bukkit.craftbukkit.libs.com.google.gson.Gson;
 | 
				
			||||||
 | 
					import org.bukkit.craftbukkit.libs.com.google.gson.JsonSyntaxException;
 | 
				
			||||||
import com.massivecraft.factions.zcore.util.DiscUtil;
 | 
					import com.massivecraft.factions.zcore.util.DiscUtil;
 | 
				
			||||||
import com.massivecraft.factions.zcore.util.TextUtil;
 | 
					import com.massivecraft.factions.zcore.util.TextUtil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -216,8 +219,23 @@ public abstract class EntityCollection<E extends Entity>
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		Type type = this.getMapType();
 | 
							Type type = this.getMapType();
 | 
				
			||||||
 | 
							try
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
			return this.gson.fromJson(content, type);
 | 
								return this.gson.fromJson(content, type);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							catch(JsonSyntaxException ex)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Bukkit.getLogger().log(Level.WARNING, "JSON error encountered loading \"" + file + "\": " + ex.getLocalizedMessage());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// backup bad file, so user can attempt to recover something from it
 | 
				
			||||||
 | 
								File backup = new File(file.getPath()+"_bad");
 | 
				
			||||||
 | 
								if (backup.exists()) backup.delete();
 | 
				
			||||||
 | 
								Bukkit.getLogger().log(Level.WARNING, "Backing up copy of bad file to: "+backup);
 | 
				
			||||||
 | 
								file.renameTo(backup);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return null;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	// ID MANAGEMENT
 | 
						// ID MANAGEMENT
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user