From c38181e5e9f4edd3860fec5016fe9836e963c94b Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Tue, 5 Mar 2019 17:14:02 +0100 Subject: [PATCH] Convert factions properly --- src/com/massivecraft/factions/Factions.java | 2 + .../massivecraft/factions/entity/Faction.java | 2 +- .../massivecraft/factions/entity/Rank.java | 6 +-- .../MigratorFaction004WarpsPerms.java | 40 +++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/com/massivecraft/factions/entity/migrator/MigratorFaction004WarpsPerms.java diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 2e3c1b9b..3ddf29e9 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -55,6 +55,7 @@ import com.massivecraft.factions.entity.MPlayerColl; import com.massivecraft.factions.entity.migrator.MigratorFaction001Invitations; import com.massivecraft.factions.entity.migrator.MigratorFaction002Ranks; import com.massivecraft.factions.entity.migrator.MigratorFaction003Warps; +import com.massivecraft.factions.entity.migrator.MigratorFaction004WarpsPerms; import com.massivecraft.factions.entity.migrator.MigratorMConf001EnumerationUtil; import com.massivecraft.factions.entity.migrator.MigratorMConf002CleanInactivity; import com.massivecraft.factions.entity.migrator.MigratorMConf003CleanInactivity; @@ -145,6 +146,7 @@ public class Factions extends MassivePlugin MigratorFaction001Invitations.class, MigratorFaction002Ranks.class, MigratorFaction003Warps.class, + MigratorFaction004WarpsPerms.class, MigratorMConf001EnumerationUtil.class, MigratorMConf002CleanInactivity.class, MigratorMConf003CleanInactivity.class, diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 695d98c5..55652f79 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -102,7 +102,7 @@ public class Faction extends Entity implements FactionsParticipator, MP // VERSION // -------------------------------------------- // - public int version = 3; + public int version = 4; // -------------------------------------------- // // FIELDS: RAW diff --git a/src/com/massivecraft/factions/entity/Rank.java b/src/com/massivecraft/factions/entity/Rank.java index 67679395..db6695fe 100644 --- a/src/com/massivecraft/factions/entity/Rank.java +++ b/src/com/massivecraft/factions/entity/Rank.java @@ -3,9 +3,9 @@ package com.massivecraft.factions.entity; import com.massivecraft.massivecore.store.EntityInternal; import com.massivecraft.massivecore.store.EntityInternalMap; import com.massivecraft.massivecore.util.Txt; +import org.apache.commons.lang.ObjectUtils.Null; import org.bukkit.ChatColor; -import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; @@ -28,10 +28,10 @@ public class Rank extends EntityInternal implements MPerm.MPermable { for (Faction f : FactionColl.get().getAll()) { - for (Iterator>> it = f.getPerms().entrySet().iterator(); it.hasNext();) + for (Entry> entry : f.getPerms().entrySet()) { - Entry> entry = it.next(); Set value = entry.getValue(); + if (value == null) throw new NullPointerException(entry.getKey()); value.remove(id); } } diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorFaction004WarpsPerms.java b/src/com/massivecraft/factions/entity/migrator/MigratorFaction004WarpsPerms.java new file mode 100644 index 00000000..22c28b98 --- /dev/null +++ b/src/com/massivecraft/factions/entity/migrator/MigratorFaction004WarpsPerms.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.entity.migrator; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +public class MigratorFaction004WarpsPerms extends MigratorRoot +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorFaction004WarpsPerms i = new MigratorFaction004WarpsPerms(); + public static MigratorFaction004WarpsPerms get() { return i; } + private MigratorFaction004WarpsPerms() + { + super(Faction.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void migrateInner(JsonObject entity) + { + JsonElement perms = entity.get("perms"); + if (perms == null || perms.isJsonNull() || !perms.isJsonObject()) return; + + JsonObject permsO = perms.getAsJsonObject(); + + JsonElement home = permsO.remove("home"); + if (home != null) permsO.add("warp", home); + + JsonElement sethome = permsO.remove("sethome"); + if (home != null) permsO.add("setwarp", home); + } + +}