diff --git a/src/com/massivecraft/factions/Const.java b/src/com/massivecraft/factions/Const.java index 465051aa..b9be839d 100644 --- a/src/com/massivecraft/factions/Const.java +++ b/src/com/massivecraft/factions/Const.java @@ -18,6 +18,10 @@ public class Const public static final String COLLECTION_BASENAME_PLAYER = COLLECTION_BASENAME_+"player"; public static final String COLLECTION_BASENAME_FACTION = COLLECTION_BASENAME_+"faction"; + // Aspect Ids + + public static final String ASPECT_ID = "factions"; + // Defautlt faction ids public static final String FACTIONID_NONE = "0"; public static final String FACTIONID_SAFEZONE = "-1"; diff --git a/src/com/massivecraft/factions/FPerm.java b/src/com/massivecraft/factions/FPerm.java index 8abf2ca7..8091ca01 100644 --- a/src/com/massivecraft/factions/FPerm.java +++ b/src/com/massivecraft/factions/FPerm.java @@ -12,9 +12,8 @@ import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; -import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.FPlayer; -import com.massivecraft.factions.entity.FPlayerColl; import com.massivecraft.factions.entity.Faction; import com.massivecraft.mcore.ps.PS; @@ -178,7 +177,7 @@ public enum FPerm if (testSubject instanceof CommandSender) { - rpSubject = FPlayerColl.get().get(testSubject); + rpSubject = FPlayer.get(testSubject); } else if (testSubject instanceof RelationParticipator) { @@ -213,7 +212,7 @@ public enum FPerm } public boolean has(Object testSubject, PS ps, boolean informIfNot) { - TerritoryAccess access = BoardColl.get().getTerritoryAccessAt(ps); + TerritoryAccess access = BoardColls.get().getTerritoryAccessAt(ps); if (this.isTerritoryPerm()) { @@ -224,7 +223,7 @@ public enum FPerm { FPlayer notify = null; if (testSubject instanceof CommandSender) - notify = FPlayerColl.get().get(testSubject); + notify = FPlayer.get(testSubject); else if (testSubject instanceof FPlayer) notify = (FPlayer)testSubject; if (notify != null) diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 87f982c1..0aaf9fb2 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -20,9 +20,9 @@ import com.massivecraft.factions.chat.tag.ChatTagTagforce; import com.massivecraft.factions.chat.tag.ChatTagTitle; import com.massivecraft.factions.cmd.*; import com.massivecraft.factions.entity.Board; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.FPlayerColl; -import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.BoardColls; +import com.massivecraft.factions.entity.FPlayerColls; +import com.massivecraft.factions.entity.FactionColls; import com.massivecraft.factions.entity.MConfColl; import com.massivecraft.factions.integration.LWCFeatures; import com.massivecraft.factions.integration.SpoutFeatures; @@ -38,6 +38,9 @@ import com.massivecraft.factions.task.AutoLeaveTask; import com.massivecraft.factions.task.EconLandRewardTask; import com.massivecraft.mcore.MPlugin; +import com.massivecraft.mcore.usys.Aspect; +import com.massivecraft.mcore.usys.AspectColl; +import com.massivecraft.mcore.usys.Multiverse; import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.xlib.gson.GsonBuilder; @@ -62,6 +65,11 @@ public class Factions extends MPlugin // Listeners public TodoFactionsPlayerListener playerListener; + + // Aspects + private Aspect aspect; + public Aspect getAspect() { return this.aspect; } + public Multiverse getMultiverse() { return this.getAspect().getMultiverse(); } // -------------------------------------------- // // OVERRIDE @@ -75,15 +83,23 @@ public class Factions extends MPlugin // Load Server Config ConfServer.get().load(); + // Initialize Aspects + this.aspect = AspectColl.get().get(Const.ASPECT_ID, 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()); // Initialize Collections MConfColl.get().init(); - FPlayerColl.get().init(); - FactionColl.get().init(); - BoardColl.get().init(); + FPlayerColls.get().init(); + FactionColls.get().init(); + BoardColls.get().init(); // Commands this.outerCmdFactions = new CmdFactions(); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java index 341f3ac7..69a0cc1d 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java @@ -5,7 +5,7 @@ import com.massivecraft.factions.Perm; import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.FPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.integration.SpoutFeatures; @@ -36,7 +36,7 @@ public class CmdFactionsAccess extends FCommand type = (type == null) ? "" : type.toLowerCase(); PS chunk = PS.valueOf(me).getChunk(true); - TerritoryAccess territory = BoardColl.get().getTerritoryAccessAt(chunk); + TerritoryAccess territory = BoardColls.get().getTerritoryAccessAt(chunk); Faction locFaction = territory.getHostFaction(); boolean accessAny = Perm.ACCESS_ANY.has(sender, false); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java index 3cee85cd..e9046ef3 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java @@ -10,7 +10,7 @@ import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; -import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.FPlayer; import com.massivecraft.factions.entity.FPlayerColl; import com.massivecraft.factions.entity.Faction; @@ -69,7 +69,7 @@ public class CmdFactionsHome extends FCommand } - Faction faction = BoardColl.get().getFactionAt(PS.valueOf(me)); + Faction faction = BoardColls.get().getFactionAt(PS.valueOf(me)); Location loc = me.getLocation().clone(); // if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java index 9307ac3a..24fdb3cb 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java @@ -1,13 +1,12 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Perm; -import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.mcore.cmd.arg.ARBoolean; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; - public class CmdFactionsMap extends FCommand { public CmdFactionsMap() @@ -49,7 +48,7 @@ public class CmdFactionsMap extends FCommand public void showMap() { - sendMessage(BoardColl.get().getMap(myFaction, PS.valueOf(me), fme.getPlayer().getLocation().getYaw())); + sendMessage(BoardColls.get().getMap(myFaction, PS.valueOf(me), fme.getPlayer().getLocation().getYaw())); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java index a4914f31..eac67369 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.ConfServer; -import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.event.FactionsEventLandUnclaim; @@ -29,7 +29,7 @@ public class CmdFactionsUnclaim extends FCommand { // Args PS chunk = PS.valueOf(me).getChunk(true); - Faction otherFaction = BoardColl.get().getFactionAt(chunk); + Faction otherFaction = BoardColls.get().getFactionAt(chunk); // FPerm if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return; @@ -54,7 +54,7 @@ public class CmdFactionsUnclaim extends FCommand } } - BoardColl.get().removeAt(chunk); + BoardColls.get().removeAt(chunk); SpoutFeatures.updateTerritoryDisplayLoc(chunk); myFaction.msg("%s unclaimed some land.", fme.describeTo(myFaction, true)); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java index 20dd9775..b5188aab 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java @@ -5,7 +5,7 @@ import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; -import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.event.FactionsEventLandUnclaimAll; import com.massivecraft.factions.integration.Econ; @@ -45,7 +45,7 @@ public class CmdFactionsUnclaimall extends FCommand // TODO: this event cannot be cancelled yet. // Apply - BoardColl.get().removeAll(myFaction); + BoardColls.get().removeAll(myFaction); // Inform myFaction.msg("%s unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true)); diff --git a/src/com/massivecraft/factions/entity/Board.java b/src/com/massivecraft/factions/entity/Board.java index 9f105910..e31e3012 100644 --- a/src/com/massivecraft/factions/entity/Board.java +++ b/src/com/massivecraft/factions/entity/Board.java @@ -32,7 +32,7 @@ public class Board extends Entity implements BoardInterface public static Board get(Object oid) { - return BoardColl.get().get(oid); + return BoardColls.get().get2(oid); } // -------------------------------------------- // @@ -169,7 +169,7 @@ public class Board extends Entity implements BoardInterface { TerritoryAccess territoryAccess = entry.getValue(); - if (FactionColl.get().containsId(territoryAccess.getHostFactionId())) continue; + if (FactionColls.get().get(this).containsId(territoryAccess.getHostFactionId())) continue; PS ps = entry.getKey(); this.removeAt(ps); diff --git a/src/com/massivecraft/factions/entity/BoardColl.java b/src/com/massivecraft/factions/entity/BoardColl.java index f23b5caf..97eee39e 100644 --- a/src/com/massivecraft/factions/entity/BoardColl.java +++ b/src/com/massivecraft/factions/entity/BoardColl.java @@ -1,35 +1,25 @@ package com.massivecraft.factions.entity; -import java.io.File; -import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.Map; -import java.util.Map.Entry; import com.massivecraft.factions.ConfServer; -import com.massivecraft.factions.Const; import com.massivecraft.factions.Factions; import com.massivecraft.factions.RelationParticipator; import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.mcore.ps.PS; -import com.massivecraft.mcore.ps.PSBuilder; import com.massivecraft.mcore.store.Coll; import com.massivecraft.mcore.store.MStore; -import com.massivecraft.mcore.util.DiscUtil; import com.massivecraft.mcore.util.MUtil; -import com.massivecraft.mcore.xlib.gson.reflect.TypeToken; public class BoardColl extends Coll implements BoardInterface { // -------------------------------------------- // - // INSTANCE & CONSTRUCT + // CONSTRUCT // -------------------------------------------- // - private static BoardColl i = new BoardColl(); - public static BoardColl get() { return i; } - private BoardColl() + public BoardColl(String name) { - super(Const.COLLECTION_BASENAME_BOARD, Board.class, MStore.getDb(ConfServer.dburi), Factions.get(), true, true); + super(name, Board.class, MStore.getDb(ConfServer.dburi), Factions.get(), true, true); } // -------------------------------------------- // @@ -46,50 +36,6 @@ public class BoardColl extends Coll implements BoardInterface return MUtil.extract(String.class, "worldName", oid); } - @Override - public void init() - { - super.init(); - - this.migrate(); - } - - public void migrate() - { - // Create file objects - File oldFile = new File(Factions.get().getDataFolder(), "board.json"); - File newFile = new File(Factions.get().getDataFolder(), "board.json.migrated"); - - // Already migrated? - if ( ! oldFile.exists()) return; - - // Read the file content through GSON. - Type type = new TypeToken>>(){}.getType(); - Map> worldCoordIds = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type); - - // Set the data - for (Entry> entry : worldCoordIds.entrySet()) - { - String worldName = entry.getKey(); - Board board = this.get(worldName); - for (Entry entry2 : entry.getValue().entrySet()) - { - String[] ChunkCoordParts = entry2.getKey().trim().split("[,\\s]+"); - int chunkX = Integer.parseInt(ChunkCoordParts[0]); - int chunkZ = Integer.parseInt(ChunkCoordParts[1]); - PS ps = new PSBuilder().chunkX(chunkX).chunkZ(chunkZ).build(); - - TerritoryAccess territoryAccess = entry2.getValue(); - - board.setTerritoryAccessAt(ps, territoryAccess); - } - } - - // Mark as migrated - oldFile.renameTo(newFile); - } - - // -------------------------------------------- // // OVERRIDE: BOARD // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/BoardColls.java b/src/com/massivecraft/factions/entity/BoardColls.java new file mode 100644 index 00000000..8146c063 --- /dev/null +++ b/src/com/massivecraft/factions/entity/BoardColls.java @@ -0,0 +1,233 @@ +package com.massivecraft.factions.entity; + +import java.io.File; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Map; +import java.util.Map.Entry; + +import com.massivecraft.factions.Const; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.RelationParticipator; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.mcore.ps.PS; +import com.massivecraft.mcore.ps.PSBuilder; +import com.massivecraft.mcore.store.Coll; +import com.massivecraft.mcore.store.Colls; +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.xlib.gson.reflect.TypeToken; + +public class BoardColls extends Colls implements BoardInterface +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static BoardColls i = new BoardColls(); + public static BoardColls get() { return i; } + + // -------------------------------------------- // + // OVERRIDE: COLLS + // -------------------------------------------- // + + @Override + public BoardColl createColl(String collName) + { + return new BoardColl(collName); + } + + @Override + public Aspect getAspect() + { + return Factions.get().getAspect(); + } + + @Override + public String getBasename() + { + return Const.COLLECTION_BASENAME_UCONF; + } + + @Override + public BoardColl get(Object o) + { + if (o == null) return null; + + if (o instanceof Entity) + { + return this.getForUniverse(((Entity)o).getUniverse()); + } + + if (o instanceof Coll) + { + return this.getForUniverse(((Coll)o).getUniverse()); + } + + String worldName = MUtil.extract(String.class, "worldName", o); + if (worldName == null) return null; + return this.getForWorld(worldName); + } + + @Override + public void init() + { + super.init(); + + this.migrate(); + } + + public void migrate() + { + // Create file objects + File oldFile = new File(Factions.get().getDataFolder(), "board.json"); + File newFile = new File(Factions.get().getDataFolder(), "board.json.migrated"); + + // Already migrated? + if ( ! oldFile.exists()) return; + + // Read the file content through GSON. + Type type = new TypeToken>>(){}.getType(); + Map> worldCoordIds = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type); + + // Set the data + for (Entry> entry : worldCoordIds.entrySet()) + { + String worldName = entry.getKey(); + BoardColl boardColl = this.getForWorld(worldName); + Board board = boardColl.get(worldName); + for (Entry entry2 : entry.getValue().entrySet()) + { + String[] ChunkCoordParts = entry2.getKey().trim().split("[,\\s]+"); + int chunkX = Integer.parseInt(ChunkCoordParts[0]); + int chunkZ = Integer.parseInt(ChunkCoordParts[1]); + PS ps = new PSBuilder().chunkX(chunkX).chunkZ(chunkZ).build(); + + TerritoryAccess territoryAccess = entry2.getValue(); + + board.setTerritoryAccessAt(ps, territoryAccess); + } + } + + // Mark as migrated + oldFile.renameTo(newFile); + } + + // -------------------------------------------- // + // OVERRIDE: BOARD + // -------------------------------------------- // + + @Override + public TerritoryAccess getTerritoryAccessAt(PS ps) + { + if (ps == null) return null; + BoardColl coll = this.getForWorld(ps.getWorld()); + if (coll == null) return null; + return coll.getTerritoryAccessAt(ps); + } + + @Override + public Faction getFactionAt(PS ps) + { + if (ps == null) return null; + BoardColl coll = this.getForWorld(ps.getWorld()); + if (coll == null) return null; + return coll.getFactionAt(ps); + } + + // SET + + @Override + public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess) + { + if (ps == null) return; + BoardColl coll = this.getForWorld(ps.getWorld()); + if (coll == null) return; + coll.setTerritoryAccessAt(ps, territoryAccess); + } + + @Override + public void setFactionAt(PS ps, Faction faction) + { + if (ps == null) return; + BoardColl coll = this.getForWorld(ps.getWorld()); + if (coll == null) return; + coll.setFactionAt(ps, faction); + } + + // REMOVE + + @Override + public void removeAt(PS ps) + { + if (ps == null) return; + BoardColl coll = this.getForWorld(ps.getWorld()); + if (coll == null) return; + coll.removeAt(ps); + } + + @Override + public void removeAll(Faction faction) + { + for (BoardColl coll : this.getColls()) + { + coll.removeAll(faction); + } + } + + @Override + public void clean() + { + for (BoardColl coll : this.getColls()) + { + coll.clean(); + } + } + + // COUNT + + @Override + public int getCount(Faction faction) + { + int ret = 0; + for (BoardColl coll : this.getColls()) + { + ret += coll.getCount(faction); + } + return ret; + } + + // NEARBY DETECTION + + @Override + public boolean isBorderPs(PS ps) + { + if (ps == null) return false; + BoardColl coll = this.getForWorld(ps.getWorld()); + if (coll == null) return false; + return coll.isBorderPs(ps); + } + + @Override + public boolean isConnectedPs(PS ps, Faction faction) + { + if (ps == null) return false; + BoardColl coll = this.getForWorld(ps.getWorld()); + if (coll == null) return false; + return coll.isConnectedPs(ps, faction); + } + + // MAP GENERATION + + @Override + public ArrayList getMap(RelationParticipator observer, PS centerPs, double inDegrees) + { + if (centerPs == null) return null; + BoardColl coll = this.getForWorld(centerPs.getWorld()); + if (coll == null) return null; + return coll.getMap(observer, centerPs, inDegrees); + } + +} diff --git a/src/com/massivecraft/factions/entity/FPlayer.java b/src/com/massivecraft/factions/entity/FPlayer.java index de976992..6d797579 100644 --- a/src/com/massivecraft/factions/entity/FPlayer.java +++ b/src/com/massivecraft/factions/entity/FPlayer.java @@ -41,7 +41,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato public static FPlayer get(Object oid) { - return FPlayerColl.get().get(oid); + return FPlayerColls.get().get2(oid); } // -------------------------------------------- // @@ -200,8 +200,8 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // This method never returns null public Faction getFaction() { - Faction ret = FactionColl.get().get(this.getFactionId()); - if (ret == null) ret = FactionColl.get().get(Const.FACTIONID_NONE); + Faction ret = FactionColls.get().get(this).get(this.getFactionId()); + if (ret == null) ret = FactionColls.get().get(this).get(Const.FACTIONID_NONE); return ret; } @@ -235,15 +235,15 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // Next we must be attached and inited if (!this.attached()) return; if (!this.getColl().inited()) return; - if (!FactionColl.get().inited()) return; + if (!FactionColls.get().get(this).inited()) return; // Spout Derp SpoutFeatures.updateTitle(this, null); SpoutFeatures.updateTitle(null, this); // Update index - Faction oldFaction = FactionColl.get().get(oldFactionId); - Faction faction = FactionColl.get().get(factionId); + Faction oldFaction = FactionColls.get().get(this).get(oldFactionId); + Faction faction = FactionColls.get().get(this).get(factionId); oldFaction.fplayers.remove(this); faction.fplayers.add(this); @@ -596,7 +596,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato public Rel getRelationToLocation() { // TODO: Use some built in system to get sender - return BoardColl.get().getFactionAt(PS.valueOf(this.getPlayer())).getRelationTo(this); + return BoardColls.get().getFactionAt(PS.valueOf(this.getPlayer())).getRelationTo(this); } @Override @@ -626,13 +626,13 @@ public class FPlayer extends SenderEntity implements EconomyParticipato public boolean isInOwnTerritory() { // TODO: Use Mixin to get this PS instead - return BoardColl.get().getFactionAt(PS.valueOf(this.getPlayer())) == this.getFaction(); + return BoardColls.get().getFactionAt(Mixin.getSenderPs(this.getId())) == this.getFaction(); } public boolean isInEnemyTerritory() { // TODO: Use Mixin to get this PS instead - return BoardColl.get().getFactionAt(PS.valueOf(this.getPlayer())).getRelationTo(this) == Rel.ENEMY; + return BoardColls.get().getFactionAt(Mixin.getSenderPs(this.getId())).getRelationTo(this) == Rel.ENEMY; } public void sendFactionHereMessage() @@ -641,7 +641,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato { return; } - Faction factionHere = BoardColl.get().getFactionAt(this.getCurrentChunk()); + Faction factionHere = BoardColls.get().getFactionAt(this.getCurrentChunk()); String msg = Txt.parse("")+" ~ "+factionHere.getTag(this); if (factionHere.hasDescription()) { @@ -705,7 +705,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato if (myFaction.isNormal() && !permanent && myFaction.getFPlayers().isEmpty()) { // Remove this faction - for (FPlayer fplayer : FPlayerColl.get().getAllOnline()) + for (FPlayer fplayer : FPlayerColls.get().get(this).getAllOnline()) { fplayer.msg("%s was disbanded.", myFaction.describeTo(fplayer, true)); } @@ -723,7 +723,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato String error = null; Faction myFaction = this.getFaction(); - Faction currentFaction = BoardColl.get().getFactionAt(ps); + Faction currentFaction = BoardColls.get().getFactionAt(ps); int ownedLand = forFaction.getLandCount(); if (ConfServer.worldGuardChecking && Worldguard.checkForRegionsInChunk(ps)) @@ -772,7 +772,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato ConfServer.claimsMustBeConnected && ! this.isUsingAdminMode() && myFaction.getLandCountInWorld(ps.getWorld()) > 0 - && !BoardColl.get().isConnectedPs(ps, myFaction) + && !BoardColls.get().isConnectedPs(ps, myFaction) && (!ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal()) ) { @@ -788,7 +788,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // TODO more messages WARN current faction most importantly error = Txt.parse("%s owns this land and is strong enough to keep it.", currentFaction.getTag(this)); } - else if ( ! BoardColl.get().isBorderPs(ps)) + else if ( ! BoardColls.get().isBorderPs(ps)) { error = Txt.parse("You must start claiming land at the border of the territory."); } @@ -806,7 +806,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato public boolean attemptClaim(Faction forFaction, PS psChunk, boolean notifyFailure) { psChunk = psChunk.getChunk(true); - Faction currentFaction = BoardColl.get().getFactionAt(psChunk); + Faction currentFaction = BoardColls.get().getFactionAt(psChunk); int ownedLand = forFaction.getLandCount(); if ( ! this.canClaimForFactionAtLocation(forFaction, psChunk, notifyFailure)) return false; @@ -820,7 +820,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // TODO: The economy integration should cancel the event above! // Calculate the cost to claim the area double cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal()); - if (ConfServer.econClaimUnconnectedFee != 0.0 && forFaction.getLandCountInWorld(psChunk.getWorld()) > 0 && !BoardColl.get().isConnectedPs(psChunk, forFaction)) + if (ConfServer.econClaimUnconnectedFee != 0.0 && forFaction.getLandCountInWorld(psChunk.getWorld()) > 0 && !BoardColls.get().isConnectedPs(psChunk, forFaction)) { cost += ConfServer.econClaimUnconnectedFee; } @@ -841,7 +841,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato fp.msg("%s claimed land for %s from %s.", this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp)); } - BoardColl.get().setFactionAt(psChunk, forFaction); + BoardColls.get().setFactionAt(psChunk, forFaction); SpoutFeatures.updateTerritoryDisplayLoc(psChunk); if (MConf.get().logLandClaims) diff --git a/src/com/massivecraft/factions/entity/FPlayerColl.java b/src/com/massivecraft/factions/entity/FPlayerColl.java index 54177b60..a0cef9d9 100644 --- a/src/com/massivecraft/factions/entity/FPlayerColl.java +++ b/src/com/massivecraft/factions/entity/FPlayerColl.java @@ -1,73 +1,28 @@ package com.massivecraft.factions.entity; -import java.io.File; -import java.lang.reflect.Type; -import java.util.Map; -import java.util.Map.Entry; - import com.massivecraft.factions.ConfServer; -import com.massivecraft.factions.Const; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Rel; import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.store.MStore; import com.massivecraft.mcore.store.SenderColl; -import com.massivecraft.mcore.util.DiscUtil; import com.massivecraft.mcore.util.TimeUnit; -import com.massivecraft.mcore.xlib.gson.reflect.TypeToken; public class FPlayerColl extends SenderColl { // -------------------------------------------- // - // INSTANCE & CONSTRUCT + // CONSTRUCT // -------------------------------------------- // - private static FPlayerColl i = new FPlayerColl(); - public static FPlayerColl get() { return i; } - private FPlayerColl() + public FPlayerColl(String name) { - super(Const.COLLECTION_BASENAME_PLAYER, FPlayer.class, MStore.getDb(ConfServer.dburi), Factions.get()); + super(name, FPlayer.class, MStore.getDb(ConfServer.dburi), Factions.get()); } // -------------------------------------------- // // OVERRIDE: COLL // -------------------------------------------- // - - // TODO: Init and migration routine! - - @Override - public void init() - { - super.init(); - this.migrate(); - } - - public void migrate() - { - // Create file objects - File oldFile = new File(Factions.get().getDataFolder(), "players.json"); - File newFile = new File(Factions.get().getDataFolder(), "players.json.migrated"); - - // Already migrated? - if ( ! oldFile.exists()) return; - - // Read the file content through GSON. - Type type = new TypeToken>(){}.getType(); - Map id2fplayer = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type); - - // Set the data - for (Entry entry : id2fplayer.entrySet()) - { - String playerId = entry.getKey(); - FPlayer fplayer = entry.getValue(); - FPlayerColl.get().create(playerId).load(fplayer); - } - - // Mark as migrated - oldFile.renameTo(newFile); - } - @Override protected synchronized String attach(FPlayer entity, Object oid, boolean noteChange) { @@ -75,7 +30,7 @@ public class FPlayerColl extends SenderColl // If inited ... if (!this.inited()) return ret; - if (!FactionColl.get().inited()) return ret; + if (!FactionColls.get().getForUniverse(this.getUniverse()).inited()) return ret; // ... update the index. Faction faction = entity.getFaction(); @@ -108,7 +63,7 @@ public class FPlayerColl extends SenderColl { for (FPlayer fplayer : this.getAll()) { - if (FactionColl.get().containsId(fplayer.getFactionId())) continue; + if (FactionColls.get().get(this).containsId(fplayer.getFactionId())) continue; Factions.get().log("Reset faction data (invalid faction) for player "+fplayer.getName()); fplayer.resetFactionData(false); diff --git a/src/com/massivecraft/factions/entity/FPlayerColls.java b/src/com/massivecraft/factions/entity/FPlayerColls.java new file mode 100644 index 00000000..9a2b6d8e --- /dev/null +++ b/src/com/massivecraft/factions/entity/FPlayerColls.java @@ -0,0 +1,103 @@ +package com.massivecraft.factions.entity; + +import java.io.File; +import java.lang.reflect.Type; +import java.util.Map; +import java.util.Map.Entry; + +import com.massivecraft.factions.Const; +import com.massivecraft.factions.Factions; +import com.massivecraft.mcore.MCore; +import com.massivecraft.mcore.store.Coll; +import com.massivecraft.mcore.store.Colls; +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.xlib.gson.reflect.TypeToken; + +public class FPlayerColls extends Colls +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static FPlayerColls i = new FPlayerColls(); + public static FPlayerColls get() { return i; } + + // -------------------------------------------- // + // OVERRIDE: COLLS + // -------------------------------------------- // + + @Override + public FPlayerColl createColl(String collName) + { + return new FPlayerColl(collName); + } + + @Override + public Aspect getAspect() + { + return Factions.get().getAspect(); + } + + @Override + public String getBasename() + { + return Const.COLLECTION_BASENAME_PLAYER; + } + + @Override + public FPlayerColl get(Object o) + { + if (o == null) return null; + + if (o instanceof Entity) + { + return this.getForUniverse(((Entity)o).getUniverse()); + } + + if (o instanceof Coll) + { + return this.getForUniverse(((Coll)o).getUniverse()); + } + + String worldName = MUtil.extract(String.class, "worldName", o); + if (worldName == null) return null; + return this.getForWorld(worldName); + } + + @Override + public void init() + { + super.init(); + + this.migrate(); + } + + public void migrate() + { + // Create file objects + File oldFile = new File(Factions.get().getDataFolder(), "players.json"); + File newFile = new File(Factions.get().getDataFolder(), "players.json.migrated"); + + // Already migrated? + if ( ! oldFile.exists()) return; + + // Read the file content through GSON. + Type type = new TypeToken>(){}.getType(); + Map id2fplayer = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type); + + // 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); + } + + // Mark as migrated + oldFile.renameTo(newFile); + } + +} diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 074de2f2..41b089ad 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -36,7 +36,7 @@ public class Faction extends Entity implements EconomyParticipator public static Faction get(Object oid) { - return FactionColl.get().get(oid); + return FactionColls.get().get2(oid); } // -------------------------------------------- // @@ -238,7 +238,7 @@ public class Faction extends Entity implements EconomyParticipator { if (ps == null) return true; if (!ConfServer.homesMustBeInClaimedTerritory) return true; - if (BoardColl.get().getFactionAt(ps) == this) return true; + if (BoardColls.get().getFactionAt(ps) == this) return true; return false; } @@ -451,7 +451,7 @@ public class Faction extends Entity implements EconomyParticipator { ret.put(rel, new ArrayList()); } - for (Faction faction : FactionColl.get().getAll()) + for (Faction faction : FactionColls.get().get(this).getAll()) { Rel relation = faction.getRelationTo(this); if (onlyNonNeutral && relation == Rel.NEUTRAL) continue; @@ -715,11 +715,11 @@ public class Faction extends Entity implements EconomyParticipator public int getLandCount() { - return BoardColl.get().getCount(this); + return BoardColls.get().getCount(this); } public int getLandCountInWorld(String worldName) { - return BoardColl.get().get(worldName).getCount(this); + return BoardColls.get().get(worldName).getCount(this); } public boolean hasLandInflation() @@ -743,7 +743,7 @@ public class Faction extends Entity implements EconomyParticipator String factionId = this.getId(); if (factionId == null) return; - for (FPlayer fplayer : FPlayerColl.get().getAll()) + for (FPlayer fplayer : FPlayerColls.get().get(this).getAll()) { if (!MUtil.equals(factionId, fplayer.getFactionId())) continue; this.fplayers.add(fplayer); @@ -805,7 +805,8 @@ public class Faction extends Entity implements EconomyParticipator List ret = new ArrayList(); for (CommandSender player : SenderUtil.getOnlineSenders()) { - FPlayer fplayer = FPlayerColl.get().get(player); + FPlayer fplayer = FPlayer.get(player); + if (!MUtil.equals(fplayer.getUniverse(), this.getUniverse())) continue; if (fplayer.getFaction() != this) continue; ret.add(player); } @@ -817,7 +818,8 @@ public class Faction extends Entity implements EconomyParticipator List ret = new ArrayList(); for (Player player : Bukkit.getOnlinePlayers()) { - FPlayer fplayer = FPlayerColl.get().get(player); + FPlayer fplayer = FPlayer.get(player); + if (!MUtil.equals(fplayer.getUniverse(), this.getUniverse())) continue; if (fplayer.getFaction() != this) continue; ret.add(player); } @@ -856,7 +858,7 @@ public class Faction extends Entity implements EconomyParticipator Factions.get().log("The faction "+this.getTag()+" ("+this.getId()+") has been disbanded since it has no members left."); } - for (FPlayer fplayer : FPlayerColl.get().getAllOnline()) + for (FPlayer fplayer : FPlayerColls.get().get(this).getAllOnline()) { fplayer.msg("The faction %s was disbanded.", this.getTag(fplayer)); } diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index e0c682c4..c0c37183 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -1,18 +1,13 @@ package com.massivecraft.factions.entity; -import java.io.File; -import java.lang.reflect.Type; import java.util.*; -import java.util.Map.Entry; import org.bukkit.ChatColor; import com.massivecraft.mcore.money.Money; import com.massivecraft.mcore.store.Coll; import com.massivecraft.mcore.store.MStore; -import com.massivecraft.mcore.util.DiscUtil; import com.massivecraft.mcore.util.Txt; -import com.massivecraft.mcore.xlib.gson.reflect.TypeToken; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Const; @@ -26,14 +21,12 @@ import com.massivecraft.factions.util.MiscUtil; public class FactionColl extends Coll { // -------------------------------------------- // - // INSTANCE & CONSTRUCT + // CONSTRUCT // -------------------------------------------- // - private static FactionColl i = new FactionColl(); - public static FactionColl get() { return i; } - private FactionColl() + public FactionColl(String name) { - super(Const.COLLECTION_BASENAME_FACTION, Faction.class, MStore.getDb(ConfServer.dburi), Factions.get()); + super(name, Faction.class, MStore.getDb(ConfServer.dburi), Factions.get()); } // -------------------------------------------- // @@ -45,37 +38,10 @@ public class FactionColl extends Coll { super.init(); - this.migrate(); this.createDefaultFactions(); this.reindexFPlayers(); } - public void migrate() - { - // Create file objects - File oldFile = new File(Factions.get().getDataFolder(), "factions.json"); - File newFile = new File(Factions.get().getDataFolder(), "factions.json.migrated"); - - // Already migrated? - if ( ! oldFile.exists()) return; - - // Read the file content through GSON. - Type type = new TypeToken>(){}.getType(); - Map id2faction = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type); - - // Set the data - for (Entry entry : id2faction.entrySet()) - { - String factionId = entry.getKey(); - Faction faction = entry.getValue(); - - FactionColl.get().create(factionId).load(faction); - } - - // Mark as migrated - oldFile.renameTo(newFile); - } - @Override protected synchronized String attach(Faction faction, Object oid, boolean noteChange) { @@ -97,19 +63,16 @@ public class FactionColl extends Coll public Faction detachId(Object oid) { Faction faction = this.get(oid); - if (faction != null) - { - Money.set(faction, faction, 0); - } + Money.set(faction, 0); + String universe = faction.getUniverse(); Faction ret = super.detachId(oid); // Clean the board - // TODO: Use events for this instead? - BoardColl.get().clean(); + BoardColls.get().getForUniverse(universe).clean(); // Clean the fplayers - FPlayerColl.get().clean(); + FPlayerColls.get().getForUniverse(universe).clean(); return ret; } diff --git a/src/com/massivecraft/factions/entity/FactionColls.java b/src/com/massivecraft/factions/entity/FactionColls.java new file mode 100644 index 00000000..7d3e185e --- /dev/null +++ b/src/com/massivecraft/factions/entity/FactionColls.java @@ -0,0 +1,104 @@ +package com.massivecraft.factions.entity; + +import java.io.File; +import java.lang.reflect.Type; +import java.util.Map; +import java.util.Map.Entry; + +import com.massivecraft.factions.Const; +import com.massivecraft.factions.Factions; +import com.massivecraft.mcore.MCore; +import com.massivecraft.mcore.store.Coll; +import com.massivecraft.mcore.store.Colls; +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.xlib.gson.reflect.TypeToken; + +public class FactionColls extends Colls +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static FactionColls i = new FactionColls(); + public static FactionColls get() { return i; } + + // -------------------------------------------- // + // OVERRIDE: COLLS + // -------------------------------------------- // + + @Override + public FactionColl createColl(String collName) + { + return new FactionColl(collName); + } + + @Override + public Aspect getAspect() + { + return Factions.get().getAspect(); + } + + @Override + public String getBasename() + { + return Const.COLLECTION_BASENAME_FACTION; + } + + @Override + public FactionColl get(Object o) + { + if (o == null) return null; + + if (o instanceof Entity) + { + return this.getForUniverse(((Entity)o).getUniverse()); + } + + if (o instanceof Coll) + { + return this.getForUniverse(((Coll)o).getUniverse()); + } + + String worldName = MUtil.extract(String.class, "worldName", o); + if (worldName == null) return null; + return this.getForWorld(worldName); + } + + @Override + public void init() + { + super.init(); + + this.migrate(); + } + + public void migrate() + { + // Create file objects + File oldFile = new File(Factions.get().getDataFolder(), "factions.json"); + File newFile = new File(Factions.get().getDataFolder(), "factions.json.migrated"); + + // Already migrated? + if ( ! oldFile.exists()) return; + + // Read the file content through GSON. + Type type = new TypeToken>(){}.getType(); + Map id2faction = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type); + + // Set the data + for (Entry entry : id2faction.entrySet()) + { + String factionId = entry.getKey(); + Faction faction = entry.getValue(); + + this.getForUniverse(MCore.DEFAULT).create(factionId).load(faction); + } + + // Mark as migrated + oldFile.renameTo(newFile); + } + +} diff --git a/src/com/massivecraft/factions/integration/SpoutFeatures.java b/src/com/massivecraft/factions/integration/SpoutFeatures.java index d4edb612..d2aad973 100644 --- a/src/com/massivecraft/factions/integration/SpoutFeatures.java +++ b/src/com/massivecraft/factions/integration/SpoutFeatures.java @@ -1,7 +1,6 @@ package com.massivecraft.factions.integration; import java.util.Arrays; -import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -14,7 +13,6 @@ import org.bukkit.plugin.Plugin; import org.bukkit.entity.Player; import com.massivecraft.factions.entity.FPlayer; -import com.massivecraft.factions.entity.FPlayerColl; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.util.HealthBarUtil; import com.massivecraft.mcore.ps.PS; @@ -252,17 +250,16 @@ public class SpoutFeatures { if ( ! isEnabled()) return; - Collection players = FPlayerColl.get().getAllOnline(); - - for (FPlayer player : players) + for (Player player : Bukkit.getOnlinePlayers()) { + FPlayer fplayer = FPlayer.get(player); if (chunk == null) { - mainListener.updateTerritoryDisplay(player, false); + mainListener.updateTerritoryDisplay(fplayer, false); } - else if (player.getCurrentChunk().equals(chunk)) + else if (fplayer.getCurrentChunk().equals(chunk)) { - mainListener.updateTerritoryDisplay(player, true); + mainListener.updateTerritoryDisplay(fplayer, true); } } } @@ -281,12 +278,13 @@ public class SpoutFeatures chunk = chunk.getChunk(true); - Collection players = FPlayerColl.get().getAllOnline(); - - for (FPlayer player : players) + for (Player player : Bukkit.getOnlinePlayers()) { - if (chunk == null || player.getCurrentChunk().equals(chunk)) - mainListener.updateAccessInfo(player); + FPlayer fplayer = FPlayer.get(player); + if (chunk == null || fplayer.getCurrentChunk().equals(chunk)) + { + mainListener.updateAccessInfo(fplayer); + } } } diff --git a/src/com/massivecraft/factions/integration/SpoutMainListener.java b/src/com/massivecraft/factions/integration/SpoutMainListener.java index ae653e98..2c70783d 100644 --- a/src/com/massivecraft/factions/integration/SpoutMainListener.java +++ b/src/com/massivecraft/factions/integration/SpoutMainListener.java @@ -11,9 +11,8 @@ import org.bukkit.event.Listener; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.FPlayer; -import com.massivecraft.factions.entity.FPlayerColl; import com.massivecraft.factions.entity.Faction; import com.massivecraft.mcore.ps.PS; @@ -29,7 +28,7 @@ public class SpoutMainListener implements Listener @EventHandler(priority = EventPriority.NORMAL) public void onSpoutCraftEnable(SpoutCraftEnableEvent event) { - final FPlayer me = FPlayerColl.get().get(event.getPlayer()); + final FPlayer me = FPlayer.get(event.getPlayer()); SpoutFeatures.updateTitle(me, null); SpoutFeatures.updateTitle(null, me); @@ -90,7 +89,7 @@ public class SpoutMainListener implements Listener private void doLabels(FPlayer player, SpoutPlayer sPlayer, boolean notify) { PS here = player.getCurrentChunk(); - Faction factionHere = BoardColl.get().getFactionAt(here); + Faction factionHere = BoardColls.get().getFactionAt(here); String tag = factionHere.getColorTo(player).toString() + factionHere.getTag(); // ---------------------- @@ -181,7 +180,7 @@ public class SpoutMainListener implements Listener } String msg = ""; - TerritoryAccess access = BoardColl.get().getTerritoryAccessAt(here); + TerritoryAccess access = BoardColls.get().getTerritoryAccessAt(here); if ( ! access.isDefault()) { diff --git a/src/com/massivecraft/factions/integration/herochat/FactionChannel.java b/src/com/massivecraft/factions/integration/herochat/FactionChannel.java index 2b237195..318760a3 100644 --- a/src/com/massivecraft/factions/integration/herochat/FactionChannel.java +++ b/src/com/massivecraft/factions/integration/herochat/FactionChannel.java @@ -11,7 +11,7 @@ import com.massivecraft.factions.entity.MConf; public class FactionChannel extends FactionsChannelAbstract { - public static final Set targetRelations = EnumSet.of(Rel.MEMBER); + public static final Set targetRelations = EnumSet.of(Rel.MEMBER, Rel.RECRUIT); @Override public Set getTargetRelations() { return targetRelations; } @Override public String getName() { return MConf.get().herochatFactionName; } diff --git a/src/com/massivecraft/factions/integration/herochat/FactionsChannelAbstract.java b/src/com/massivecraft/factions/integration/herochat/FactionsChannelAbstract.java index 6d89724b..f8cca6a3 100644 --- a/src/com/massivecraft/factions/integration/herochat/FactionsChannelAbstract.java +++ b/src/com/massivecraft/factions/integration/herochat/FactionsChannelAbstract.java @@ -24,7 +24,6 @@ import com.dthielke.herochat.MessageNotFoundException; import com.dthielke.herochat.util.Messaging; import com.massivecraft.factions.Rel; import com.massivecraft.factions.entity.FPlayer; -import com.massivecraft.factions.entity.FPlayerColl; import com.massivecraft.factions.entity.Faction; public abstract class FactionsChannelAbstract implements Channel @@ -206,30 +205,27 @@ public abstract class FactionsChannelAbstract implements Channel return this.getMutes().contains(name.toLowerCase()); } - public abstract Set getTargetRelations(); - // TODO: When I add in universes I will need to separate the channel per universe. public Set getRecipients(Player sender) { Set ret = new HashSet(); - FPlayer fpsender = FPlayerColl.get().get(sender); - Faction faction = fpsender.getFaction(); - ret.addAll(faction.getOnlinePlayers()); + FPlayer fpsender = FPlayer.get(sender); + Faction faction = fpsender.getFaction(); + String universe = fpsender.getUniverse(); - for (FPlayer fplayer : FPlayerColl.get().getAllOnline()) + for (Player player : Bukkit.getOnlinePlayers()) { - if(this.getTargetRelations().contains(faction.getRelationTo(fplayer))) - { - ret.add(fplayer.getPlayer()); - } + FPlayer frecipient = FPlayer.get(player); + if (!frecipient.getUniverse().equals(universe)) continue; + if (!this.getTargetRelations().contains(faction.getRelationTo(frecipient))) continue; + ret.add(player); } return ret; } - @Override public void processChat(ChannelChatEvent event) { diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index acbaa172..457dc377 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -50,9 +50,8 @@ import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Rel; -import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.FPlayer; -import com.massivecraft.factions.entity.FPlayerColl; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.event.FactionsEventPowerChange; @@ -90,10 +89,10 @@ public class FactionsListenerMain implements Listener { // If a player dies ... Player player = event.getEntity(); - FPlayer fplayer = FPlayerColl.get().get(player); + FPlayer fplayer = FPlayer.get(player); // ... and powerloss can happen here ... - Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player)); + Faction faction = BoardColls.get().getFactionAt(PS.valueOf(player)); if (!faction.getFlag(FFlag.POWERLOSS)) { @@ -170,7 +169,7 @@ public class FactionsListenerMain implements Listener Entity edefender = event.getEntity(); if (!(edefender instanceof Player)) return true; Player defender = (Player)edefender; - FPlayer fdefender = FPlayerColl.get().get(edefender); + FPlayer fdefender = FPlayer.get(edefender); // ... and the attacker is someone else ... Entity eattacker = event.getDamager(); @@ -182,7 +181,7 @@ public class FactionsListenerMain implements Listener // ... gather defender PS and faction information ... PS defenderPs = PS.valueOf(defender); - Faction defenderPsFaction = BoardColl.get().getFactionAt(defenderPs); + Faction defenderPsFaction = BoardColls.get().getFactionAt(defenderPs); // ... PVP flag may cause a damage block ... if (defenderPsFaction.getFlag(FFlag.PVP) == false) @@ -191,7 +190,7 @@ public class FactionsListenerMain implements Listener { if (notify) { - FPlayer attacker = FPlayerColl.get().get((Player)eattacker); + FPlayer attacker = FPlayer.get(eattacker); attacker.msg("PVP is disabled in %s.", defenderPsFaction.describeTo(attacker)); } return false; @@ -202,14 +201,14 @@ public class FactionsListenerMain implements Listener // ... and if the attacker is a player ... if (!(eattacker instanceof Player)) return true; Player attacker = (Player)eattacker; - FPlayer fattacker = FPlayerColl.get().get(attacker); + FPlayer fattacker = FPlayer.get(attacker); // ... does this player bypass all protection? ... if (MConf.get().playersWhoBypassAllProtection.contains(attacker.getName())) return true; // ... gather attacker PS and faction information ... PS attackerPs = PS.valueOf(attacker); - Faction attackerPsFaction = BoardColl.get().getFactionAt(attackerPs); + Faction attackerPsFaction = BoardColls.get().getFactionAt(attackerPs); // ... PVP flag may cause a damage block ... // (just checking the defender as above isn't enough. What about the attacker? It could be in a no-pvp area) @@ -293,7 +292,7 @@ public class FactionsListenerMain implements Listener { // If a player was kicked from the server ... Player player = event.getPlayer(); - FPlayer fplayer = FPlayerColl.get().get(player); + FPlayer fplayer = FPlayer.get(player); // ... and if the if player was banned (not just kicked) ... if (!event.getReason().equals("Banned by admin.")) return; @@ -332,7 +331,7 @@ public class FactionsListenerMain implements Listener { // If a player is trying to run a command ... Player player = event.getPlayer(); - FPlayer fplayer = FPlayerColl.get().get(player); + FPlayer fplayer = FPlayer.get(player); // ... and the player does not have adminmode ... if (fplayer.isUsingAdminMode()) return; @@ -351,7 +350,7 @@ public class FactionsListenerMain implements Listener } Rel rel = fplayer.getRelationToLocation(); - if (BoardColl.get().getFactionAt(fplayer.getCurrentChunk()).isNone()) return; + if (BoardColls.get().getFactionAt(fplayer.getCurrentChunk()).isNone()) return; if (rel == Rel.NEUTRAL && containsCommand(command, ConfServer.territoryNeutralDenyCommands)) { @@ -398,7 +397,7 @@ public class FactionsListenerMain implements Listener // ... at a place where monsters are forbidden ... PS ps = PS.valueOf(event.getLocation()); - Faction faction = BoardColl.get().getFactionAt(ps); + Faction faction = BoardColls.get().getFactionAt(ps); if (faction.getFlag(FFlag.MONSTERS)) return; // ... block the spawn. @@ -413,7 +412,7 @@ public class FactionsListenerMain implements Listener // ... at a place where monsters are forbidden ... PS ps = PS.valueOf(event.getTarget()); - Faction faction = BoardColl.get().getFactionAt(ps); + Faction faction = BoardColls.get().getFactionAt(ps); if (faction.getFlag(FFlag.MONSTERS)) return; // ... then if ghast target nothing ... @@ -438,7 +437,7 @@ public class FactionsListenerMain implements Listener if (event.getCause() != RemoveCause.EXPLOSION) return; // ... and the faction there has explosions disabled ... - Faction faction = BoardColl.get().getFactionAt(PS.valueOf(event.getEntity())); + Faction faction = BoardColls.get().getFactionAt(PS.valueOf(event.getEntity())); if (faction.getFlag(FFlag.EXPLOSIONS)) return; // ... then cancel. @@ -453,12 +452,12 @@ public class FactionsListenerMain implements Listener while (iter.hasNext()) { Block block = iter.next(); - Faction faction = BoardColl.get().getFactionAt(PS.valueOf(block)); + Faction faction = BoardColls.get().getFactionAt(PS.valueOf(block)); if (faction.getFlag(FFlag.EXPLOSIONS) == false) iter.remove(); } // Check the entity. Are explosions disabled there? - if (BoardColl.get().getFactionAt(PS.valueOf(event.getEntity())).getFlag(FFlag.EXPLOSIONS) == false) + if (BoardColls.get().getFactionAt(PS.valueOf(event.getEntity())).getFlag(FFlag.EXPLOSIONS) == false) { event.setCancelled(true); } @@ -473,7 +472,7 @@ public class FactionsListenerMain implements Listener // ... and the faction there has explosions disabled ... PS ps = PS.valueOf(event.getBlock()); - Faction faction = BoardColl.get().getFactionAt(ps); + Faction faction = BoardColls.get().getFactionAt(ps); if (faction.getFlag(FFlag.EXPLOSIONS)) return; // ... stop the block alteration. @@ -493,7 +492,7 @@ public class FactionsListenerMain implements Listener // ... and the faction there has endergrief disabled ... PS ps = PS.valueOf(event.getBlock()); - Faction faction = BoardColl.get().getFactionAt(ps); + Faction faction = BoardColls.get().getFactionAt(ps); if (faction.getFlag(FFlag.ENDERGRIEF)) return; // ... stop the block alteration. @@ -512,7 +511,7 @@ public class FactionsListenerMain implements Listener FPlayer me = FPlayer.get(name); if (me.isUsingAdminMode()) return true; - Faction factionHere = BoardColl.get().getFactionAt(ps); + Faction factionHere = BoardColls.get().getFactionAt(ps); if ( ! FPerm.BUILD.has(me, ps) && FPerm.PAINBUILD.has(me, ps)) { @@ -585,13 +584,13 @@ public class FactionsListenerMain implements Listener { if ( ! ConfServer.pistonProtectionThroughDenyBuild) return; - Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock())); + Faction pistonFaction = BoardColls.get().getFactionAt(PS.valueOf(event.getBlock())); // target end-of-the-line empty (air) block which is being pushed into, including if piston itself would extend into air Block targetBlock = event.getBlock().getRelative(event.getDirection(), event.getLength() + 1); // members of faction might not have build rights in their own territory, but pistons should still work regardless; so, address that corner case - Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(targetBlock)); + Faction targetFaction = BoardColls.get().getFactionAt(PS.valueOf(targetBlock)); if (targetFaction == pistonFaction) return; // if potentially pushing into air/water/lava in another territory, we need to check it out @@ -620,10 +619,10 @@ public class FactionsListenerMain implements Listener // if potentially retracted block is just air/water/lava, no worries if (targetLoc.getBlock().isEmpty() || targetLoc.getBlock().isLiquid()) return; - Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock())); + Faction pistonFaction = BoardColls.get().getFactionAt(PS.valueOf(event.getBlock())); // members of faction might not have build rights in their own territory, but pistons should still work regardless; so, address that corner case - Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(targetLoc)); + Faction targetFaction = BoardColls.get().getFactionAt(PS.valueOf(targetLoc)); if (targetFaction == pistonFaction) return; if ( ! FPerm.BUILD.has(pistonFaction, targetLoc)) @@ -640,7 +639,7 @@ public class FactionsListenerMain implements Listener { // If the faction at the block has firespread disabled ... PS ps = PS.valueOf(block); - Faction faction = BoardColl.get().getFactionAt(ps); + Faction faction = BoardColls.get().getFactionAt(ps); if (faction.getFlag(FFlag.FIRESPREAD)) return; // then cancel the event. diff --git a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java index 5d4e6d16..2094c5ea 100644 --- a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java @@ -17,9 +17,8 @@ import org.bukkit.event.player.PlayerMoveEvent; import com.massivecraft.factions.Const; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.FPlayer; -import com.massivecraft.factions.entity.FPlayerColl; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.mcore.event.MCorePlayerLeaveEvent; @@ -34,7 +33,7 @@ public class TodoFactionsPlayerListener implements Listener { // If a player is joining the server ... Player player = event.getPlayer(); - FPlayer fplayer = FPlayerColl.get().get(player); + FPlayer fplayer = FPlayer.get(player); // ... recalculate their power as if they were offline since last recalculation ... fplayer.recalculatePower(false); @@ -53,7 +52,7 @@ public class TodoFactionsPlayerListener implements Listener public void onPlayerLeave(MCorePlayerLeaveEvent event) { Player player = event.getPlayer(); - FPlayer fplayer = FPlayerColl.get().get(player); + FPlayer fplayer = FPlayer.get(player); // Recalculate the power before the player leaves. // This is required since we recalculate as if the player were offline when they log back in. @@ -71,7 +70,7 @@ public class TodoFactionsPlayerListener implements Listener // ... update the stored current chunk ... Player player = event.getPlayer(); - FPlayer fplayer = FPlayerColl.get().get(player); + FPlayer fplayer = FPlayer.get(player); PS chunkFrom = fplayer.getCurrentChunk(); PS chunkTo = PS.valueOf(event.getTo()).getChunk(true); @@ -80,17 +79,17 @@ public class TodoFactionsPlayerListener implements Listener // ... TODO: assorted and uncleaned code below ... - TerritoryAccess access = BoardColl.get().getTerritoryAccessAt(chunkTo); + TerritoryAccess access = BoardColls.get().getTerritoryAccessAt(chunkTo); // Did we change "host"(faction)? - boolean changedFaction = (BoardColl.get().getFactionAt(chunkFrom) != access.getHostFaction()); + boolean changedFaction = (BoardColls.get().getFactionAt(chunkFrom) != access.getHostFaction()); // let Spout handle most of this if it's available boolean handledBySpout = changedFaction && SpoutFeatures.updateTerritoryDisplay(fplayer); if (fplayer.isMapAutoUpdating()) { - fplayer.sendMessage(BoardColl.get().getMap(fplayer.getFaction(), chunkTo, player.getLocation().getYaw())); + fplayer.sendMessage(BoardColls.get().getMap(fplayer.getFaction(), chunkTo, player.getLocation().getYaw())); } else if (changedFaction && ! handledBySpout) { @@ -146,7 +145,7 @@ public class TodoFactionsPlayerListener implements Listener String name = player.getName(); if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true; - FPlayer me = FPlayerColl.get().get(name); + FPlayer me = FPlayer.get(name); if (me.isUsingAdminMode()) return true; if (Const.MATERIALS_EDIT_TOOLS.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false; return true; @@ -156,7 +155,7 @@ public class TodoFactionsPlayerListener implements Listener String name = player.getName(); if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true; - FPlayer me = FPlayerColl.get().get(name); + FPlayer me = FPlayer.get(name); if (me.isUsingAdminMode()) return true; Location loc = block.getLocation(); Material material = block.getType(); diff --git a/src/com/massivecraft/factions/task/AutoLeaveTask.java b/src/com/massivecraft/factions/task/AutoLeaveTask.java index 369b3c43..7127d16d 100644 --- a/src/com/massivecraft/factions/task/AutoLeaveTask.java +++ b/src/com/massivecraft/factions/task/AutoLeaveTask.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.task; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.entity.FPlayerColl; +import com.massivecraft.factions.entity.FPlayerColls; import com.massivecraft.mcore.ModuloRepeatTask; import com.massivecraft.mcore.util.TimeUnit; @@ -33,7 +34,10 @@ public class AutoLeaveTask extends ModuloRepeatTask @Override public void invoke() { - FPlayerColl.get().autoLeaveOnInactivityRoutine(); + for (FPlayerColl coll : FPlayerColls.get().getColls()) + { + coll.autoLeaveOnInactivityRoutine(); + } } } diff --git a/src/com/massivecraft/factions/task/EconLandRewardTask.java b/src/com/massivecraft/factions/task/EconLandRewardTask.java index 18027795..f2367078 100644 --- a/src/com/massivecraft/factions/task/EconLandRewardTask.java +++ b/src/com/massivecraft/factions/task/EconLandRewardTask.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.task; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.FactionColls; import com.massivecraft.mcore.ModuloRepeatTask; import com.massivecraft.mcore.util.TimeUnit; @@ -33,7 +34,10 @@ public class EconLandRewardTask extends ModuloRepeatTask @Override public void invoke() { - FactionColl.get().econLandRewardRoutine(); + for (FactionColl coll : FactionColls.get().getColls()) + { + coll.econLandRewardRoutine(); + } } }