Add visibility-by-faction option (uses dynmap 0.60), add '%flag.FLAGID%' macros, reload support
This commit is contained in:
parent
f0c6419992
commit
467766596e
@ -17,6 +17,7 @@ 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;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -28,11 +29,21 @@ import org.dynmap.markers.Marker;
|
|||||||
import org.dynmap.markers.MarkerAPI;
|
import org.dynmap.markers.MarkerAPI;
|
||||||
import org.dynmap.markers.MarkerIcon;
|
import org.dynmap.markers.MarkerIcon;
|
||||||
import org.dynmap.markers.MarkerSet;
|
import org.dynmap.markers.MarkerSet;
|
||||||
|
import org.dynmap.markers.PlayerSet;
|
||||||
|
|
||||||
import com.massivecraft.factions.FPlayer;
|
import com.massivecraft.factions.FPlayer;
|
||||||
import com.massivecraft.factions.Factions;
|
import com.massivecraft.factions.Factions;
|
||||||
import com.massivecraft.factions.Board;
|
import com.massivecraft.factions.Board;
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
|
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
||||||
|
import com.massivecraft.factions.event.FPlayerLeaveEvent;
|
||||||
|
import com.massivecraft.factions.event.FactionCreateEvent;
|
||||||
|
import com.massivecraft.factions.event.FactionDisbandEvent;
|
||||||
|
import com.massivecraft.factions.event.FactionRenameEvent;
|
||||||
|
import com.massivecraft.factions.event.LandClaimEvent;
|
||||||
|
import com.massivecraft.factions.event.LandUnclaimAllEvent;
|
||||||
|
import com.massivecraft.factions.event.LandUnclaimEvent;
|
||||||
|
import com.massivecraft.factions.struct.FFlag;
|
||||||
import com.massivecraft.factions.struct.TerritoryAccess;
|
import com.massivecraft.factions.struct.TerritoryAccess;
|
||||||
|
|
||||||
public class DynmapFactionsPlugin extends JavaPlugin {
|
public class DynmapFactionsPlugin extends JavaPlugin {
|
||||||
@ -44,6 +55,7 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
|||||||
MarkerAPI markerapi;
|
MarkerAPI markerapi;
|
||||||
Plugin factions;
|
Plugin factions;
|
||||||
Factions factapi;
|
Factions factapi;
|
||||||
|
boolean playersets;
|
||||||
|
|
||||||
int blocksize;
|
int blocksize;
|
||||||
|
|
||||||
@ -108,9 +120,62 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class FactionsUpdate implements Runnable {
|
private class FactionsUpdate implements Runnable {
|
||||||
|
public boolean runonce;
|
||||||
|
public void run() {
|
||||||
|
if(!stop) {
|
||||||
|
updateFactions();
|
||||||
|
if(!runonce) {
|
||||||
|
getServer().getScheduler().scheduleSyncDelayedTask(DynmapFactionsPlugin.this, this, updperiod);
|
||||||
|
}
|
||||||
|
else if(pending == this) {
|
||||||
|
pending = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class PlayerSetUpdate implements Runnable {
|
||||||
|
public String faction;
|
||||||
|
public PlayerSetUpdate(String fid) {
|
||||||
|
faction = fid;
|
||||||
|
}
|
||||||
public void run() {
|
public void run() {
|
||||||
if(!stop)
|
if(!stop)
|
||||||
updateFactions();
|
updatePlayerSet(faction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void requestUpdatePlayerSet(String factid) {
|
||||||
|
if(playersets)
|
||||||
|
getServer().getScheduler().scheduleSyncDelayedTask(this, new PlayerSetUpdate(factid));
|
||||||
|
}
|
||||||
|
|
||||||
|
private FactionsUpdate pending = null;
|
||||||
|
|
||||||
|
private void requestUpdateFactions() {
|
||||||
|
if(pending == null) {
|
||||||
|
FactionsUpdate upd = new FactionsUpdate();
|
||||||
|
upd.runonce = true;
|
||||||
|
getServer().getScheduler().scheduleSyncDelayedTask(this, upd, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePlayerSet(String factid) {
|
||||||
|
Set<String> plids = new HashSet<String>();
|
||||||
|
Faction f = factapi.get(factid); /* Get faction */
|
||||||
|
if(f != null) {
|
||||||
|
Set<FPlayer> ps = f.getFPlayers();
|
||||||
|
for(FPlayer fp : ps) {
|
||||||
|
plids.add(fp.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String setid = "factions." + factid;
|
||||||
|
PlayerSet set = markerapi.getPlayerSet(setid); /* See if set exists */
|
||||||
|
if(set == null) {
|
||||||
|
set = markerapi.createPlayerSet(setid, true, plids, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
set.setPlayers(plids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +185,7 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
|||||||
private String formatInfoWindow(Faction fact) {
|
private String formatInfoWindow(Faction fact) {
|
||||||
String v = "<div class=\"regioninfo\">"+infowindow+"</div>";
|
String v = "<div class=\"regioninfo\">"+infowindow+"</div>";
|
||||||
v = v.replaceAll("%regionname%", ChatColor.stripColor(fact.getTag()));
|
v = v.replaceAll("%regionname%", ChatColor.stripColor(fact.getTag()));
|
||||||
FPlayer adm = fact.getFPlayerAdmin();
|
FPlayer adm = fact.getFPlayerLeader();
|
||||||
v = v.replaceAll("%playerowners%", (adm!=null)?adm.getName():"");
|
v = v.replaceAll("%playerowners%", (adm!=null)?adm.getName():"");
|
||||||
String res = "";
|
String res = "";
|
||||||
for(FPlayer r : fact.getFPlayers()) {
|
for(FPlayer r : fact.getFPlayers()) {
|
||||||
@ -132,8 +197,10 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
|||||||
v = v.replaceAll("%nation%", ChatColor.stripColor(fact.getTag()));
|
v = v.replaceAll("%nation%", ChatColor.stripColor(fact.getTag()));
|
||||||
/* Build flags */
|
/* Build flags */
|
||||||
String flgs = "open: " + fact.getOpen();
|
String flgs = "open: " + fact.getOpen();
|
||||||
flgs += "<br/>peaceful: " + fact.isPeaceful();
|
for(FFlag ff : FFlag.values()) {
|
||||||
flgs += "<br/>peacefulExplosionsEnabled: " + fact.getPeacefulExplosionsEnabled();
|
flgs += "<br/>" + ff.getNicename() + ": " + fact.getFlag(ff);
|
||||||
|
v = v.replaceAll("%flag." + ff.name() + "%", fact.getFlag(ff)?"true":"false");
|
||||||
|
}
|
||||||
v = v.replaceAll("%flags%", flgs);
|
v = v.replaceAll("%flags%", flgs);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@ -468,12 +535,17 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
|||||||
resareas = newmap;
|
resareas = newmap;
|
||||||
resmark = newmark;
|
resmark = newmark;
|
||||||
|
|
||||||
getServer().getScheduler().scheduleSyncDelayedTask(this, new FactionsUpdate(), updperiod);
|
}
|
||||||
|
|
||||||
|
private void updatePlayerSets() {
|
||||||
|
if(playersets) {
|
||||||
|
for(Faction f : factapi.get()) {
|
||||||
|
updatePlayerSet(f.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class OurServerListener implements Listener {
|
private class OurServerListener implements Listener {
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPluginEnable(PluginEnableEvent event) {
|
public void onPluginEnable(PluginEnableEvent event) {
|
||||||
Plugin p = event.getPlugin();
|
Plugin p = event.getPlugin();
|
||||||
@ -483,6 +555,58 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
|||||||
activate();
|
activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@EventHandler(priority=EventPriority.MONITOR)
|
||||||
|
public void onFPlayerJoin(FPlayerJoinEvent event) {
|
||||||
|
if(event.isCancelled())
|
||||||
|
return;
|
||||||
|
if(playersets)
|
||||||
|
requestUpdatePlayerSet(event.getFaction().getId());
|
||||||
|
}
|
||||||
|
@EventHandler(priority=EventPriority.MONITOR)
|
||||||
|
public void onFPlayerLeave(FPlayerLeaveEvent event) {
|
||||||
|
if(event.isCancelled())
|
||||||
|
return;
|
||||||
|
if(playersets)
|
||||||
|
requestUpdatePlayerSet(event.getFaction().getId());
|
||||||
|
}
|
||||||
|
@EventHandler(priority=EventPriority.MONITOR)
|
||||||
|
public void onFactionCreate(FactionCreateEvent event) {
|
||||||
|
if(event.isCancelled())
|
||||||
|
return;
|
||||||
|
if(playersets)
|
||||||
|
requestUpdatePlayerSet(event.getFactionId());
|
||||||
|
requestUpdateFactions();
|
||||||
|
}
|
||||||
|
@EventHandler(priority=EventPriority.MONITOR)
|
||||||
|
public void onFactionDisband(FactionDisbandEvent event) {
|
||||||
|
if(event.isCancelled())
|
||||||
|
return;
|
||||||
|
if(playersets)
|
||||||
|
requestUpdatePlayerSet(event.getFaction().getId());
|
||||||
|
requestUpdateFactions();
|
||||||
|
}
|
||||||
|
@EventHandler(priority=EventPriority.MONITOR)
|
||||||
|
public void onFactionRename(FactionRenameEvent event) {
|
||||||
|
if(event.isCancelled())
|
||||||
|
return;
|
||||||
|
requestUpdateFactions();
|
||||||
|
}
|
||||||
|
@EventHandler(priority=EventPriority.MONITOR)
|
||||||
|
public void onLandClaim(LandClaimEvent event) {
|
||||||
|
if(event.isCancelled())
|
||||||
|
return;
|
||||||
|
requestUpdateFactions();
|
||||||
|
}
|
||||||
|
@EventHandler(priority=EventPriority.MONITOR)
|
||||||
|
public void onLandUnclaim(LandUnclaimEvent event) {
|
||||||
|
if(event.isCancelled())
|
||||||
|
return;
|
||||||
|
requestUpdateFactions();
|
||||||
|
}
|
||||||
|
@EventHandler(priority=EventPriority.MONITOR)
|
||||||
|
public void onLandUnclaimAll(LandUnclaimAllEvent event) {
|
||||||
|
requestUpdateFactions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -510,6 +634,8 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
|||||||
activate();
|
activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean reload = false;
|
||||||
|
|
||||||
private void activate() {
|
private void activate() {
|
||||||
markerapi = api.getMarkerAPI();
|
markerapi = api.getMarkerAPI();
|
||||||
if(markerapi == null) {
|
if(markerapi == null) {
|
||||||
@ -522,6 +648,12 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
|||||||
blocksize = 16; /* Fixed at 16 */
|
blocksize = 16; /* Fixed at 16 */
|
||||||
|
|
||||||
/* Load configuration */
|
/* Load configuration */
|
||||||
|
if(reload) {
|
||||||
|
this.reloadConfig();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reload = true;
|
||||||
|
}
|
||||||
FileConfiguration cfg = getConfig();
|
FileConfiguration cfg = getConfig();
|
||||||
cfg.options().copyDefaults(true); /* Load defaults, if needed */
|
cfg.options().copyDefaults(true); /* Load defaults, if needed */
|
||||||
this.saveConfig(); /* Save updates, if needed */
|
this.saveConfig(); /* Save updates, if needed */
|
||||||
@ -563,6 +695,17 @@ public class DynmapFactionsPlugin extends JavaPlugin {
|
|||||||
if(hid != null) {
|
if(hid != null) {
|
||||||
hidden = new HashSet<String>(hid);
|
hidden = new HashSet<String>(hid);
|
||||||
}
|
}
|
||||||
|
/* Chec if player sets enabled */
|
||||||
|
playersets = cfg.getBoolean("visibility-by-faction", false);
|
||||||
|
if(playersets) {
|
||||||
|
try {
|
||||||
|
markerapi.getPlayerSets(); /* Test if API available on dynmap */
|
||||||
|
} catch (Exception x) {
|
||||||
|
playersets = false;
|
||||||
|
log.info("Dynmap does not support function needed for 'visibilitybyfaction' - need to upgrade");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updatePlayerSets();
|
||||||
|
|
||||||
/* Set up update job - based on periond */
|
/* Set up update job - based on periond */
|
||||||
int per = cfg.getInt("update.period", 300);
|
int per = cfg.getInt("update.period", 300);
|
||||||
|
@ -16,6 +16,9 @@ layer:
|
|||||||
# Format for popup - substitute values for macros
|
# Format for popup - substitute values for macros
|
||||||
infowindow: '<div class="infowindow"><span style="font-size:120%;">%regionname%</span><br />Flags<br /><span style="font-weight:bold;">%flags%</span></div>'
|
infowindow: '<div class="infowindow"><span style="font-size:120%;">%regionname%</span><br />Flags<br /><span style="font-weight:bold;">%flags%</span></div>'
|
||||||
|
|
||||||
|
# Allow players in faction to see one another on dynmap (only relevant if dynmap has 'player-info-protected' enabled)
|
||||||
|
visibility-by-faction: true
|
||||||
|
|
||||||
regionstyle:
|
regionstyle:
|
||||||
strokeColor: "#FF0000"
|
strokeColor: "#FF0000"
|
||||||
strokeOpacity: 0.8
|
strokeOpacity: 0.8
|
||||||
|
Loading…
Reference in New Issue
Block a user