Drop old special factions upon migration.
This commit is contained in:
parent
638ba4ca7f
commit
09a23353a7
@ -4,12 +4,14 @@ import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.Const;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.mcore.MCore;
|
||||
import com.massivecraft.mcore.usys.Aspect;
|
||||
import com.massivecraft.mcore.util.DiscUtil;
|
||||
import com.massivecraft.mcore.util.MUtil;
|
||||
import com.massivecraft.mcore.xlib.gson.reflect.TypeToken;
|
||||
|
||||
public class FactionColls extends XColls<FactionColl, Faction>
|
||||
@ -61,6 +63,11 @@ public class FactionColls extends XColls<FactionColl, Faction>
|
||||
// Already migrated?
|
||||
if ( ! oldFile.exists()) return;
|
||||
|
||||
// Faction ids /delete
|
||||
// For simplicity we just drop the old special factions.
|
||||
// They will be replaced with new autogenerated ones per universe.
|
||||
Set<String> factionIdsToDelete = MUtil.set("0", "-1", "-2");
|
||||
|
||||
// Read the file content through GSON.
|
||||
Type type = new TypeToken<Map<String, Faction>>(){}.getType();
|
||||
Map<String, Faction> id2faction = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type);
|
||||
@ -72,6 +79,7 @@ public class FactionColls extends XColls<FactionColl, Faction>
|
||||
for (Entry<String, Faction> entry : id2faction.entrySet())
|
||||
{
|
||||
String factionId = entry.getKey();
|
||||
if (factionIdsToDelete.contains(factionId)) continue;
|
||||
Faction faction = entry.getValue();
|
||||
coll.attach(faction, factionId);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user