Minor startup fixes

This commit is contained in:
Olof Larsson 2013-04-22 15:05:00 +02:00
parent 390ad76fa6
commit 26fa7e8b95
10 changed files with 72 additions and 11 deletions

View File

@ -71,6 +71,10 @@ public class Factions extends MPlugin
public Aspect getAspect() { return this.aspect; }
public Multiverse getMultiverse() { return this.getAspect().getMultiverse(); }
// Database Initialized
private boolean databaseInitialized;
public boolean isDatabaseInitialized() { return this.databaseInitialized; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@ -96,11 +100,17 @@ public class Factions extends MPlugin
MUtil.registerExtractor(String.class, "accountId", ExtractorFactionAccountId.get());
// Initialize Collections
this.databaseInitialized = false;
MConfColl.get().init();
FPlayerColls.get().init();
FactionColls.get().init();
BoardColls.get().init();
FactionColls.get().reindexFPlayers();
this.databaseInitialized = true;
// Commands
this.outerCmdFactions = new CmdFactions();
this.outerCmdFactions.register(this);

View File

@ -6,6 +6,8 @@ import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.RelationParticipator;
@ -18,6 +20,7 @@ import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.usys.Aspect;
import com.massivecraft.mcore.util.DiscUtil;
import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.SenderUtil;
import com.massivecraft.mcore.xlib.gson.reflect.TypeToken;
public class BoardColls extends Colls<BoardColl, Board> implements BoardInterface
@ -66,6 +69,11 @@ public class BoardColls extends Colls<BoardColl, Board> implements BoardInterfac
return this.getForUniverse(((Coll<?>)o).getUniverse());
}
if (SenderUtil.isNonplayer(o))
{
return this.getForWorld(Bukkit.getWorlds().get(0).getName());
}
String worldName = MUtil.extract(String.class, "worldName", o);
if (worldName == null) return null;
return this.getForWorld(worldName);

View File

@ -231,7 +231,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
// Next we must be attached and inited
if (!this.attached()) return;
if (!this.getColl().inited()) return;
if (!FactionColls.get().get(this).inited()) return;
if (!Factions.get().isDatabaseInitialized()) return;
// Spout Derp
SpoutFeatures.updateTitle(this, null);

View File

@ -30,7 +30,7 @@ public class FPlayerColl extends SenderColl<FPlayer>
// If inited ...
if (!this.inited()) return ret;
if (!FactionColls.get().getForUniverse(this.getUniverse()).inited()) return ret;
if (!Factions.get().isDatabaseInitialized()) return ret;
// ... update the index.
Faction faction = entity.getFaction();

View File

@ -5,6 +5,8 @@ import java.lang.reflect.Type;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
import com.massivecraft.mcore.MCore;
@ -14,6 +16,7 @@ import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.usys.Aspect;
import com.massivecraft.mcore.util.DiscUtil;
import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.SenderUtil;
import com.massivecraft.mcore.xlib.gson.reflect.TypeToken;
public class FPlayerColls extends Colls<FPlayerColl, FPlayer>
@ -62,6 +65,11 @@ public class FPlayerColls extends Colls<FPlayerColl, FPlayer>
return this.getForUniverse(((Coll<?>)o).getUniverse());
}
if (SenderUtil.isNonplayer(o))
{
return this.getForWorld(Bukkit.getWorlds().get(0).getName());
}
String worldName = MUtil.extract(String.class, "worldName", o);
if (worldName == null) return null;
return this.getForWorld(worldName);
@ -88,12 +96,15 @@ public class FPlayerColls extends Colls<FPlayerColl, FPlayer>
Type type = new TypeToken<Map<String, FPlayer>>(){}.getType();
Map<String, FPlayer> id2fplayer = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type);
// The Coll
FPlayerColl coll = this.getForUniverse(MCore.DEFAULT);
// Set the data
for (Entry<String, FPlayer> entry : id2fplayer.entrySet())
{
String playerId = entry.getKey();
FPlayer fplayer = entry.getValue();
FPlayerColls.get().getForUniverse(MCore.DEFAULT).create(playerId).load(fplayer);
coll.attach(fplayer, playerId);
}
// Mark as migrated

