Change the underlying mechanics of /f access

This commit is contained in:
Magnus Ulf 2019-04-14 23:18:10 +02:00
parent 7c214496b7
commit d015f19181
12 changed files with 182 additions and 230 deletions

View File

@ -64,6 +64,7 @@ import com.massivecraft.factions.entity.migrator.MigratorMConf005Warps;
import com.massivecraft.factions.entity.migrator.MigratorMPerm001Warps;
import com.massivecraft.factions.entity.migrator.MigratorMPlayer001Ranks;
import com.massivecraft.factions.entity.migrator.MigratorMPlayer002UsingAdminMode;
import com.massivecraft.factions.entity.migrator.MigratorTerritoryAccess001Restructure;
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
import com.massivecraft.factions.integration.V18.IntegrationV18;
import com.massivecraft.factions.integration.V19.IntegrationV19;
@ -131,6 +132,7 @@ public class Factions extends MassivePlugin
MUtil.registerExtractor(String.class, "accountId", ExtractorFactionAccountId.get());
MigratorUtil.addJsonRepresentation(Board.class, Board.MAP_TYPE);
MigratorUtil.setTargetVersion(TerritoryAccess.class, 1);
// Activate
this.activateAuto();
@ -154,7 +156,8 @@ public class Factions extends MassivePlugin
MigratorMConf005Warps.class,
MigratorMPerm001Warps.class,
MigratorMPlayer001Ranks.class,
MigratorMPlayer002UsingAdminMode.class
MigratorMPlayer002UsingAdminMode.class,
MigratorTerritoryAccess001Restructure.class
);
}

View File

