From f0189c0f8fbabe1ad60839bcb98c104c39c8b0a0 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 17 Sep 2014 16:15:33 +0200 Subject: [PATCH] Fix an updater bug, remove the aspect and readd EngineIdUpdate. --- .../massivecraft/factions/EngineIdUpdate.java | 110 ++++++++++++++++++ .../com/massivecraft/factions/Factions.java | 21 +--- .../massivecraft/factions/entity/MPlayer.java | 4 +- .../factions/update/UpdateUtil.java | 10 +- 4 files changed, 120 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/EngineIdUpdate.java diff --git a/src/main/java/com/massivecraft/factions/EngineIdUpdate.java b/src/main/java/com/massivecraft/factions/EngineIdUpdate.java new file mode 100644 index 00000000..154dca8d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/EngineIdUpdate.java @@ -0,0 +1,110 @@ +package com.massivecraft.factions; + +import java.util.Set; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.plugin.Plugin; + +import com.massivecraft.factions.entity.Board; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.massivecore.EngineAbstract; +import com.massivecraft.massivecore.event.EventMassiveCoreUuidUpdate; +import com.massivecraft.massivecore.util.IdUpdateUtil; +import com.massivecraft.massivecore.util.MUtil; + +public class EngineIdUpdate extends EngineAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineIdUpdate i = new EngineIdUpdate(); + public static EngineIdUpdate get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Plugin getPlugin() + { + return Factions.get(); + } + + // -------------------------------------------- // + // LISTENER + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR) + public void update(EventMassiveCoreUuidUpdate event) + { + for (Faction entity : FactionColl.get().getAll()) + { + update(entity); + } + + IdUpdateUtil.update(MPlayerColl.get()); + + update(BoardColl.get()); + } + + public static void update(Faction entity) + { + // Before and After + Set before = entity.getInvitedPlayerIds(); + if (before == null) return; + Set after = IdUpdateUtil.update(before, true); + if (after == null) return; + + // NoChange + if (MUtil.equals(before, after)) return; + + // Apply + entity.setInvitedPlayerIds(after); + entity.sync(); + } + + public static void update(BoardColl coll) + { + for (Board board : coll.getAll()) + { + update(board); + } + } + + public static void update(Board board) + { + boolean changed = false; + for (TerritoryAccess ta : board.getMap().values()) + { + changed |= update(ta); + } + if (changed) + { + board.changed(); + board.sync(); + } + } + + public static boolean update(TerritoryAccess entity) + { + // Before and After + Set before = entity.playerIds; + if (before == null) return false; + Set after = IdUpdateUtil.update(before, true); + if (after == null) return false; + + // NoChange + if (MUtil.equals(before, after)) return false; + + // Apply + entity.playerIds = after; + //entity.sync(); + return true; + } + +} diff --git a/src/main/java/com/massivecraft/factions/Factions.java b/src/main/java/com/massivecraft/factions/Factions.java index e01952f8..045de41f 100644 --- a/src/main/java/com/massivecraft/factions/Factions.java +++ b/src/main/java/com/massivecraft/factions/Factions.java @@ -77,12 +77,6 @@ public class Factions extends MassivePlugin private CmdFactions outerCmdFactions; 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(); } - // Database Initialized private boolean databaseInitialized; public boolean isDatabaseInitialized() { return this.databaseInitialized; } @@ -94,28 +88,16 @@ public class Factions extends MassivePlugin // Gson without preprocessors public final Gson gsonWithoutPreprocessors = this.getGsonBuilderWithoutPreprocessors().create(); - // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // - - - @Override public void onEnable() { if ( ! preEnable()) return; - // Initialize Aspects - this.aspect = AspectColl.get().get(Const.ASPECT, true); - this.aspect.register(); - this.aspect.setDesc( - "If the factions system even is enabled and how it's configured.", - "What factions exists and what players belong to them." - ); - // Register Faction accountId Extractor // TODO: Perhaps this should be placed in the econ integration somewhere? MUtil.registerExtractor(String.class, "accountId", ExtractorFactionAccountId.get()); @@ -123,7 +105,7 @@ public class Factions extends MassivePlugin // Initialize Database this.databaseInitialized = false; MConfColl.get().init(); - UpdateUtil.update(); + UpdateUtil.update(); MPlayerColl.get().init(); FactionColl.get().init(); BoardColl.get().init(); @@ -138,6 +120,7 @@ public class Factions extends MassivePlugin FactionsListenerMain.get().setup(); FactionsListenerChat.get().setup(); FactionsListenerExploit.get().setup(); + EngineIdUpdate.get().activate(); // TODO: This listener is a work in progress. // The goal is that the Econ integration should be completely based on listening to our own events. diff --git a/src/main/java/com/massivecraft/factions/entity/MPlayer.java b/src/main/java/com/massivecraft/factions/entity/MPlayer.java index fb483891..0b652e21 100644 --- a/src/main/java/com/massivecraft/factions/entity/MPlayer.java +++ b/src/main/java/com/massivecraft/factions/entity/MPlayer.java @@ -458,7 +458,7 @@ public class MPlayer extends SenderEntity implements EconomyParticipato { // Clean input Boolean target = mapAutoUpdating; - if (target == false) target = null; + if (MUtil.equals(target, false)) target = null; // Detect Nochange if (MUtil.equals(this.mapAutoUpdating, target)) return; @@ -492,7 +492,7 @@ public class MPlayer extends SenderEntity implements EconomyParticipato { // Clean input Boolean target = usingAdminMode; - if (target == false) target = null; + if (MUtil.equals(target, false)) target = null; // Detect Nochange if (MUtil.equals(this.usingAdminMode, target)) return; diff --git a/src/main/java/com/massivecraft/factions/update/UpdateUtil.java b/src/main/java/com/massivecraft/factions/update/UpdateUtil.java index b7e48685..3ebd6467 100644 --- a/src/main/java/com/massivecraft/factions/update/UpdateUtil.java +++ b/src/main/java/com/massivecraft/factions/update/UpdateUtil.java @@ -37,6 +37,8 @@ public class UpdateUtil String universe = getUniverse(); if (universe == null) return; + Factions.get().log("Updating Database to New Version!"); + // ... load the old uconf data ... OldConfColls.get().init(); OldConf oldConf = OldConfColls.get().getForUniverse(universe).get(MassiveCore.INSTANCE, true); @@ -47,6 +49,10 @@ public class UpdateUtil // ... rename target collections ... Db db = MStore.getDb(); + // The old mplayer data we don't care much for. + // Could even delete it but let's just move it out of the way. + db.getDriver().renameColl(db, Const.COLLECTION_MPLAYER, "old_"+Const.COLLECTION_MPLAYER); + 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); @@ -112,8 +118,4 @@ public class UpdateUtil return ret; } - - - - }