Allow naming of chunks

This commit is contained in:
Magnus Ulf
2021-02-21 14:02:59 +01:00
parent bc01275933
commit bc62e17068
7 changed files with 159 additions and 26 deletions

View File

@@ -26,6 +26,7 @@ public class TerritoryAccessAdapter implements JsonDeserializer<TerritoryAccess>
public static final String HOST_FACTION_ID = "hostFactionId";
public static final String HOST_FACTION_ALLOWED = "hostFactionAllowed";
public static final String GRANTED_IDS = "grantedIds";
public static final String CHUNK_NAME = "chunkName";
public static final Type SET_OF_STRING_TYPE = new TypeToken<Set<String>>(){}.getType();
@@ -57,7 +58,8 @@ public class TerritoryAccessAdapter implements JsonDeserializer<TerritoryAccess>
String hostFactionId = null;
Boolean hostFactionAllowed = null;
Set<String> grantedIds = Collections.emptySet();
String chunkName = null;
// Read variables (test old values first)
JsonElement element = null;
@@ -69,8 +71,11 @@ public class TerritoryAccessAdapter implements JsonDeserializer<TerritoryAccess>
element = obj.get(GRANTED_IDS);
if (element != null) grantedIds = context.deserialize(element, SET_OF_STRING_TYPE);
element = obj.get(CHUNK_NAME);
if (element != null) chunkName = element.getAsString();
return TerritoryAccess.valueOf(hostFactionId, hostFactionAllowed, grantedIds);
return TerritoryAccess.valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName);
}
@Override
@@ -99,6 +104,11 @@ public class TerritoryAccessAdapter implements JsonDeserializer<TerritoryAccess>
obj.add(GRANTED_IDS, context.serialize(src.getGrantedIds(), SET_OF_STRING_TYPE));
}
if (src.getChunkName() != null)
{
obj.addProperty(CHUNK_NAME, src.getChunkName());
}
obj.add(MigratorUtil.VERSION_FIELD_NAME, new JsonPrimitive(src.version));
return obj;