@ -1,7 +1,10 @@
package com.massivecraft.factions;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPerm.MPermable;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.massivecore.collections.MassiveSet;
import java.util.Collection;
@ -23,56 +26,42 @@ public class TerritoryAccess
public boolean isHostFactionAllowed() { return this.hostFactionAllowed; }
// default is empty
private final Set<String> factionIds;
public Set<String> getFactionIds() { return this.factionIds; }
private final Set<String> grantedIds;
public Set<String> getGrantedIds() { return this.grantedIds; }
// default is empty
private final Set<String> playerIds;
public Set<String> getPlayerIds() { return this.playerIds; }
// -------------------------------------------- //
// FIELDS: VERSION
// -------------------------------------------- //
public int version = 1;
// -------------------------------------------- //
// FIELDS: DELTA
// -------------------------------------------- //
// The simple ones
public TerritoryAccess withHostFactionId(String hostFactionId) { return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds); }
public TerritoryAccess withHostFactionAllowed(Boolean hostFactionAllowed) { return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds); }
public TerritoryAccess withFactionIds(Collection<String> factionIds) { return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds); }
public TerritoryAccess withPlayerIds(Collection<String> playerIds) { return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds); }
public TerritoryAccess withHostFactionId(String hostFactionId) { return valueOf(hostFactionId, hostFactionAllowed, grantedIds); }
public TerritoryAccess withHostFactionAllowed(Boolean hostFactionAllowed) { return valueOf(hostFactionId, hostFactionAllowed, grantedIds); }
public TerritoryAccess withGrantedIds(Collection<String> factionIds) { return valueOf(hostFactionId, hostFactionAllowed, grantedIds); }
// The intermediate ones
public TerritoryAccess withFactionId(String factionId, boolean with)
public TerritoryAccess withGrantedId(String grantedId, boolean with)
{
if (this.getHostFactionId().equals(factionId))
if (this.getHostFactionId().equals(grantedId))
{
return valueOf(hostFactionId, with, factionIds, playerIds);
return valueOf(hostFactionId, with, grantedIds);
}
Set<String> factionIds = new MassiveSet<>(this.getFactionIds());
Set<String> grantedIds = new MassiveSet<>(this.getGrantedIds());
if (with)
{
factionIds.add(factionId);
grantedIds.add(grantedId);
}
else
{
factionIds.remove(factionId);
grantedIds.remove(grantedId);
}
return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds);
}
public TerritoryAccess withPlayerId(String playerId, boolean with)
{
playerId = playerId.toLowerCase();
Set<String> playerIds = new MassiveSet<>(this.getPlayerIds());
if (with)
{
playerIds.add(playerId);
}
else
{
playerIds.remove(playerId);
}
return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds);
return valueOf(hostFactionId, hostFactionAllowed, grantedIds);
}
// -------------------------------------------- //
@ -86,67 +75,36 @@ public class TerritoryAccess
return Faction.get(this.getHostFactionId());
}
public Set<MPlayer> getGrantedMPlayers()
public Set<MPermable> getGranteds()
{
// Create
Set<MPlayer> ret = new MassiveSet<>();
// Fill
for (String playerId : this.getPlayerIds())
{
ret.add(MPlayer.get(playerId));
}
// Return
return ret;
}
public Set<Faction> getGrantedFactions()
{
// Create
Set<Faction> ret = new MassiveSet<>();
// Fill
for (String factionId : this.getFactionIds())
{
Faction faction = Faction.get(factionId);
if (faction == null) continue;
ret.add(faction);
}
// Return
return ret;
return MPerm.idsToMPermables(this.getGrantedIds());
}
// -------------------------------------------- //
// PRIVATE CONSTRUCTOR
// -------------------------------------------- //
private TerritoryAccess(String hostFactionId, Boolean hostFactionAllowed, Collection<String> factionIds, Collection<String> playerIds)
// Strictly for GSON only
private TerritoryAccess()
{
if (hostFactionId == null) throw new IllegalArgumentException("hostFactionId was null");
this.hostFactionId = null;
this.hostFactionAllowed = true;
this.grantedIds = null;
}
private TerritoryAccess(String hostFactionId, Boolean hostFactionAllowed, Collection<String> grantedIds)
{
if (hostFactionId == null) throw new NullPointerException("hostFactionId");
if (grantedIds == null) throw new NullPointerException("grantedIds");
this.hostFactionId = hostFactionId;
Set<String> factionIdsInner = new MassiveSet<>();
if (factionIds != null)
Set<String> grantedIdsInner = new MassiveSet<>();
grantedIdsInner.addAll(grantedIds);
if (grantedIdsInner.remove(hostFactionId))
{
factionIdsInner.addAll(factionIds);
if (factionIdsInner.remove(hostFactionId))
{
hostFactionAllowed = true;
}
hostFactionAllowed = true;
}
this.factionIds = Collections.unmodifiableSet(factionIdsInner);
Set<String> playerIdsInner = new MassiveSet<>();
if (playerIds != null)
{
for (String playerId : playerIds)
{
playerIdsInner.add(playerId.toLowerCase());
}
}
this.playerIds = Collections.unmodifiableSet(playerIdsInner);
this.grantedIds = Collections.unmodifiableSet(grantedIdsInner);
this.hostFactionAllowed = (hostFactionAllowed == null || hostFactionAllowed);
}
@ -155,45 +113,35 @@ public class TerritoryAccess
// FACTORY: VALUE OF
// -------------------------------------------- //
public static TerritoryAccess valueOf(String hostFactionId, Boolean hostFactionAllowed, Collection<String> factionIds, Collection<String> playerIds)
public static TerritoryAccess valueOf(String hostFactionId, Boolean hostFactionAllowed, Collection<String> grantedIds)
{
return new TerritoryAccess(hostFactionId, hostFactionAllowed, factionIds, playerIds);
return new TerritoryAccess(hostFactionId, hostFactionAllowed, grantedIds);
}
public static TerritoryAccess valueOf(String hostFactionId)
{
return valueOf(hostFactionId, null, null, null);
return valueOf(hostFactionId, null, Collections.emptySet());
}
// -------------------------------------------- //
// INSTANCE METHODS
// -------------------------------------------- //
public boolean isFactionGranted(Faction faction)
public boolean isGranted(MPermable permable)
{
String factionId = faction.getId();
if (this.getHostFactionId().equals(factionId))
{
return this.isHostFactionAllowed();
}
return this.getFactionIds().contains(factionId);
return isGranted(permable.getId());
}
// Note that the player can have access without being specifically granted.
// The player could for example be a member of a granted faction.
public boolean isMPlayerGranted(MPlayer mplayer)
public boolean isGranted(String permableId)
{
String mplayerId = mplayer.getId();
return this.getPlayerIds().contains(mplayerId);
return this.getGrantedIds().contains(permableId);
}
// A "default" TerritoryAccess could be serialized as a simple string only.
// The host faction is still allowed (default) and no faction or player has been granted explicit access (default).
public boolean isDefault()
{
return this.isHostFactionAllowed() && this.getFactionIds().isEmpty() && this.getPlayerIds().isEmpty();
return this.isHostFactionAllowed() && this.getGrantedIds().isEmpty();
}
// -------------------------------------------- //
@ -202,20 +150,14 @@ public class TerritoryAccess
public AccessStatus getTerritoryAccess(MPlayer mplayer)
{
if (this.isMPlayerGranted(mplayer)) return AccessStatus.ELEVATED;
if (isGranted(mplayer.getId())) return AccessStatus.ELEVATED;
if (isGranted(mplayer.getFaction().getId())) return AccessStatus.ELEVATED;
if (isGranted(mplayer.getRank().getId())) return AccessStatus.ELEVATED;
if (isGranted(RelationUtil.getRelationOfThatToMe(mplayer, this.getHostFaction()).toString())) return AccessStatus.ELEVATED;
String factionId = mplayer.getFaction().getId();
if (this.getFactionIds().contains(factionId)) return AccessStatus.ELEVATED;
if (this.getHostFactionId().equals(factionId) && !this.isHostFactionAllowed()) return AccessStatus.DECREASED;
if (this.getHostFactionId().equals(mplayer.getFaction().getId()) && !this.isHostFactionAllowed()) return AccessStatus.DECREASED;
return AccessStatus.STANDARD;
}
@Deprecated
public Boolean hasTerritoryAccess(MPlayer mplayer)
{
return this.getTerritoryAccess(mplayer).hasAccess();
}
}

