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 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<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 */
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,12 +469,12 @@ public class DynmapFactionsPlugin extends JavaPlugin {
/* Parse into faction centric mapping, split by world */
Map<String, FactionBlocks> blocks_by_faction = new HashMap<String, FactionBlocks>();
FactionColl fc = FactionColls.get().get(getServer().getConsoleSender());
Collection<Faction> facts = fc.getAll();
for (FactionColl fc : FactionColls.get().getColls()) {
Collection<Faction> facts = fc.getAll();
for (Faction fact : facts) {
Set<PS> chunks = BoardColls.get().getChunks(fact);
String fid = fact.getId();
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();
@ -500,7 +499,8 @@ public class DynmapFactionsPlugin extends JavaPlugin {
/* Loop through factions */
for(Faction fact : facts) {
String factname = ChatColor.stripColor(fact.getName());
FactionBlocks factblocks = blocks_by_faction.get(fact.getId()); /* Look up faction */
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 */
@ -530,7 +530,7 @@ public class DynmapFactionsPlugin extends JavaPlugin {
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 (FactionColl fc : FactionColls.get().getColls()) {
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) {
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)