From 26fa7e8b95aaf4f6a7449f33c097366b7b04da7b Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 22 Apr 2013 15:05:00 +0200 Subject: [PATCH] Minor startup fixes --- src/com/massivecraft/factions/Factions.java | 10 +++++++ .../factions/entity/BoardColls.java | 8 ++++++ .../massivecraft/factions/entity/FPlayer.java | 2 +- .../factions/entity/FPlayerColl.java | 2 +- .../factions/entity/FPlayerColls.java | 13 +++++++++- .../factions/entity/FactionColl.java | 13 ++++++++-- .../factions/entity/FactionColls.java | 26 +++++++++++++++++-- .../massivecraft/factions/entity/MConf.java | 4 +-- .../factions/entity/MConfColl.java | 3 ++- .../listeners/FactionsListenerMain.java | 2 +- 10 files changed, 72 insertions(+), 11 deletions(-) diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 0aaf9fb2..17aea3e7 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -70,6 +70,10 @@ public class Factions extends MPlugin 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; } // -------------------------------------------- // // 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); diff --git a/src/com/massivecraft/factions/entity/BoardColls.java b/src/com/massivecraft/factions/entity/BoardColls.java index 8146c063..563e6763 100644 --- a/src/com/massivecraft/factions/entity/BoardColls.java +++ b/src/com/massivecraft/factions/entity/BoardColls.java @@ -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 implements BoardInterface @@ -66,6 +69,11 @@ public class BoardColls extends Colls 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); diff --git a/src/com/massivecraft/factions/entity/FPlayer.java b/src/com/massivecraft/factions/entity/FPlayer.java index 8f9a0cb2..edbb4b1e 100644 --- a/src/com/massivecraft/factions/entity/FPlayer.java +++ b/src/com/massivecraft/factions/entity/FPlayer.java @@ -231,7 +231,7 @@ public class FPlayer extends SenderEntity 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); diff --git a/src/com/massivecraft/factions/entity/FPlayerColl.java b/src/com/massivecraft/factions/entity/FPlayerColl.java index a0cef9d9..8b8b1901 100644 --- a/src/com/massivecraft/factions/entity/FPlayerColl.java +++ b/src/com/massivecraft/factions/entity/FPlayerColl.java @@ -30,7 +30,7 @@ public class FPlayerColl extends SenderColl // 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(); diff --git a/src/com/massivecraft/factions/entity/FPlayerColls.java b/src/com/massivecraft/factions/entity/FPlayerColls.java index 9a2b6d8e..93bf8608 100644 --- a/src/com/massivecraft/factions/entity/FPlayerColls.java +++ b/src/com/massivecraft/factions/entity/FPlayerColls.java @@ -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 @@ -62,6 +65,11 @@ public class FPlayerColls extends Colls 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 Type type = new TypeToken>(){}.getType(); Map id2fplayer = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type); + // The Coll + FPlayerColl coll = this.getForUniverse(MCore.DEFAULT); + // Set the data for (Entry 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 diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index c0c37183..5ddb84c3 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -39,9 +39,9 @@ public class FactionColl extends Coll 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 // 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) @@ -76,6 +81,10 @@ public class FactionColl extends Coll return ret; } + + // -------------------------------------------- // + // INDEX + // -------------------------------------------- // public void reindexFPlayers() { diff --git a/src/com/massivecraft/factions/entity/FactionColls.java b/src/com/massivecraft/factions/entity/FactionColls.java index 7d3e185e..2591c191 100644 --- a/src/com/massivecraft/factions/entity/FactionColls.java +++ b/src/com/massivecraft/factions/entity/FactionColls.java @@ -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 @@ -62,6 +65,11 @@ public class FactionColls extends Colls 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 Type type = new TypeToken>(){}.getType(); Map id2faction = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type); + // The Coll + FactionColl coll = this.getForUniverse(MCore.DEFAULT); + // Set the data for (Entry 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(); + } + } + } diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index a385a27f..fba951d3 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -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 @@ -16,9 +15,10 @@ public class MConf extends Entity // META // -------------------------------------------- // + protected static transient MConf i; public static MConf get() { - return MConfColl.get().get(MCore.INSTANCE); + return i; } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/MConfColl.java b/src/com/massivecraft/factions/entity/MConfColl.java index 4d96427a..4829cb52 100644 --- a/src/com/massivecraft/factions/entity/MConfColl.java +++ b/src/com/massivecraft/factions/entity/MConfColl.java @@ -28,7 +28,8 @@ public class MConfColl extends Coll public void init() { super.init(); - this.get(MCore.INSTANCE); + + MConf.i = this.get(MCore.INSTANCE); } } diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index 97c3772c..adab408e 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -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);