View File

@ -11,6 +11,7 @@ import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.massivecore.store.migrator.MigratorUtil;
import java.lang.reflect.Type;
import java.util.Set;
@ -23,8 +24,9 @@ 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 FACTION_IDS = "factionIds";
public static final String PLAYER_IDS = "playerIds";
/*public static final String FACTION_IDS = "factionIds";
public static final String PLAYER_IDS = "playerIds";*/
public static final String GRANTED_IDS = "grantedIds";
public static final Type SET_OF_STRING_TYPE = new TypeToken<Set<String>>(){}.getType();
@ -55,8 +57,7 @@ public class TerritoryAccessAdapter implements JsonDeserializer<TerritoryAccess>
// Prepare variables
String hostFactionId = null;
Boolean hostFactionAllowed = null;
Set<String> factionIds = null;
Set<String> playerIds = null;
Set<String> grantedIds = null;
// Read variables (test old values first)
JsonElement element = null;
@ -69,15 +70,10 @@ public class TerritoryAccessAdapter implements JsonDeserializer<TerritoryAccess>
if (element == null) element = obj.get(HOST_FACTION_ALLOWED);
if (element != null) hostFactionAllowed = element.getAsBoolean();
element = obj.get("factions");
if (element == null) element = obj.get(FACTION_IDS);
if (element != null) factionIds = context.deserialize(element, SET_OF_STRING_TYPE);
element = obj.get(GRANTED_IDS);
if (element != null) grantedIds = context.deserialize(element, SET_OF_STRING_TYPE);
element = obj.get("fplayers");
if (element == null) element = obj.get(PLAYER_IDS);
if (element != null) playerIds = context.deserialize(element, SET_OF_STRING_TYPE);
return TerritoryAccess.valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds);
return TerritoryAccess.valueOf(hostFactionId, hostFactionAllowed, grantedIds);
}
@Override
@ -101,15 +97,12 @@ public class TerritoryAccessAdapter implements JsonDeserializer<TerritoryAccess>
obj.addProperty(HOST_FACTION_ALLOWED, src.isHostFactionAllowed());
}
if (!src.getFactionIds().isEmpty())
if (!src.getGrantedIds().isEmpty())
{
obj.add(FACTION_IDS, context.serialize(src.getFactionIds(), SET_OF_STRING_TYPE));
obj.add(GRANTED_IDS, context.serialize(src.getGrantedIds(), SET_OF_STRING_TYPE));
}
if (!src.getPlayerIds().isEmpty())
{
obj.add(PLAYER_IDS, context.serialize(src.getPlayerIds(), SET_OF_STRING_TYPE));
}
obj.add(MigratorUtil.VERSION_FIELD_NAME, new JsonPrimitive(src.version));
return obj;
}

View File

@ -59,8 +59,7 @@ public abstract class CmdFactionsAccessAbstract extends FactionsCommand
msg("<k>Host Faction: %s", hostFaction.describeTo(msender, true));
msg("<k>Host Faction Allowed: %s", ta.isHostFactionAllowed() ? Txt.parse("<lime>TRUE") : Txt.parse("<rose>FALSE"));
msg("<k>Granted Players: %s", describeRelationParticipators(ta.getGrantedMPlayers(), msender));
msg("<k>Granted Factions: %s", describeRelationParticipators(ta.getGrantedFactions(), msender));
msg("<k>Granted to: %s", CmdFactionsPermShow.permablesToDisplayString(ta.getGranteds(), msender));
}
public static String describeRelationParticipators(Collection<? extends RelationParticipator> relationParticipators, RelationParticipator observer)

View File