View File

@ -39,9 +39,9 @@ public class FactionColl extends Coll<Faction>
super.init();
this.createDefaultFactions();
this.reindexFPlayers();
}
/*
@Override
protected synchronized String attach(Faction faction, Object oid, boolean noteChange)
{
@ -51,13 +51,18 @@ public class FactionColl extends Coll<Faction>
// TODO: Can this be done here?
// TODO: Or will it be a to heavy operation to do this often?
//System.out.println("faction "+faction);
//System.out.println("faction.getId() "+faction.getId());
// TODO: Why does this happen for Wilderness?
if (faction.getId() == null) return ret;
if (!Money.exists(faction))
{
Money.set(faction, 0);
}
return ret;
}
}*/
@Override
public Faction detachId(Object oid)
@ -77,6 +82,10 @@ public class FactionColl extends Coll<Faction>
return ret;
}
// -------------------------------------------- //
// INDEX
// -------------------------------------------- //
public void reindexFPlayers()
{
for (Faction faction : this.getAll())

View File

@ -5,6 +5,8 @@ import java.lang.reflect.Type;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
import com.massivecraft.mcore.MCore;
@ -14,6 +16,7 @@ import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.usys.Aspect;
import com.massivecraft.mcore.util.DiscUtil;
import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.SenderUtil;
import com.massivecraft.mcore.xlib.gson.reflect.TypeToken;
public class FactionColls extends Colls<FactionColl, Faction>
@ -62,6 +65,11 @@ public class FactionColls extends Colls<FactionColl, Faction>
return this.getForUniverse(((Coll<?>)o).getUniverse());
}
if (SenderUtil.isNonplayer(o))
{
return this.getForWorld(Bukkit.getWorlds().get(0).getName());
}
String worldName = MUtil.extract(String.class, "worldName", o);
if (worldName == null) return null;
return this.getForWorld(worldName);
@ -88,17 +96,31 @@ public class FactionColls extends Colls<FactionColl, Faction>
Type type = new TypeToken<Map<String, Faction>>(){}.getType();
Map<String, Faction> id2faction = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type);
// The Coll
FactionColl coll = this.getForUniverse(MCore.DEFAULT);
// Set the data
for (Entry<String, Faction> entry : id2faction.entrySet())
{
String factionId = entry.getKey();
Faction faction = entry.getValue();
this.getForUniverse(MCore.DEFAULT).create(factionId).load(faction);
coll.attach(faction, factionId);
}
// Mark as migrated
oldFile.renameTo(newFile);
}
// -------------------------------------------- //
// INDEX
// -------------------------------------------- //
public void reindexFPlayers()
{
for (FactionColl coll : this.getColls())
{
coll.reindexFPlayers();
}
}
}

View File

@ -7,7 +7,6 @@ import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.event.EventPriority;
import com.massivecraft.mcore.MCore;
import com.massivecraft.mcore.store.Entity;
public class MConf extends Entity<MConf>
@ -16,9 +15,10 @@ public class MConf extends Entity<MConf>
// META
// -------------------------------------------- //
protected static transient MConf i;
public static MConf get()
{
return MConfColl.get().get(MCore.INSTANCE);
return i;
}
// -------------------------------------------- //

View File

@ -28,7 +28,8 @@ public class MConfColl extends Coll<MConf>
public void init()
{
super.init();
this.get(MCore.INSTANCE);
MConf.i = this.get(MCore.INSTANCE);
}
}

View File

@ -507,7 +507,7 @@ public class FactionsListenerMain implements Listener
String name = player.getName();
if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true;
FPlayer me = FPlayer.get(name);
FPlayer me = FPlayer.get(player);
if (me.isUsingAdminMode()) return true;
Faction factionHere = BoardColls.get().getFactionAt(ps);