Fix an updater bug, remove the aspect and readd EngineIdUpdate.
This commit is contained in:
parent
d35fb013d6
commit
f0189c0f8f
110
src/main/java/com/massivecraft/factions/EngineIdUpdate.java
Normal file
110
src/main/java/com/massivecraft/factions/EngineIdUpdate.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
@ -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(
|
||||
"<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
|
||||
// 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.
|
||||
|
@ -458,7 +458,7 @@ public class MPlayer extends SenderEntity<MPlayer> 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<MPlayer> 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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user