Centralize World class dependencies in DynmapWorld

This commit is contained in:
Mike Primm 2012-01-11 13:33:36 +08:00 committed by mikeprimm
parent 77a6637dbd
commit c681a9284a
10 changed files with 73 additions and 51 deletions

View file

@ -42,10 +42,10 @@ public class ClientConfigurationComponent extends Component {
JSONObject wo = new JSONObject(); JSONObject wo = new JSONObject();
s(wo, "name", wn.getString("name")); s(wo, "name", wn.getString("name"));
s(wo, "title", wn.getString("title")); s(wo, "title", wn.getString("title"));
Location spawn = world.world.getSpawnLocation(); DynmapLocation spawn = world.getSpawnLocation();
s(wo, "center/x", wn.getDouble("center/x", spawn.getX())); s(wo, "center/x", wn.getDouble("center/x", spawn.x));
s(wo, "center/y", wn.getDouble("center/y", spawn.getY())); s(wo, "center/y", wn.getDouble("center/y", spawn.y));
s(wo, "center/z", wn.getDouble("center/z", spawn.getZ())); s(wo, "center/z", wn.getDouble("center/z", spawn.z));
s(wo, "bigworld", world.bigworld); s(wo, "bigworld", world.bigworld);
s(wo, "extrazoomout", world.getExtraZoomOutLevels()); s(wo, "extrazoomout", world.getExtraZoomOutLevels());
a(t, "worlds", wo); a(t, "worlds", wo);
@ -55,7 +55,7 @@ public class ClientConfigurationComponent extends Component {
if(defmap == null) defmap = mt.getName(); if(defmap == null) defmap = mt.getName();
} }
} }
s(t, "defaultworld", c.getString("defaultworld", defaultWorld == null ? "world" : defaultWorld.world.getName())); s(t, "defaultworld", c.getString("defaultworld", defaultWorld == null ? "world" : defaultWorld.getName()));
s(t, "defaultmap", c.getString("defaultmap", defmap == null ? "surface" : defmap)); s(t, "defaultmap", c.getString("defaultmap", defmap == null ? "surface" : defmap));
if(c.getString("followmap", null) != null) if(c.getString("followmap", null) != null)
s(t, "followmap", c.getString("followmap")); s(t, "followmap", c.getString("followmap"));

View file

