diff --git a/src/main/java/com/massivecraft/factions/Factions.java b/src/main/java/com/massivecraft/factions/Factions.java index 27738f46..e01952f8 100644 --- a/src/main/java/com/massivecraft/factions/Factions.java +++ b/src/main/java/com/massivecraft/factions/Factions.java @@ -40,10 +40,14 @@ import com.massivecraft.factions.mixin.PowerMixinDefault; import com.massivecraft.factions.task.TaskPlayerDataRemove; import com.massivecraft.factions.task.TaskEconLandReward; import com.massivecraft.factions.task.TaskPlayerPowerUpdate; +import com.massivecraft.factions.update.OldConfColls; +import com.massivecraft.factions.update.UpdateUtil; import com.massivecraft.massivecore.Aspect; import com.massivecraft.massivecore.AspectColl; import com.massivecraft.massivecore.MassivePlugin; import com.massivecraft.massivecore.Multiverse; +import com.massivecraft.massivecore.store.Coll; +import com.massivecraft.massivecore.store.MStore; import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.xlib.gson.Gson; import com.massivecraft.massivecore.xlib.gson.GsonBuilder; @@ -74,6 +78,7 @@ public class Factions extends MassivePlugin public CmdFactions getOuterCmdFactions() { return this.outerCmdFactions; } // Aspects + // TODO: Remove this. It's used for the update procedure only. private Aspect aspect; public Aspect getAspect() { return this.aspect; } public Multiverse getMultiverse() { return this.getAspect().getMultiverse(); } @@ -90,10 +95,14 @@ public class Factions extends MassivePlugin // Gson without preprocessors public final Gson gsonWithoutPreprocessors = this.getGsonBuilderWithoutPreprocessors().create(); + // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // + + + @Override public void onEnable() { @@ -114,6 +123,7 @@ public class Factions extends MassivePlugin // Initialize Database this.databaseInitialized = false; MConfColl.get().init(); + UpdateUtil.update(); MPlayerColl.get().init(); FactionColl.get().init(); BoardColl.get().init(); diff --git a/src/main/java/com/massivecraft/factions/entity/old/OldConf.java b/src/main/java/com/massivecraft/factions/update/OldConf.java similarity index 56% rename from src/main/java/com/massivecraft/factions/entity/old/OldConf.java rename to src/main/java/com/massivecraft/factions/update/OldConf.java index d28f74b3..5adb1f0b 100644 --- a/src/main/java/com/massivecraft/factions/entity/old/OldConf.java +++ b/src/main/java/com/massivecraft/factions/update/OldConf.java @@ -1,4 +1,4 @@ -package com.massivecraft.factions.entity.old; +package com.massivecraft.factions.update; import java.util.List; import java.util.Map; @@ -9,11 +9,83 @@ import org.bukkit.event.EventPriority; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.event.EventFactionsChunkChangeType; import com.massivecraft.massivecore.store.Entity; public class OldConf extends Entity { + // -------------------------------------------- // + // META + // -------------------------------------------- // + + public void transferTo(MConf mconf) + { + //mconf.enabled = this.enabled; + mconf.factionIdNone = this.factionIdNone; + mconf.factionIdSafezone = this.factionIdSafezone; + mconf.factionIdWarzone = this.factionIdWarzone; + mconf.defaultPlayerFactionId = this.defaultPlayerFactionId; + mconf.defaultPlayerRole = this.defaultPlayerRole; + mconf.defaultPlayerPower = this.defaultPlayerPower; + mconf.defaultFactionOpen = this.defaultFactionOpen; + mconf.defaultFactionFlags = this.defaultFactionFlags; + mconf.defaultFactionPerms = this.defaultFactionPerms; + mconf.broadcastNameChange = this.broadcastNameChange; + mconf.powerMax = this.powerMax; + mconf.powerMin = this.powerMin; + mconf.powerPerHour = this.powerPerHour; + mconf.powerPerDeath = this.powerPerDeath; + mconf.canLeaveWithNegativePower = this.canLeaveWithNegativePower; + mconf.factionMemberLimit = this.factionMemberLimit; + mconf.factionPowerMax = this.factionPowerMax; + mconf.factionNameLengthMin = this.factionNameLengthMin; + mconf.factionNameLengthMax = this.factionNameLengthMax; + mconf.factionNameForceUpperCase = this.factionNameForceUpperCase; + mconf.claimsMustBeConnected = this.claimsMustBeConnected; + mconf.claimingFromOthersAllowed = this.claimingFromOthersAllowed; + mconf.claimsCanBeUnconnectedIfOwnedByOtherFaction = this.claimsCanBeUnconnectedIfOwnedByOtherFaction; + mconf.claimsRequireMinFactionMembers = this.claimsRequireMinFactionMembers; + mconf.claimedLandsMax = this.claimedLandsMax; + mconf.homesEnabled = this.homesEnabled; + mconf.homesMustBeInClaimedTerritory = this.homesMustBeInClaimedTerritory; + mconf.homesTeleportCommandEnabled = this.homesTeleportCommandEnabled; + mconf.homesTeleportAllowedFromEnemyTerritory = this.homesTeleportAllowedFromEnemyTerritory; + mconf.homesTeleportAllowedFromDifferentWorld = this.homesTeleportAllowedFromDifferentWorld; + mconf.homesTeleportAllowedEnemyDistance = this.homesTeleportAllowedEnemyDistance; + mconf.homesTeleportIgnoreEnemiesIfInOwnTerritory = this.homesTeleportIgnoreEnemiesIfInOwnTerritory; + mconf.homesTeleportToOnDeathActive = this.homesTeleportToOnDeathActive; + mconf.homesTeleportToOnDeathPriority = this.homesTeleportToOnDeathPriority; + mconf.permanentFactionsDisableLeaderPromotion = this.permanentFactionsDisableLeaderPromotion; + mconf.actionDeniedPainAmount = this.actionDeniedPainAmount; + mconf.disablePVPForFactionlessPlayers = this.disablePVPForFactionlessPlayers; + mconf.enablePVPAgainstFactionlessInAttackersLand = this.enablePVPAgainstFactionlessInAttackersLand; + mconf.territoryShieldFactor = this.territoryShieldFactor; + mconf.denyCommandsPermanentFactionMember = this.denyCommandsPermanentFactionMember; + mconf.denyCommandsTerritoryRelation = this.denyCommandsTerritoryRelation; + mconf.lwcRemoveOnChange = this.lwcRemoveOnChange; + mconf.econEnabled = this.econEnabled; + mconf.econLandReward = this.econLandReward; + mconf.econUniverseAccount = this.econUniverseAccount; + mconf.econChunkCost = this.econChunkCost; + mconf.econCostCreate = this.econCostCreate; + mconf.econCostSethome = this.econCostSethome; + mconf.econCostJoin = this.econCostJoin; + mconf.econCostLeave = this.econCostLeave; + mconf.econCostKick = this.econCostKick; + mconf.econCostInvite = this.econCostInvite; + mconf.econCostDeinvite = this.econCostDeinvite; + mconf.econCostHome = this.econCostHome; + mconf.econCostName = this.econCostName; + mconf.econCostDescription = this.econCostDescription; + mconf.econCostTitle = this.econCostTitle; + mconf.econCostOpen = this.econCostOpen; + mconf.econRelCost = this.econRelCost; + mconf.bankEnabled = this.bankEnabled; + mconf.bankFactionPaysCosts = this.bankFactionPaysCosts; + mconf.bankFactionPaysLandCosts = this.bankFactionPaysLandCosts; + } + // -------------------------------------------- // // UNIVERSE ENABLE SWITCH // -------------------------------------------- // diff --git a/src/main/java/com/massivecraft/factions/entity/old/OldConfColl.java b/src/main/java/com/massivecraft/factions/update/OldConfColl.java similarity index 89% rename from src/main/java/com/massivecraft/factions/entity/old/OldConfColl.java rename to src/main/java/com/massivecraft/factions/update/OldConfColl.java index cc439503..e71a70ba 100644 --- a/src/main/java/com/massivecraft/factions/entity/old/OldConfColl.java +++ b/src/main/java/com/massivecraft/factions/update/OldConfColl.java @@ -1,4 +1,4 @@ -package com.massivecraft.factions.entity.old; +package com.massivecraft.factions.update; import com.massivecraft.factions.Factions; import com.massivecraft.massivecore.MassiveCore; diff --git a/src/main/java/com/massivecraft/factions/entity/old/OldConfColls.java b/src/main/java/com/massivecraft/factions/update/OldConfColls.java similarity index 91% rename from src/main/java/com/massivecraft/factions/entity/old/OldConfColls.java rename to src/main/java/com/massivecraft/factions/update/OldConfColls.java index 061c95ab..00b2ff37 100644 --- a/src/main/java/com/massivecraft/factions/entity/old/OldConfColls.java +++ b/src/main/java/com/massivecraft/factions/update/OldConfColls.java @@ -1,4 +1,4 @@ -package com.massivecraft.factions.entity.old; +package com.massivecraft.factions.update; import com.massivecraft.factions.Factions; import com.massivecraft.massivecore.Aspect; diff --git a/src/main/java/com/massivecraft/factions/update/UpdateUtil.java b/src/main/java/com/massivecraft/factions/update/UpdateUtil.java new file mode 100644 index 00000000..b7e48685 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/update/UpdateUtil.java @@ -0,0 +1,119 @@ +package com.massivecraft.factions.update; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import com.massivecraft.factions.Const; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.MassiveCore; +import com.massivecraft.massivecore.store.Coll; +import com.massivecraft.massivecore.store.Db; +import com.massivecraft.massivecore.store.MStore; +import com.massivecraft.massivecore.util.MUtil; + +public class UpdateUtil +{ + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public static final List oldCollnamePrefixes = MUtil.list( + "factions_board@", + "factions_faction@", + "factions_uplayer@", + "factions_uconf@" + ); + + // -------------------------------------------- // + // UPDATE + // -------------------------------------------- // + // Assumes the MConfColl has been inited! + + public static void update() + { + // Select the old universe of our attention ... + String universe = getUniverse(); + if (universe == null) return; + + // ... load the old uconf data ... + OldConfColls.get().init(); + OldConf oldConf = OldConfColls.get().getForUniverse(universe).get(MassiveCore.INSTANCE, true); + + // ... transfer the old uconf data over to the new mconf ... + oldConf.transferTo(MConf.get()); + + // ... rename target collections ... + Db db = MStore.getDb(); + + db.getDriver().renameColl(db, "factions_board@" + universe, Const.COLLECTION_BOARD); + db.getDriver().renameColl(db, "factions_faction@" + universe, Const.COLLECTION_FACTION); + db.getDriver().renameColl(db, "factions_uplayer@" + universe, Const.COLLECTION_MPLAYER); + + // ... rename remaining collections ... + for (String collname : db.getCollnames()) + { + if (!collname.startsWith("factions_")) continue; + if (!collname.contains("@")) continue; + db.getDriver().renameColl(db, collname, "old_" + collname); + } + + } + + // -------------------------------------------- // + // UNIVERSE SELECTION + // -------------------------------------------- // + + public static String getUniverse() + { + List universes = getUniverses(); + + String ret = null; + int best = -1; + + for (String universe : universes) + { + int count = getUniverseFactionCount(universe); + if (count > 0 && count > best) + { + ret = universe; + best = count; + } + } + + return ret; + } + + public static int getUniverseFactionCount(String universe) + { + Coll coll = new Coll("factions_faction@"+universe, Object.class, MStore.getDb(), Factions.get()); + + Collection ids = MStore.getDb().getDriver().getIds(coll); + + return ids.size(); + } + + public static List getUniverses() + { + List ret = new ArrayList(); + + for (String collname : MStore.getDb().getCollnames()) + { + for (String prefix : oldCollnamePrefixes) + { + if (collname.startsWith(prefix)) + { + ret.add(collname.substring(prefix.length())); + } + } + } + + return ret; + } + + + + + +}