Fix migrator bug
This commit is contained in:
parent
5d09b5d05f
commit
6b14bb0b56
@ -1,8 +1,11 @@
|
|||||||
package com.massivecraft.factions.entity.migrator;
|
package com.massivecraft.factions.entity.migrator;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
import com.massivecraft.factions.entity.Faction;
|
import com.massivecraft.factions.entity.Faction;
|
||||||
|
import com.massivecraft.factions.entity.FactionColl;
|
||||||
|
import com.massivecraft.factions.entity.MConf;
|
||||||
import com.massivecraft.factions.entity.MPlayer;
|
import com.massivecraft.factions.entity.MPlayer;
|
||||||
import com.massivecraft.factions.entity.Rank;
|
import com.massivecraft.factions.entity.Rank;
|
||||||
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
|
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
|
||||||
@ -29,18 +32,45 @@ public class MigratorMPlayer001Ranks extends MigratorRoot
|
|||||||
@Override
|
@Override
|
||||||
public void migrateInner(JsonObject entity)
|
public void migrateInner(JsonObject entity)
|
||||||
{
|
{
|
||||||
String role = entity.remove("role").getAsString();
|
// Get role
|
||||||
String factionId = entity.get("factionId").getAsString();
|
JsonElement jsonRole = entity.remove("role");
|
||||||
Faction faction = Faction.get(factionId);
|
String role;
|
||||||
|
if (jsonRole == null)
|
||||||
Collection<Rank> ranks = faction.getRanks().getAll();
|
|
||||||
for (Rank rank : ranks)
|
|
||||||
{
|
{
|
||||||
if (!rank.getName().equalsIgnoreCase(role)) continue;
|
// The role can be null.
|
||||||
|
// Then they are probably recruit in the default faction (Wilderness).
|
||||||
entity.add("rankId", new JsonPrimitive(rank.getId()));
|
role = null;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
role = jsonRole.getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get faction
|
||||||
|
JsonElement jsonFaction = entity.get("factionId");
|
||||||
|
|
||||||
|
String factionId;
|
||||||
|
if (jsonFaction == null) factionId = MConf.get().defaultPlayerFactionId;
|
||||||
|
else factionId = jsonFaction.getAsString();
|
||||||
|
|
||||||
|
Faction faction = FactionColl.get().get(factionId);
|
||||||
|
if (faction == null) faction = FactionColl.get().getNone();
|
||||||
|
|
||||||
|
// Get rank
|
||||||
|
Rank rank = null;
|
||||||
|
if (role != null)
|
||||||
|
{
|
||||||
|
Collection<Rank> ranks = faction.getRanks().getAll();
|
||||||
|
for (Rank r : ranks)
|
||||||
|
{
|
||||||
|
if (!r.getName().equalsIgnoreCase(role)) continue;
|
||||||
|
rank = r;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rank == null) rank = faction.getLowestRank();
|
||||||
|
|
||||||
|
entity.add("rankId", new JsonPrimitive(rank.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user