Add proper handling of universes in Factions
This commit is contained in:
parent
036092f53f
commit
afd5d32f05
@ -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,12 +469,12 @@ 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 (FactionColl fc : FactionColls.get().getColls()) {
|
||||||
|
Collection<Faction> facts = fc.getAll();
|
||||||
for (Faction fact : facts) {
|
for (Faction fact : facts) {
|
||||||
Set<PS> chunks = BoardColls.get().getChunks(fact);
|
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 */
|
FactionBlocks factblocks = blocks_by_faction.get(fid); /* Look up faction */
|
||||||
if(factblocks == null) { /* Create faction block if first time */
|
if(factblocks == null) { /* Create faction block if first time */
|
||||||
factblocks = new FactionBlocks();
|
factblocks = new FactionBlocks();
|
||||||
@ -500,7 +499,8 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
|||||||
/* Loop through factions */
|
/* Loop through factions */
|
||||||
for(Faction fact : facts) {
|
for(Faction fact : facts) {
|
||||||
String factname = ChatColor.stripColor(fact.getName());
|
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;
|
if (factblocks == null) continue;
|
||||||
|
|
||||||
/* Loop through each world that faction has blocks on */
|
/* Loop through each world that faction has blocks on */
|
||||||
@ -530,7 +530,7 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
|||||||
newmark.put(markid, home);
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user