@ -26,7 +26,7 @@ public class ClientUpdateComponent extends Component {
} }
protected void buildClientUpdate(ClientUpdateEvent e) { protected void buildClientUpdate(ClientUpdateEvent e) {
World world = e.world.world; DynmapWorld world = e.world;
JSONObject u = e.update; JSONObject u = e.update;
long since = e.timestamp; long since = e.timestamp;
String worldName = world.getName(); String worldName = world.getName();

View file

@ -1,5 +1,7 @@
package org.dynmap; package org.dynmap;
import static org.dynmap.JSONUtils.s;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -26,7 +28,7 @@ public class DynmapWorld {
FORMAPONLY, FORMAPONLY,
PERMANENT PERMANENT
} }
public World world; private World world;
public List<MapType> maps = new ArrayList<MapType>(); public List<MapType> maps = new ArrayList<MapType>();
public UpdateQueue updates = new UpdateQueue(); public UpdateQueue updates = new UpdateQueue();
public ConfigurationNode configuration; public ConfigurationNode configuration;
@ -46,7 +48,12 @@ public class DynmapWorld {
private HashSet<String> zoomoutupdates[] = new HashSet[0]; private HashSet<String> zoomoutupdates[] = new HashSet[0];
private boolean checkts = true; /* Check timestamps on first run with new configuration */ private boolean checkts = true; /* Check timestamps on first run with new configuration */
private boolean cancelled; private boolean cancelled;
private String wname;
public DynmapWorld(World w) {
world = w;
wname = w.getName();
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void setExtraZoomOutLevels(int lvl) { public void setExtraZoomOutLevels(int lvl) {
extrazoomoutlevels = lvl; extrazoomoutlevels = lvl;
@ -489,7 +496,7 @@ public class DynmapWorld {
} }
/* Get world name */ /* Get world name */
public String getName() { public String getName() {
return world.getName(); return wname;
} }
/* Get world spawn location */ /* Get world spawn location */
public DynmapLocation getSpawnLocation() { public DynmapLocation getSpawnLocation() {
@ -501,6 +508,22 @@ public class DynmapWorld {
} }
public int hashCode() { public int hashCode() {
return world.hashCode(); return wname.hashCode();
}
public long getTime() {
return world.getTime();
}
public boolean hasStorm() {
return world.hasStorm();
}
public boolean isThundering() {
return world.isThundering();
}
public World getWorld() {
return world;
} }
} }

View file

@ -142,15 +142,13 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
if(plugin.mapManager == null) return; if(plugin.mapManager == null) return;
//Handles Updates //Handles Updates
for (DynmapWorld dynmapWorld : plugin.mapManager.getWorlds()) { for (DynmapWorld dynmapWorld : plugin.mapManager.getWorlds()) {
World world = dynmapWorld.world;
JSONObject update = new JSONObject(); JSONObject update = new JSONObject();
update.put("timestamp", currentTimestamp); update.put("timestamp", currentTimestamp);
ClientUpdateEvent clientUpdate = new ClientUpdateEvent(currentTimestamp - 30000, dynmapWorld, update); ClientUpdateEvent clientUpdate = new ClientUpdateEvent(currentTimestamp - 30000, dynmapWorld, update);
plugin.events.trigger("buildclientupdate", clientUpdate); plugin.events.trigger("buildclientupdate", clientUpdate);
outputFile = getStandaloneFile("dynmap_" + world.getName() + ".json"); outputFile = getStandaloneFile("dynmap_" + dynmapWorld.getName() + ".json");
outputTempFile = getStandaloneFile("dynmap_" + world.getName() + ".json.new"); outputTempFile = getStandaloneFile("dynmap_" + dynmapWorld.getName() + ".json.new");
int retrycnt = 0; int retrycnt = 0;
boolean done = false; boolean done = false;
while(!done) { while(!done) {

View file

@ -350,7 +350,7 @@ public class MapManager {
public HashMap<String,Object> saveState() { public HashMap<String,Object> saveState() {
HashMap<String,Object> v = new HashMap<String,Object>(); HashMap<String,Object> v = new HashMap<String,Object>();
v.put("world", world.world.getName()); v.put("world", world.getName());
v.put("locX", loc.x); v.put("locX", loc.x);
v.put("locY", loc.y); v.put("locY", loc.y);
v.put("locZ", loc.z); v.put("locZ", loc.z);
@ -420,10 +420,10 @@ public class MapManager {
double rendtime = total_render_ns.doubleValue() * 0.000001 / rendercalls.get(); double rendtime = total_render_ns.doubleValue() * 0.000001 / rendercalls.get();
if(activemapcnt > 1) if(activemapcnt > 1)
sendMessage(String.format("%s of maps [%s] of '%s' completed - %d tiles rendered each (%.2f msec/map-tile, %.2f msec per render)", sendMessage(String.format("%s of maps [%s] of '%s' completed - %d tiles rendered each (%.2f msec/map-tile, %.2f msec per render)",
rendertype, activemaps, world.world.getName(), rendercnt, msecpertile, rendtime)); rendertype, activemaps, world.getName(), rendercnt, msecpertile, rendtime));
else else
sendMessage(String.format("%s of map '%s' of '%s' completed - %d tiles rendered (%.2f msec/map-tile, %.2f msec per render)", sendMessage(String.format("%s of map '%s' of '%s' completed - %d tiles rendered (%.2f msec/map-tile, %.2f msec per render)",
rendertype, activemaps, world.world.getName(), rendercnt, msecpertile, rendtime)); rendertype, activemaps, world.getName(), rendercnt, msecpertile, rendtime));
/* Now, if fullrender, use the render bitmap to purge obsolete tiles */ /* Now, if fullrender, use the render bitmap to purge obsolete tiles */
if(rendertype.equals(RENDERTYPE_FULLRENDER)) { if(rendertype.equals(RENDERTYPE_FULLRENDER)) {
if(activemapcnt == 1) { if(activemapcnt == 1) {
@ -458,7 +458,7 @@ public class MapManager {
} }
} }
if(map_index >= world.maps.size()) { /* Last one done? */ if(map_index >= world.maps.size()) { /* Last one done? */
sendMessage(rendertype + " of '" + world.world.getName() + "' finished."); sendMessage(rendertype + " of '" + world.getName() + "' finished.");
cleanup(); cleanup();
return; return;
} }
@ -529,7 +529,6 @@ public class MapManager {
} }
tile = tile0; tile = tile0;
} }
World w = world.world;
boolean notdone = true; boolean notdone = true;
@ -543,14 +542,14 @@ public class MapManager {
final long ts = tstart; final long ts = tstart;
Future<Boolean> future = mapman.render_pool.submit(new Callable<Boolean>() { Future<Boolean> future = mapman.render_pool.submit(new Callable<Boolean>() {
public Boolean call() { public Boolean call() {
return processTile(mt, mt.world.world, ts, cnt); return processTile(mt, ts, cnt);
} }
}); });
rslt.add(future); rslt.add(future);
} }
} }
/* Now, do our render (first one) */ /* Now, do our render (first one) */
notdone = processTile(tileset.get(0), w, tstart, cnt); notdone = processTile(tileset.get(0), tstart, cnt);
/* Now, join with others */ /* Now, join with others */
for(int i = 0; i < rslt.size(); i++) { for(int i = 0; i < rslt.size(); i++) {
try { try {
@ -565,7 +564,7 @@ public class MapManager {
timeaccum = save_timeaccum + System.currentTimeMillis() - tstart; timeaccum = save_timeaccum + System.currentTimeMillis() - tstart;
} }
else { else {
notdone = processTile(tile, w, tstart, 1); notdone = processTile(tile, tstart, 1);
} }
if(notdone) { if(notdone) {
@ -587,7 +586,7 @@ public class MapManager {
} }
} }
private boolean processTile(MapTile tile, World w, long tstart, int parallelcnt) { private boolean processTile(MapTile tile, long tstart, int parallelcnt) {
/* Get list of chunks required for tile */ /* Get list of chunks required for tile */
List<DynmapChunk> requiredChunks = tile.getRequiredChunks(); List<DynmapChunk> requiredChunks = tile.getRequiredChunks();
/* If we are doing radius limit render, see if any are inside limits */ /* If we are doing radius limit render, see if any are inside limits */
@ -652,10 +651,10 @@ public class MapManager {
double msecpertile = (double)timeaccum / (double)rendercnt / (double)activemapcnt; double msecpertile = (double)timeaccum / (double)rendercnt / (double)activemapcnt;
if(activemapcnt > 1) if(activemapcnt > 1)
sendMessage(String.format("%s of maps [%s] of '%s' in progress - %d tiles rendered each (%.2f msec/map-tile, %.2f msec per render)", sendMessage(String.format("%s of maps [%s] of '%s' in progress - %d tiles rendered each (%.2f msec/map-tile, %.2f msec per render)",
rendertype, activemaps, world.world.getName(), rendercnt, msecpertile, rendtime)); rendertype, activemaps, world.getName(), rendercnt, msecpertile, rendtime));
else else
sendMessage(String.format("%s of map '%s' of '%s' in progress - %d tiles rendered (%.2f msec/tile, %.2f msec per render)", sendMessage(String.format("%s of map '%s' of '%s' in progress - %d tiles rendered (%.2f msec/tile, %.2f msec per render)",
rendertype, activemaps, world.world.getName(), rendercnt, msecpertile, rendtime)); rendertype, activemaps, world.getName(), rendercnt, msecpertile, rendtime));
} }
} }
} }
@ -685,7 +684,7 @@ public class MapManager {
Future<Integer> f = scheduler.callSyncMethod(plug_in, new Callable<Integer>() { Future<Integer> f = scheduler.callSyncMethod(plug_in, new Callable<Integer>() {
public Integer call() throws Exception { public Integer call() throws Exception {
for(DynmapWorld w : worlds) { for(DynmapWorld w : worlds) {
int new_servertime = (int)(w.world.getTime() % 24000); int new_servertime = (int)(w.getTime() % 24000);
/* Check if we went from night to day */ /* Check if we went from night to day */
boolean wasday = w.servertime >= 0 && w.servertime < 13700; boolean wasday = w.servertime >= 0 && w.servertime < 13700;
boolean isday = new_servertime >= 0 && new_servertime < 13700; boolean isday = new_servertime >= 0 && new_servertime < 13700;
@ -875,8 +874,7 @@ public class MapManager {
} }
String worldName = w.getName(); String worldName = w.getName();
DynmapWorld dynmapWorld = new DynmapWorld(); DynmapWorld dynmapWorld = new DynmapWorld(w);
dynmapWorld.world = w;
dynmapWorld.configuration = worldConfiguration; dynmapWorld.configuration = worldConfiguration;
Log.verboseinfo("Loading maps of world '" + worldName + "'..."); Log.verboseinfo("Loading maps of world '" + worldName + "'...");
for(MapType map : worldConfiguration.<MapType>createInstances("maps", new Class<?>[0], new Object[0])) { for(MapType map : worldConfiguration.<MapType>createInstances("maps", new Class<?>[0], new Object[0])) {
@ -965,7 +963,7 @@ public class MapManager {
else { else {
int insertIndex; int insertIndex;
for(insertIndex = 0; insertIndex < worlds.size(); insertIndex++) { for(insertIndex = 0; insertIndex < worlds.size(); insertIndex++) {
Integer nextWorldIndex = indexLookup.get(worlds.get(insertIndex).world.getName()); Integer nextWorldIndex = indexLookup.get(worlds.get(insertIndex).getName());
if (nextWorldIndex == null || worldIndex < nextWorldIndex.intValue()) { if (nextWorldIndex == null || worldIndex < nextWorldIndex.intValue()) {
break; break;
} }
@ -979,8 +977,12 @@ public class MapManager {
loadPending(dynmapWorld); loadPending(dynmapWorld);
} }
public void deactivateWorld(String wname) {
Log.warning("World unloading not properly supported");
}
private void loadPending(DynmapWorld w) { private void loadPending(DynmapWorld w) {
String wname = w.world.getName(); String wname = w.getName();
File f = new File(plug_in.getDataFolder(), wname + ".pending"); File f = new File(plug_in.getDataFolder(), wname + ".pending");
if(f.exists()) { if(f.exists()) {
org.bukkit.util.config.Configuration saved = new org.bukkit.util.config.Configuration(f); org.bukkit.util.config.Configuration saved = new org.bukkit.util.config.Configuration(f);
@ -1019,7 +1021,7 @@ public class MapManager {
List<MapTile> mt = tileQueue.popAll(); List<MapTile> mt = tileQueue.popAll();
for(DynmapWorld w : worlds) { for(DynmapWorld w : worlds) {
boolean dosave = false; boolean dosave = false;
File f = new File(plug_in.getDataFolder(), w.world.getName() + ".pending"); File f = new File(plug_in.getDataFolder(), w.getName() + ".pending");
org.bukkit.util.config.Configuration saved = new org.bukkit.util.config.Configuration(f); org.bukkit.util.config.Configuration saved = new org.bukkit.util.config.Configuration(f);
ArrayList<ConfigurationNode> savedtiles = new ArrayList<ConfigurationNode>(); ArrayList<ConfigurationNode> savedtiles = new ArrayList<ConfigurationNode>();
for(MapTile tile : mt) { for(MapTile tile : mt) {
@ -1032,17 +1034,17 @@ public class MapManager {
if(savedtiles.size() > 0) { /* Something to save? */ if(savedtiles.size() > 0) { /* Something to save? */
saved.setProperty("tiles", savedtiles); saved.setProperty("tiles", savedtiles);
dosave = true; dosave = true;
Log.info("Saved " + savedtiles.size() + " pending tile renders in world '" + w.world.getName()); Log.info("Saved " + savedtiles.size() + " pending tile renders in world '" + w.getName());
} }
FullWorldRenderState job = active_renders.get(w.world.getName()); FullWorldRenderState job = active_renders.get(w.getName());
if(job != null) { if(job != null) {
saved.setProperty("job", job.saveState()); saved.setProperty("job", job.saveState());
dosave = true; dosave = true;
Log.info("Saved active render job in world '" + w.world.getName()); Log.info("Saved active render job in world '" + w.getName());
} }
if(dosave) { if(dosave) {
saved.save(); saved.save();
Log.info("Saved " + savedtiles.size() + " pending tile renders in world '" + w.world.getName()); Log.info("Saved " + savedtiles.size() + " pending tile renders in world '" + w.getName());
} }
} }
} }
@ -1097,7 +1099,7 @@ public class MapManager {
/* Resume pending jobs */ /* Resume pending jobs */
for(FullWorldRenderState job : active_renders.values()) { for(FullWorldRenderState job : active_renders.values()) {
scheduleDelayedJob(job, 5000); scheduleDelayedJob(job, 5000);
Log.info("Resumed render starting on world '" + job.world.world.getName() + "'..."); Log.info("Resumed render starting on world '" + job.world.getName() + "'...");
} }
} }
@ -1174,7 +1176,7 @@ public class MapManager {
c.setHiddenFillStyle(w.hiddenchunkstyle); c.setHiddenFillStyle(w.hiddenchunkstyle);
} }
c.setChunks(w.world, chunks); c.setChunks(w.getWorld(), chunks);
if(c.setChunkDataTypes(blockdata, biome, highesty, rawbiome) == false) if(c.setChunkDataTypes(blockdata, biome, highesty, rawbiome) == false)
Log.severe("CraftBukkit build does not support biome APIs"); Log.severe("CraftBukkit build does not support biome APIs");
if(chunks.size() == 0) { /* No chunks to get? */ if(chunks.size() == 0) { /* No chunks to get? */

View file

@ -61,23 +61,22 @@ public class MarkersComponent extends ClientComponent {
World w = event.getWorld(); /* Get the world */ World w = event.getWorld(); /* Get the world */
Location loc = w.getSpawnLocation(); /* Get location of spawn */ Location loc = w.getSpawnLocation(); /* Get location of spawn */
if(loc != null) if(loc != null)
addUpdateWorld(w, loc); addUpdateWorld(w, new DynmapLocation(w.getName(), loc.getX(), loc.getY(), loc.getZ()));
} }
public void onSpawnChange(SpawnChangeEvent event) { public void onSpawnChange(SpawnChangeEvent event) {
World w = event.getWorld(); /* Get the world */ World w = event.getWorld(); /* Get the world */
Location loc = w.getSpawnLocation(); /* Get location of spawn */ Location loc = w.getSpawnLocation(); /* Get location of spawn */
if(loc != null) if(loc != null)
addUpdateWorld(w, loc); addUpdateWorld(w, new DynmapLocation(w.getName(), loc.getX(), loc.getY(), loc.getZ()));
} }
}; };
plugin.registerEvent(org.bukkit.event.Event.Type.WORLD_LOAD, wl); plugin.registerEvent(org.bukkit.event.Event.Type.WORLD_LOAD, wl);
plugin.registerEvent(org.bukkit.event.Event.Type.SPAWN_CHANGE, wl); plugin.registerEvent(org.bukkit.event.Event.Type.SPAWN_CHANGE, wl);
/* Initialize already loaded worlds */ /* Initialize already loaded worlds */
for(DynmapWorld w : plugin.getMapManager().getWorlds()) { for(DynmapWorld w : plugin.getMapManager().getWorlds()) {
World world = w.world; DynmapLocation loc = w.getSpawnLocation();
Location loc = world.getSpawnLocation();
if(loc != null) if(loc != null)
addUpdateWorld(world, loc); addUpdateWorld(w.getWorld(), loc);
} }
} }
/* If showing offline players as markers */ /* If showing offline players as markers */
@ -195,17 +194,17 @@ public class MarkersComponent extends ClientComponent {
} }
} }
private void addUpdateWorld(World w, Location loc) { private void addUpdateWorld(World w, DynmapLocation loc) {
MarkerSet ms = api.getMarkerSet(MarkerSet.DEFAULT); MarkerSet ms = api.getMarkerSet(MarkerSet.DEFAULT);
if(ms != null) { if(ms != null) {
String spawnid = "_spawn_" + w.getName(); String spawnid = "_spawn_" + w.getName();
Marker m = ms.findMarker(spawnid); /* See if defined */ Marker m = ms.findMarker(spawnid); /* See if defined */
if(m == null) { /* Not defined yet, add it */ if(m == null) { /* Not defined yet, add it */
ms.createMarker(spawnid, spawnlbl, w.getName(), loc.getX(), loc.getY(), loc.getZ(), ms.createMarker(spawnid, spawnlbl, w.getName(), loc.x, loc.y, loc.z,
spawnicon, false); spawnicon, false);
} }
else { else {
m.setLocation(w.getName(), loc.getX(), loc.getY(), loc.getZ()); m.setLocation(w.getName(), loc.z, loc.y, loc.z);
} }
} }
} }

View file

@ -554,7 +554,7 @@ public class FlatMap extends MapType {
@Override @Override
public String getKey(String prefix) { public String getKey(String prefix) {
return world.world.getName() + "." + map.getPrefix(); return world.getName() + "." + map.getPrefix();
} }
public boolean isHightestBlockYDataNeeded() { return true; } public boolean isHightestBlockYDataNeeded() { return true; }

View file

@ -500,7 +500,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
private void freshenMarkerFiles() { private void freshenMarkerFiles() {
if(MapManager.mapman != null) { if(MapManager.mapman != null) {
for(DynmapWorld w : MapManager.mapman.worlds) { for(DynmapWorld w : MapManager.mapman.worlds) {
dirty_worlds.add(w.world.getName()); dirty_worlds.add(w.getName());
} }
} }
} }
@ -1599,7 +1599,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
@Override @Override
public void triggered(DynmapWorld t) { public void triggered(DynmapWorld t) {
/* Update markers for now-active world */ /* Update markers for now-active world */
dirty_worlds.add(t.world.getName()); dirty_worlds.add(t.getName());
} }
/* Remove icon */ /* Remove icon */

View file

@ -42,7 +42,7 @@ public class ClientUpdateHandler implements HttpHandler {
if(plugin.mapManager != null) { if(plugin.mapManager != null) {
dynmapWorld = plugin.mapManager.getWorld(worldName); dynmapWorld = plugin.mapManager.getWorld(worldName);
} }
if (dynmapWorld == null || dynmapWorld.world == null) { if (dynmapWorld == null) {
response.status = WorldNotFound; response.status = WorldNotFound;
return; return;
} }

View file

@ -1,7 +1,7 @@
var config = { var config = {
// For internal server or proxying webserver. // For internal server or proxying webserver.
url : { url : {
configuration : 'up/configuration', configuration : 'up/configuration?_={timestamp}',
update : 'up/world/{world}/{timestamp}', update : 'up/world/{world}/{timestamp}',
sendmessage : 'up/sendmessage' sendmessage : 'up/sendmessage'
}, },