@ -29,13 +29,13 @@ public class CmdFactionsAccessFaction extends CmdFactionsAccessAbstract
{
// Args
Faction faction = this.readArg();
boolean newValue = this.readArg(!ta.isFactionGranted(faction));
boolean newValue = this.readArg(!ta.isGranted(faction));
// MPerm
if (!MPerm.getPermAccess().has(msender, hostFaction, true)) return;
// Apply
ta = ta.withFactionId(faction.getId(), newValue);
ta = ta.withGrantedId(faction.getId(), newValue);
BoardColl.get().setTerritoryAccessAt(chunk, ta);
// Inform

View File

@ -29,13 +29,13 @@ public class CmdFactionsAccessPlayer extends CmdFactionsAccessAbstract
{
// Args
MPlayer mplayer = this.readArg();
boolean newValue = this.readArg(!ta.isMPlayerGranted(mplayer));
boolean newValue = this.readArg(!ta.isGranted(mplayer));
// MPerm
if (!MPerm.getPermAccess().has(msender, hostFaction, true)) return;
// Apply
ta = ta.withPlayerId(mplayer.getId(), newValue);
ta = ta.withGrantedId(mplayer.getId(), newValue);
BoardColl.get().setTerritoryAccessAt(chunk, ta);
// Inform

View File

@ -7,6 +7,7 @@ import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.Invitation;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.MPlayerColl;
import com.massivecraft.massivecore.MassiveException;
@ -144,11 +145,11 @@ public class CmdFactionsClean extends FactionsCommand
TerritoryAccess territoryAccess = entry.getValue();
boolean changed = false;
for (String factionId : territoryAccess.getFactionIds())
for (String grantedIds : territoryAccess.getGrantedIds())
{
if (FactionColl.get().containsId(factionId)) continue;
if (MPerm.idToMPermableOptional(grantedIds).isPresent()) continue;
territoryAccess = territoryAccess.withFactionId(factionId, false);
territoryAccess = territoryAccess.withGrantedId(grantedIds, false);
ret += 1;
changed = true;
}

View File

@ -1,15 +1,11 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.factions.cmd.type.TypeMPerm;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPerm.MPermable;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.MPlayerColl;
import com.massivecraft.factions.entity.Rank;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.util.Txt;
@ -62,26 +58,10 @@ public class CmdFactionsPermShow extends FactionsCommand
msg("<i>In <reset>%s <i>permission <reset>%s <i>is granted to <reset>%s<i>.", faction.describeTo(msender), mperm.getDesc(true, false), permableNames);
}
@Deprecated
public static MPerm.MPermable idToMPermable(String id)
{
MPlayer mplayer = MPlayerColl.get().get(id, false);
if (mplayer != null) return mplayer;
Faction faction = Faction.get(id);
if (faction != null) return faction;
for (Faction f : FactionColl.get().getAll())
{
Rank rank = f.getRank(id);
if (rank != null) return rank;
}
if (Rel.ALLY.name().equalsIgnoreCase(id)) return Rel.ALLY;
if (Rel.TRUCE.name().equalsIgnoreCase(id)) return Rel.TRUCE;
if (Rel.NEUTRAL.name().equalsIgnoreCase(id)) return Rel.NEUTRAL;
if (Rel.ENEMY.name().equalsIgnoreCase(id)) return Rel.ENEMY;
throw new RuntimeException(id);
return MPerm.idToMPermable(id);
}
public static String permablesToDisplayString(Collection<MPermable> permables, Object watcherObject)

View File

@ -52,8 +52,6 @@ public class Board extends Entity<Board> implements BoardInterface
// FIELDS
// -------------------------------------------- //
// TODO: Make TerritoryAccess immutable.
private ConcurrentSkipListMap<PS, TerritoryAccess> map;
public Map<PS, TerritoryAccess> getMap() { return Collections.unmodifiableMap(this.map); }
public Map<PS, TerritoryAccess> getMapRaw() { return this.map; }

View File

@ -6,7 +6,6 @@ import com.massivecraft.factions.FactionsIndex;
import com.massivecraft.factions.FactionsParticipator;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.cmd.CmdFactionsPermShow;
import com.massivecraft.factions.entity.MPerm.MPermable;
import com.massivecraft.factions.predicate.PredicateCommandSenderFaction;
import com.massivecraft.factions.predicate.PredicateMPlayerRank;
@ -867,9 +866,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
public Set<MPermable> getPermittedPermables(String permId)
{
return getPermitted(permId).stream()
.map(CmdFactionsPermShow::idToMPermable)
.collect(Collectors.toSet());
return MPerm.idsToMPermables(getPermitted(permId));
}
public Set<MPermable> getPermittedPermables(MPerm mperm)
@ -882,6 +879,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
if (permableId == null) throw new NullPointerException("permableId");
if (permId == null) throw new NullPointerException("permId");
// TODO: Isn't this section redundant and just a copy of that from getPermitted?
Set<String> permables = this.perms.get(permId);
if (permables == null)
{

View File

@ -16,15 +16,19 @@ import com.massivecraft.massivecore.comparator.ComparatorSmart;
import com.massivecraft.massivecore.predicate.PredicateIsRegistered;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, Named
{
@ -414,7 +418,7 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
}
// -------------------------------------------- //
// UTIL: ASCII
// PERMABLES
// -------------------------------------------- //
public static List<MPermable> getPermables(Faction faction)
@ -431,60 +435,6 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
return list;
}
/*public static String getStateHeaders(Faction faction)
{
if (faction == null) throw new NullPointerException("faction");
String ret = "";
for (MPermable permable : getPermables(faction))
{
ret += permable.getColor().toString();
ret += permable.getShortName().toUpperCase();
ret += " ";
}
return ret;
}
public String getStateInfo(Faction faction, boolean withDesc)
{
if (faction == null) throw new NullPointerException("faction");
String ret = "";
for (MPermable permable : getPermables(faction))
{
if (faction.isPermablePermitted(permable, this))
{
ret += "<g>YES";
}
else
{
ret += "<b>NOO";
}
ret += " ";
}
String color = "<aqua>";
if (!this.isVisible())
{
color = "<silver>";
}
else if (this.isEditable())
{
color = "<pink>";
}
ret += color;
ret += this.getName();
ret = Txt.parse(ret);
if (withDesc) ret += " <i>" + this.getDesc();
return ret;
}*/
public interface MPermable extends Named, Identified
{
default boolean isRelation()
@ -505,4 +455,42 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
String getDisplayName(Object senderObject);
}
public static Set<MPermable> idsToMPermables(Collection<String> ids)
{
return ids.stream()
.map(MPerm::idToMPermable)
.collect(Collectors.toSet());
}
public static MPermable idToMPermable(String id)
{
return idToMPermableOptional(id).orElseThrow(() -> new RuntimeException(id));
}
public static Optional<MPermable> idToMPermableOptional(String id)
{
MPlayer mplayer = MPlayerColl.get().get(id, false);
if (mplayer != null) return Optional.of(mplayer);
// Workaround for registered senders
// Players ussually have a power, which makes sure they are in the coll
if (IdUtil.getRegistryIdToSender().containsKey(id)) return Optional.of(MPlayerColl.get().get(id, true));
Faction faction = Faction.get(id);
if (faction != null) return Optional.of(faction);
for (Faction f : FactionColl.get().getAll())
{
Rank rank = f.getRank(id);
if (rank != null) return Optional.of(rank);
}
if (Rel.ALLY.name().equalsIgnoreCase(id)) return Optional.of(Rel.ALLY);
if (Rel.TRUCE.name().equalsIgnoreCase(id)) return Optional.of(Rel.TRUCE);
if (Rel.NEUTRAL.name().equalsIgnoreCase(id)) return Optional.of(Rel.NEUTRAL);
if (Rel.ENEMY.name().equalsIgnoreCase(id)) return Optional.of(Rel.ENEMY);
return Optional.empty();
}
}

View File

@ -0,0 +1,50 @@
package com.massivecraft.factions.entity.migrator;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.adapter.TerritoryAccessAdapter;
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
public class MigratorTerritoryAccess001Restructure extends MigratorRoot
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static MigratorTerritoryAccess001Restructure i = new MigratorTerritoryAccess001Restructure();
public static MigratorTerritoryAccess001Restructure get() { return i; }
private MigratorTerritoryAccess001Restructure()
{
super(TerritoryAccess.class);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void migrateInner(JsonObject entity)
{
JsonElement factionIds = entity.remove("factionIds");
JsonElement playerIds = entity.remove("playerIds");
JsonArray grantedIds = new JsonArray();
if (factionIds != null && factionIds.isJsonArray())
{
JsonArray factionIdsArr = factionIds.getAsJsonArray();
grantedIds.addAll(factionIdsArr);
}
if (playerIds != null && playerIds.isJsonArray())
{
JsonArray playerIdsArr = playerIds.getAsJsonArray();
grantedIds.addAll(playerIdsArr);
}
if (grantedIds.size() > 0) entity.add(TerritoryAccessAdapter.GRANTED_IDS, grantedIds);
}
}