Add proper handling of universes in Factions

This commit is contained in:
Mike Primm 2013-06-28 01:33:54 -05:00
parent 036092f53f
commit afd5d32f05

View File

@ -14,7 +14,6 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -34,8 +33,6 @@ import org.dynmap.markers.PlayerSet;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FFlag; 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.BoardColls;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.FactionColl;
@ -146,18 +143,20 @@ public class DynmapFactionsPlugin extends JavaPlugin {
private class PlayerSetUpdate implements Runnable { private class PlayerSetUpdate implements Runnable {
public String faction; public String faction;
public PlayerSetUpdate(String fid) { public String univ;
public PlayerSetUpdate(String univ, String fid) {
this.univ = univ;
faction = fid; faction = fid;
} }
public void run() { public void run() {
if(!stop) if(!stop)
updatePlayerSet(faction); updatePlayerSet(univ, faction);
} }
} }
private void requestUpdatePlayerSet(String factid) { private void requestUpdatePlayerSet(String univid, String factid) {
if(playersets) if(playersets)
getServer().getScheduler().scheduleSyncDelayedTask(this, new PlayerSetUpdate(factid)); getServer().getScheduler().scheduleSyncDelayedTask(this, new PlayerSetUpdate(univid, factid));
} }
private FactionsUpdate pending = null; 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 Wilderness or other unassociated factions, skip */
if(factid.equals("0") || factid.startsWith("-")) { if(factid.equals("0") || factid.startsWith("-")) {
return; return;
} }
Set<String> plids = new HashSet<String>(); Set<String> plids = new HashSet<String>();
FactionColl fc = FactionColls.get().get(getServer().getConsoleSender()); FactionColl fc = FactionColls.get().getForUniverse(univid);
Faction f = fc.getByName(factid); /* Get faction */ Faction f = fc.getByName(factid); /* Get faction */
if(f != null) { if(f != null) {
@ -186,11 +185,11 @@ public class DynmapFactionsPlugin extends JavaPlugin {
} }
factid = f.getId(); factid = f.getId();
} }
String setid = "factions." + factid; String setid = "factions." + univid + "." + factid;
PlayerSet set = markerapi.getPlayerSet(setid); /* See if set exists */ PlayerSet set = markerapi.getPlayerSet(setid); /* See if set exists */
if((set == null) && (f != null)) { if((set == null) && (f != null)) {
set = markerapi.createPlayerSet(setid, true, plids, false); 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) { else if(f != null) {
set.setPlayers(plids); set.setPlayers(plids);
@ -470,67 +469,68 @@ public class DynmapFactionsPlugin extends JavaPlugin {
/* Parse into faction centric mapping, split by world */ /* Parse into faction centric mapping, split by world */
Map<String, FactionBlocks> blocks_by_faction = new HashMap<String, FactionBlocks>(); Map<String, FactionBlocks> blocks_by_faction = new HashMap<String, FactionBlocks>();
FactionColl fc = FactionColls.get().get(getServer().getConsoleSender());
Collection<Faction> facts = fc.getAll();
for (Faction fact : facts) { for (FactionColl fc : FactionColls.get().getColls()) {
Set<PS> chunks = BoardColls.get().getChunks(fact); Collection<Faction> facts = fc.getAll();
String fid = fact.getId(); for (Faction fact : facts) {
FactionBlocks factblocks = blocks_by_faction.get(fid); /* Look up faction */ Set<PS> chunks = BoardColls.get().getChunks(fact);
if(factblocks == null) { /* Create faction block if first time */ String fid = fc.getUniverse() + "_" + fact.getId();
factblocks = new FactionBlocks(); FactionBlocks factblocks = blocks_by_faction.get(fid); /* Look up faction */
blocks_by_faction.put(fid, factblocks); 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<FactionBlock> blocks = factblocks.blocks.get(world);
if(blocks == null) {
blocks = new LinkedList<FactionBlock>();
factblocks.blocks.put(world, blocks);
} }
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 (PS cc : chunks) {
for(Map.Entry<String, LinkedList<FactionBlock>> worldblocks : factblocks.blocks.entrySet()) { String world = cc.getWorld();
handleFactionOnWorld(factname, fact, worldblocks.getKey(), worldblocks.getValue(), newmap, newmark);
}
factblocks.blocks.clear();
/* Now, add marker for home location */ /* Get block set for given world */
PS homeloc = fact.getHome(); LinkedList<FactionBlock> blocks = factblocks.blocks.get(world);
if(homeloc != null) { if(blocks == null) {
String markid = factname + "__home"; blocks = new LinkedList<FactionBlock>();
MarkerIcon ico = getMarkerIcon(factname, fact); factblocks.blocks.put(world, blocks);
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 { FactionBlock fb = new FactionBlock();
home.setLocation(homeloc.getWorld(), homeloc.getBlockX(), homeloc.getBlockY(), homeloc.getBlockZ()); fb.x = cc.getChunkX();
home.setLabel(lbl); /* Update label */ fb.z = cc.getChunkZ();
home.setMarkerIcon(ico); blocks.add(fb); /* Add to list */
}
home.setDescription(formatInfoWindow(fact)); /* Set popup */
newmark.put(markid, home);
} }
} }
/* 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<String, LinkedList<FactionBlock>> 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(); blocks_by_faction.clear();
@ -549,9 +549,10 @@ public class DynmapFactionsPlugin extends JavaPlugin {
private void updatePlayerSets() { private void updatePlayerSets() {
if(playersets) { if(playersets) {
FactionColl fc = FactionColls.get().get(getServer().getConsoleSender()); for (FactionColl fc : FactionColls.get().getColls()) {
for(Faction f : fc.getAll()) { for(Faction f : fc.getAll()) {
updatePlayerSet(f.getId()); updatePlayerSet(fc.getUniverse(), f.getId());
}
} }
} }
} }
@ -570,23 +571,27 @@ public class DynmapFactionsPlugin extends JavaPlugin {
public void onFPlayerJoin(FactionsEventMembershipChange event) { public void onFPlayerJoin(FactionsEventMembershipChange event) {
if(event.isCancelled()) if(event.isCancelled())
return; return;
if(playersets) if(playersets) {
requestUpdatePlayerSet(event.getNewFaction().getId()); Faction f = event.getNewFaction();
requestUpdatePlayerSet(f.getUniverse(), f.getId());
}
} }
@EventHandler(priority=EventPriority.MONITOR) @EventHandler(priority=EventPriority.MONITOR)
public void onFactionCreate(FactionsEventCreate event) { public void onFactionCreate(FactionsEventCreate event) {
if(event.isCancelled()) if(event.isCancelled())
return; return;
if(playersets) if(playersets)
requestUpdatePlayerSet(event.getFactionId()); requestUpdatePlayerSet(event.getUniverse(), event.getFactionId());
requestUpdateFactions(); requestUpdateFactions();
} }
@EventHandler(priority=EventPriority.MONITOR) @EventHandler(priority=EventPriority.MONITOR)
public void onFactionDisband(FactionsEventDisband event) { public void onFactionDisband(FactionsEventDisband event) {
if(event.isCancelled()) if(event.isCancelled())
return; return;
if(playersets) if(playersets) {
requestUpdatePlayerSet(event.getFaction().getId()); Faction f = event.getFaction();
requestUpdatePlayerSet(f.getUniverse(), f.getId());
}
requestUpdateFactions(); requestUpdateFactions();
} }
@EventHandler(priority=EventPriority.MONITOR) @EventHandler(priority=EventPriority.MONITOR)