From afd5d32f05585e0a7d121ecff3ceea16ec49be99 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 28 Jun 2013 01:33:54 -0500 Subject: [PATCH] Add proper handling of universes in Factions --- .../dynmap/factions/DynmapFactionsPlugin.java | 155 +++++++++--------- 1 file changed, 80 insertions(+), 75 deletions(-) diff --git a/src/main/java/org/dynmap/factions/DynmapFactionsPlugin.java b/src/main/java/org/dynmap/factions/DynmapFactionsPlugin.java index 457159d..6a2119a 100644 --- a/src/main/java/org/dynmap/factions/DynmapFactionsPlugin.java +++ b/src/main/java/org/dynmap/factions/DynmapFactionsPlugin.java @@ -14,7 +14,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.ChatColor; -import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.event.EventHandler; @@ -34,8 +33,6 @@ import org.dynmap.markers.PlayerSet; import com.massivecraft.factions.Factions; import com.massivecraft.factions.FFlag; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.entity.Board; import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.FactionColl; @@ -146,18 +143,20 @@ public class DynmapFactionsPlugin extends JavaPlugin { private class PlayerSetUpdate implements Runnable { public String faction; - public PlayerSetUpdate(String fid) { + public String univ; + public PlayerSetUpdate(String univ, String fid) { + this.univ = univ; faction = fid; } public void run() { if(!stop) - updatePlayerSet(faction); + updatePlayerSet(univ, faction); } } - private void requestUpdatePlayerSet(String factid) { + private void requestUpdatePlayerSet(String univid, String factid) { if(playersets) - getServer().getScheduler().scheduleSyncDelayedTask(this, new PlayerSetUpdate(factid)); + getServer().getScheduler().scheduleSyncDelayedTask(this, new PlayerSetUpdate(univid, factid)); } private FactionsUpdate pending = null; @@ -170,13 +169,13 @@ public class DynmapFactionsPlugin extends JavaPlugin { } } - private void updatePlayerSet(String factid) { + private void updatePlayerSet(String univid, String factid) { /* If Wilderness or other unassociated factions, skip */ if(factid.equals("0") || factid.startsWith("-")) { return; } Set plids = new HashSet(); - FactionColl fc = FactionColls.get().get(getServer().getConsoleSender()); + FactionColl fc = FactionColls.get().getForUniverse(univid); Faction f = fc.getByName(factid); /* Get faction */ if(f != null) { @@ -186,11 +185,11 @@ public class DynmapFactionsPlugin extends JavaPlugin { } factid = f.getId(); } - String setid = "factions." + factid; + String setid = "factions." + univid + "." + factid; PlayerSet set = markerapi.getPlayerSet(setid); /* See if set exists */ if((set == null) && (f != null)) { set = markerapi.createPlayerSet(setid, true, plids, false); - info("Added player visibility set '" + setid + "' for faction " + factid); + info("Added player visibility set '" + setid + "' for faction " + univid + "." + factid); } else if(f != null) { set.setPlayers(plids); @@ -470,67 +469,68 @@ public class DynmapFactionsPlugin extends JavaPlugin { /* Parse into faction centric mapping, split by world */ Map blocks_by_faction = new HashMap(); - FactionColl fc = FactionColls.get().get(getServer().getConsoleSender()); - Collection facts = fc.getAll(); - - for (Faction fact : facts) { - Set chunks = BoardColls.get().getChunks(fact); - String fid = fact.getId(); - FactionBlocks factblocks = blocks_by_faction.get(fid); /* Look up faction */ - if(factblocks == null) { /* Create faction block if first time */ - factblocks = new FactionBlocks(); - blocks_by_faction.put(fid, factblocks); - } - - for (PS cc : chunks) { - String world = cc.getWorld(); - - /* Get block set for given world */ - LinkedList blocks = factblocks.blocks.get(world); - if(blocks == null) { - blocks = new LinkedList(); - factblocks.blocks.put(world, blocks); + + for (FactionColl fc : FactionColls.get().getColls()) { + Collection facts = fc.getAll(); + for (Faction fact : facts) { + Set chunks = BoardColls.get().getChunks(fact); + String fid = fc.getUniverse() + "_" + fact.getId(); + FactionBlocks factblocks = blocks_by_faction.get(fid); /* Look up faction */ + if(factblocks == null) { /* Create faction block if first time */ + factblocks = new FactionBlocks(); + blocks_by_faction.put(fid, factblocks); } - FactionBlock fb = new FactionBlock(); - fb.x = cc.getChunkX(); - fb.z = cc.getChunkZ(); - blocks.add(fb); /* Add to list */ - } - } - /* Loop through factions */ - for(Faction fact : facts) { - String factname = ChatColor.stripColor(fact.getName()); - FactionBlocks factblocks = blocks_by_faction.get(fact.getId()); /* Look up faction */ - if (factblocks == null) continue; - - /* Loop through each world that faction has blocks on */ - for(Map.Entry> worldblocks : factblocks.blocks.entrySet()) { - handleFactionOnWorld(factname, fact, worldblocks.getKey(), worldblocks.getValue(), newmap, newmark); - } - factblocks.blocks.clear(); - - /* Now, add marker for home location */ - PS homeloc = fact.getHome(); - if(homeloc != null) { - String markid = factname + "__home"; - MarkerIcon ico = getMarkerIcon(factname, fact); - if(ico != null) { - Marker home = resmark.remove(markid); - String lbl = factname + " [home]"; - if(home == null) { - home = set.createMarker(markid, lbl, homeloc.getWorld(), - homeloc.getBlockX(), homeloc.getBlockY(), homeloc.getBlockZ(), ico, false); + + for (PS cc : chunks) { + String world = cc.getWorld(); + + /* Get block set for given world */ + LinkedList blocks = factblocks.blocks.get(world); + if(blocks == null) { + blocks = new LinkedList(); + factblocks.blocks.put(world, blocks); } - else { - home.setLocation(homeloc.getWorld(), homeloc.getBlockX(), homeloc.getBlockY(), homeloc.getBlockZ()); - home.setLabel(lbl); /* Update label */ - home.setMarkerIcon(ico); - } - home.setDescription(formatInfoWindow(fact)); /* Set popup */ - newmark.put(markid, home); + FactionBlock fb = new FactionBlock(); + fb.x = cc.getChunkX(); + fb.z = cc.getChunkZ(); + blocks.add(fb); /* Add to list */ } } + /* Loop through factions */ + for(Faction fact : facts) { + String factname = ChatColor.stripColor(fact.getName()); + String fid = fc.getUniverse() + "_" + fact.getId(); + FactionBlocks factblocks = blocks_by_faction.get(fid); /* Look up faction */ + if (factblocks == null) continue; + /* Loop through each world that faction has blocks on */ + for(Map.Entry> worldblocks : factblocks.blocks.entrySet()) { + handleFactionOnWorld(factname, fact, worldblocks.getKey(), worldblocks.getValue(), newmap, newmark); + } + factblocks.blocks.clear(); + + /* Now, add marker for home location */ + PS homeloc = fact.getHome(); + if(homeloc != null) { + String markid = factname + "__home"; + MarkerIcon ico = getMarkerIcon(factname, fact); + if(ico != null) { + Marker home = resmark.remove(markid); + String lbl = factname + " [home]"; + if(home == null) { + home = set.createMarker(markid, lbl, homeloc.getWorld(), + homeloc.getBlockX(), homeloc.getBlockY(), homeloc.getBlockZ(), ico, false); + } + else { + home.setLocation(homeloc.getWorld(), homeloc.getBlockX(), homeloc.getBlockY(), homeloc.getBlockZ()); + home.setLabel(lbl); /* Update label */ + home.setMarkerIcon(ico); + } + home.setDescription(formatInfoWindow(fact)); /* Set popup */ + newmark.put(markid, home); + } + } + } } blocks_by_faction.clear(); @@ -549,9 +549,10 @@ public class DynmapFactionsPlugin extends JavaPlugin { private void updatePlayerSets() { if(playersets) { - FactionColl fc = FactionColls.get().get(getServer().getConsoleSender()); - for(Faction f : fc.getAll()) { - updatePlayerSet(f.getId()); + for (FactionColl fc : FactionColls.get().getColls()) { + for(Faction f : fc.getAll()) { + updatePlayerSet(fc.getUniverse(), f.getId()); + } } } } @@ -570,23 +571,27 @@ public class DynmapFactionsPlugin extends JavaPlugin { public void onFPlayerJoin(FactionsEventMembershipChange event) { if(event.isCancelled()) return; - if(playersets) - requestUpdatePlayerSet(event.getNewFaction().getId()); + if(playersets) { + Faction f = event.getNewFaction(); + requestUpdatePlayerSet(f.getUniverse(), f.getId()); + } } @EventHandler(priority=EventPriority.MONITOR) public void onFactionCreate(FactionsEventCreate event) { if(event.isCancelled()) return; if(playersets) - requestUpdatePlayerSet(event.getFactionId()); + requestUpdatePlayerSet(event.getUniverse(), event.getFactionId()); requestUpdateFactions(); } @EventHandler(priority=EventPriority.MONITOR) public void onFactionDisband(FactionsEventDisband event) { if(event.isCancelled()) return; - if(playersets) - requestUpdatePlayerSet(event.getFaction().getId()); + if(playersets) { + Faction f = event.getFaction(); + requestUpdatePlayerSet(f.getUniverse(), f.getId()); + } requestUpdateFactions(); } @EventHandler(priority=EventPriority.MONITOR)