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 aa2270ae76
commit d7a7ee9c5d
10 changed files with 73 additions and 51 deletions

View File

@ -42,10 +42,10 @@ public class ClientConfigurationComponent extends Component {
JSONObject wo = new JSONObject();
s(wo, "name", wn.getString("name"));
s(wo, "title", wn.getString("title"));
Location spawn = world.world.getSpawnLocation();
s(wo, "center/x", wn.getDouble("center/x", spawn.getX()));
s(wo, "center/y", wn.getDouble("center/y", spawn.getY()));
s(wo, "center/z", wn.getDouble("center/z", spawn.getZ()));
DynmapLocation spawn = world.getSpawnLocation();
s(wo, "center/x", wn.getDouble("center/x", spawn.x));
s(wo, "center/y", wn.getDouble("center/y", spawn.y));
s(wo, "center/z", wn.getDouble("center/z", spawn.z));
s(wo, "bigworld", world.bigworld);
s(wo, "extrazoomout", world.getExtraZoomOutLevels());
a(t, "worlds", wo);
@ -55,7 +55,7 @@ public class ClientConfigurationComponent extends Component {
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));
if(c.getString("followmap", null) != null)
s(t, "followmap", c.getString("followmap"));

View File

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

View File

@ -1,5 +1,7 @@
package org.dynmap;
import static org.dynmap.JSONUtils.s;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -26,7 +28,7 @@ public class DynmapWorld {
FORMAPONLY,
PERMANENT
}
public World world;
private World world;
public List<MapType> maps = new ArrayList<MapType>();
public UpdateQueue updates = new UpdateQueue();
public ConfigurationNode configuration;
@ -46,7 +48,12 @@ public class DynmapWorld {
private HashSet<String> zoomoutupdates[] = new HashSet[0];
private boolean checkts = true; /* Check timestamps on first run with new configuration */
private boolean cancelled;
private String wname;
public DynmapWorld(World w) {
world = w;
wname = w.getName();
}
@SuppressWarnings("unchecked")
public void setExtraZoomOutLevels(int lvl) {
extrazoomoutlevels = lvl;
@ -489,7 +496,7 @@ public class DynmapWorld {
}
/* Get world name */
public String getName() {
return world.getName();
return wname;
}
/* Get world spawn location */
public DynmapLocation getSpawnLocation() {
@ -501,6 +508,22 @@ public class DynmapWorld {
}
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;
//Handles Updates
for (DynmapWorld dynmapWorld : plugin.mapManager.getWorlds()) {
World world = dynmapWorld.world;
JSONObject update = new JSONObject();
update.put("timestamp", currentTimestamp);
ClientUpdateEvent clientUpdate = new ClientUpdateEvent(currentTimestamp - 30000, dynmapWorld, update);
plugin.events.trigger("buildclientupdate", clientUpdate);
outputFile = getStandaloneFile("dynmap_" + world.getName() + ".json");
outputTempFile = getStandaloneFile("dynmap_" + world.getName() + ".json.new");
outputFile = getStandaloneFile("dynmap_" + dynmapWorld.getName() + ".json");
outputTempFile = getStandaloneFile("dynmap_" + dynmapWorld.getName() + ".json.new");
int retrycnt = 0;
boolean done = false;
while(!done) {

View File

@ -350,7 +350,7 @@ public class MapManager {
public HashMap<String,Object> saveState() {
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("locY", loc.y);
v.put("locZ", loc.z);
@ -420,10 +420,10 @@ public class MapManager {
double rendtime = total_render_ns.doubleValue() * 0.000001 / rendercalls.get();
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)",
rendertype, activemaps, world.world.getName(), rendercnt, msecpertile, rendtime));
rendertype, activemaps, world.getName(), rendercnt, msecpertile, rendtime));
else
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 */
if(rendertype.equals(RENDERTYPE_FULLRENDER)) {
if(activemapcnt == 1) {
@ -458,7 +458,7 @@ public class MapManager {
}
}
if(map_index >= world.maps.size()) { /* Last one done? */
sendMessage(rendertype + " of '" + world.world.getName() + "' finished.");
sendMessage(rendertype + " of '" + world.getName() + "' finished.");
cleanup();
return;
}
@ -529,8 +529,7 @@ public class MapManager {
}
tile = tile0;
}
World w = world.world;
boolean notdone = true;
if(tileset != null) {
@ -543,14 +542,14 @@ public class MapManager {
final long ts = tstart;
Future<Boolean> future = mapman.render_pool.submit(new Callable<Boolean>() {
public Boolean call() {
return processTile(mt, mt.world.world, ts, cnt);
return processTile(mt, ts, cnt);
}
});
rslt.add(future);
}
}
/* 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 */
for(int i = 0; i < rslt.size(); i++) {
try {
@ -565,7 +564,7 @@ public class MapManager {
timeaccum = save_timeaccum + System.currentTimeMillis() - tstart;
}
else {
notdone = processTile(tile, w, tstart, 1);
notdone = processTile(tile, tstart, 1);
}
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 */
List<DynmapChunk> requiredChunks = tile.getRequiredChunks();
/* 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;
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)",
rendertype, activemaps, world.world.getName(), rendercnt, msecpertile, rendtime));
rendertype, activemaps, world.getName(), rendercnt, msecpertile, rendtime));
else
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>() {
public Integer call() throws Exception {
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 */
boolean wasday = w.servertime >= 0 && w.servertime < 13700;
boolean isday = new_servertime >= 0 && new_servertime < 13700;
@ -875,8 +874,7 @@ public class MapManager {
}
String worldName = w.getName();
DynmapWorld dynmapWorld = new DynmapWorld();
dynmapWorld.world = w;
DynmapWorld dynmapWorld = new DynmapWorld(w);
dynmapWorld.configuration = worldConfiguration;
Log.verboseinfo("Loading maps of world '" + worldName + "'...");
for(MapType map : worldConfiguration.<MapType>createInstances("maps", new Class<?>[0], new Object[0])) {
@ -965,7 +963,7 @@ public class MapManager {
else {
int 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()) {
break;
}
@ -978,9 +976,13 @@ public class MapManager {
if(saverestorepending)
loadPending(dynmapWorld);
}
public void deactivateWorld(String wname) {
Log.warning("World unloading not properly supported");
}
private void loadPending(DynmapWorld w) {
String wname = w.world.getName();
String wname = w.getName();
File f = new File(plug_in.getDataFolder(), wname + ".pending");
if(f.exists()) {
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();
for(DynmapWorld w : worlds) {
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);
ArrayList<ConfigurationNode> savedtiles = new ArrayList<ConfigurationNode>();
for(MapTile tile : mt) {
@ -1032,17 +1034,17 @@ public class MapManager {
if(savedtiles.size() > 0) { /* Something to save? */
saved.setProperty("tiles", savedtiles);
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) {
saved.setProperty("job", job.saveState());
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) {
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 */
for(FullWorldRenderState job : active_renders.values()) {
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.setChunks(w.world, chunks);
c.setChunks(w.getWorld(), chunks);
if(c.setChunkDataTypes(blockdata, biome, highesty, rawbiome) == false)
Log.severe("CraftBukkit build does not support biome APIs");
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 */
Location loc = w.getSpawnLocation(); /* Get location of spawn */
if(loc != null)
addUpdateWorld(w, loc);
addUpdateWorld(w, new DynmapLocation(w.getName(), loc.getX(), loc.getY(), loc.getZ()));
}
public void onSpawnChange(SpawnChangeEvent event) {
World w = event.getWorld(); /* Get the world */
Location loc = w.getSpawnLocation(); /* Get location of spawn */
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.SPAWN_CHANGE, wl);
/* Initialize already loaded worlds */
for(DynmapWorld w : plugin.getMapManager().getWorlds()) {
World world = w.world;
Location loc = world.getSpawnLocation();
DynmapLocation loc = w.getSpawnLocation();
if(loc != null)
addUpdateWorld(world, loc);
addUpdateWorld(w.getWorld(), loc);
}
}
/* 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);
if(ms != null) {
String spawnid = "_spawn_" + w.getName();
Marker m = ms.findMarker(spawnid); /* See if defined */
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);
}
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
public String getKey(String prefix) {
return world.world.getName() + "." + map.getPrefix();
return world.getName() + "." + map.getPrefix();
}
public boolean isHightestBlockYDataNeeded() { return true; }

View File

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

View File

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

View File

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