Fix an updater bug, remove the aspect and readd EngineIdUpdate.

This commit is contained in:
Olof Larsson 2014-09-17 16:15:33 +02:00
parent d35fb013d6
commit f0189c0f8f
4 changed files with 120 additions and 25 deletions

View File

@ -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<String> before = entity.getInvitedPlayerIds();
if (before == null) return;
Set<String> 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<String> before = entity.playerIds;
if (before == null) return false;
Set<String> 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;
}
}

View File

@ -77,12 +77,6 @@ public class Factions extends MassivePlugin
private CmdFactions outerCmdFactions; private CmdFactions outerCmdFactions;
public CmdFactions getOuterCmdFactions() { return this.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 // Database Initialized
private boolean databaseInitialized; private boolean databaseInitialized;
public boolean isDatabaseInitialized() { return this.databaseInitialized; } public boolean isDatabaseInitialized() { return this.databaseInitialized; }
@ -95,27 +89,15 @@ public class Factions extends MassivePlugin
// Gson without preprocessors // Gson without preprocessors
public final Gson gsonWithoutPreprocessors = this.getGsonBuilderWithoutPreprocessors().create(); public final Gson gsonWithoutPreprocessors = this.getGsonBuilderWithoutPreprocessors().create();
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void onEnable() public void onEnable()
{ {
if ( ! preEnable()) return; if ( ! preEnable()) return;
// Initialize Aspects
this.aspect = AspectColl.get().get(Const.ASPECT, true);
this.aspect.register();
this.aspect.setDesc(
"<i>If the factions system even is enabled and how it's configured.",
"<i>What factions exists and what players belong to them."
);
// Register Faction accountId Extractor // Register Faction accountId Extractor
// TODO: Perhaps this should be placed in the econ integration somewhere? // TODO: Perhaps this should be placed in the econ integration somewhere?
MUtil.registerExtractor(String.class, "accountId", ExtractorFactionAccountId.get()); MUtil.registerExtractor(String.class, "accountId", ExtractorFactionAccountId.get());
@ -138,6 +120,7 @@ public class Factions extends MassivePlugin
FactionsListenerMain.get().setup(); FactionsListenerMain.get().setup();
FactionsListenerChat.get().setup(); FactionsListenerChat.get().setup();
FactionsListenerExploit.get().setup(); FactionsListenerExploit.get().setup();
EngineIdUpdate.get().activate();
// TODO: This listener is a work in progress. // 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. // The goal is that the Econ integration should be completely based on listening to our own events.

View File

@ -458,7 +458,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
{ {
// Clean input // Clean input
Boolean target = mapAutoUpdating; Boolean target = mapAutoUpdating;
if (target == false) target = null; if (MUtil.equals(target, false)) target = null;
// Detect Nochange // Detect Nochange
if (MUtil.equals(this.mapAutoUpdating, target)) return; if (MUtil.equals(this.mapAutoUpdating, target)) return;
@ -492,7 +492,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
{ {
// Clean input // Clean input
Boolean target = usingAdminMode; Boolean target = usingAdminMode;
if (target == false) target = null; if (MUtil.equals(target, false)) target = null;
// Detect Nochange // Detect Nochange
if (MUtil.equals(this.usingAdminMode, target)) return; if (MUtil.equals(this.usingAdminMode, target)) return;

View File

@ -37,6 +37,8 @@ public class UpdateUtil
String universe = getUniverse(); String universe = getUniverse();
if (universe == null) return; if (universe == null) return;
Factions.get().log("Updating Database to New Version!");
// ... load the old uconf data ... // ... load the old uconf data ...
OldConfColls.get().init(); OldConfColls.get().init();
OldConf oldConf = OldConfColls.get().getForUniverse(universe).get(MassiveCore.INSTANCE, true); OldConf oldConf = OldConfColls.get().getForUniverse(universe).get(MassiveCore.INSTANCE, true);
@ -47,6 +49,10 @@ public class UpdateUtil
// ... rename target collections ... // ... rename target collections ...
Db db = MStore.getDb(); 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_board@" + universe, Const.COLLECTION_BOARD);
db.getDriver().renameColl(db, "factions_faction@" + universe, Const.COLLECTION_FACTION); db.getDriver().renameColl(db, "factions_faction@" + universe, Const.COLLECTION_FACTION);
db.getDriver().renameColl(db, "factions_uplayer@" + universe, Const.COLLECTION_MPLAYER); db.getDriver().renameColl(db, "factions_uplayer@" + universe, Const.COLLECTION_MPLAYER);
@ -112,8 +118,4 @@ public class UpdateUtil
return ret; return ret;
} }
} }