mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-18 22:57:49 +01:00
Made MapTypes per World (instead of having MapTypes for all worlds).
This commit is contained in:
parent
65f3ea4fe3
commit
8d0f509bfe
@ -19,7 +19,9 @@ disabledcommands:
|
|||||||
- fullrender
|
- fullrender
|
||||||
|
|
||||||
# The maptypes Dynmap will use to render.
|
# The maptypes Dynmap will use to render.
|
||||||
maps:
|
worlds:
|
||||||
|
- name: world
|
||||||
|
maps:
|
||||||
- class: org.dynmap.kzedmap.KzedMap
|
- class: org.dynmap.kzedmap.KzedMap
|
||||||
renderers:
|
renderers:
|
||||||
- class: org.dynmap.kzedmap.DefaultTileRenderer
|
- class: org.dynmap.kzedmap.DefaultTileRenderer
|
||||||
@ -28,6 +30,10 @@ maps:
|
|||||||
- class: org.dynmap.kzedmap.CaveTileRenderer
|
- class: org.dynmap.kzedmap.CaveTileRenderer
|
||||||
prefix: ct
|
prefix: ct
|
||||||
maximumheight: 127
|
maximumheight: 127
|
||||||
|
- name: nether
|
||||||
|
maps:
|
||||||
|
- class: org.dynmap.kzedmap.KzedMap
|
||||||
|
renderers:
|
||||||
- class: org.dynmap.kzedmap.DefaultTileRenderer
|
- class: org.dynmap.kzedmap.DefaultTileRenderer
|
||||||
prefix: nt
|
prefix: nt
|
||||||
maximumheight: 64
|
maximumheight: 64
|
||||||
|
@ -9,21 +9,18 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Event.Priority;
|
import org.bukkit.event.Event.Priority;
|
||||||
import org.bukkit.event.block.BlockListener;
|
import org.bukkit.event.block.BlockListener;
|
||||||
import org.bukkit.event.player.PlayerListener;
|
import org.bukkit.event.player.PlayerListener;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.event.world.WorldEvent;
|
||||||
import org.bukkit.plugin.PluginLoader;
|
import org.bukkit.event.world.WorldListener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.config.Configuration;
|
import org.bukkit.util.config.Configuration;
|
||||||
import org.dynmap.Event.Listener;
|
import org.dynmap.Event.Listener;
|
||||||
import org.dynmap.debug.Debug;
|
import org.dynmap.debug.Debug;
|
||||||
import org.dynmap.debug.Debugger;
|
import org.dynmap.debug.Debugger;
|
||||||
import org.dynmap.debug.LogDebugger;
|
|
||||||
import org.dynmap.kzedmap.MapTileRenderer;
|
|
||||||
import org.dynmap.web.HttpServer;
|
import org.dynmap.web.HttpServer;
|
||||||
import org.dynmap.web.handlers.ClientConfigurationHandler;
|
import org.dynmap.web.handlers.ClientConfigurationHandler;
|
||||||
import org.dynmap.web.handlers.ClientUpdateHandler;
|
import org.dynmap.web.handlers.ClientUpdateHandler;
|
||||||
@ -66,7 +63,7 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
playerList = new PlayerList(getServer(), getFile("hiddenplayers.txt"));
|
playerList = new PlayerList(getServer(), getFile("hiddenplayers.txt"));
|
||||||
playerList.load();
|
playerList.load();
|
||||||
|
|
||||||
mapManager = new MapManager(configuration);
|
mapManager = new MapManager(this, configuration);
|
||||||
mapManager.startRendering();
|
mapManager.startRendering();
|
||||||
|
|
||||||
InetAddress bindAddress;
|
InetAddress bindAddress;
|
||||||
@ -123,6 +120,14 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Monitor, this);
|
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Monitor, this);
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Monitor, this);
|
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Monitor, this);
|
||||||
|
|
||||||
|
WorldListener worldListener = new WorldListener() {
|
||||||
|
@Override
|
||||||
|
public void onWorldLoaded(WorldEvent event) {
|
||||||
|
mapManager.activateWorld(event.getWorld());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
getServer().getPluginManager().registerEvent(Event.Type.WORLD_LOADED, worldListener, Priority.Monitor, this);
|
||||||
|
|
||||||
PlayerListener playerListener = new DynmapPlayerListener(mapManager, playerList, configuration);
|
PlayerListener playerListener = new DynmapPlayerListener(mapManager, playerList, configuration);
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
|
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
|
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
|
||||||
|
@ -19,18 +19,17 @@ import org.dynmap.debug.Debug;
|
|||||||
public class MapManager {
|
public class MapManager {
|
||||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
private MapType[] mapTypes;
|
|
||||||
public AsynchronousQueue<MapTile> tileQueue;
|
public AsynchronousQueue<MapTile> tileQueue;
|
||||||
|
|
||||||
public Map<String, UpdateQueue> worldUpdateQueues = new HashMap<String, UpdateQueue>();
|
public Map<String, DynmapWorld> worlds = new HashMap<String, DynmapWorld>();
|
||||||
public ArrayList<String> worlds = new ArrayList<String>();
|
public Map<String, DynmapWorld> inactiveworlds = new HashMap<String, DynmapWorld>();
|
||||||
|
|
||||||
public PlayerList playerList;
|
public PlayerList playerList;
|
||||||
|
|
||||||
/* lock for our data structures */
|
/* lock for our data structures */
|
||||||
public static final Object lock = new Object();
|
public static final Object lock = new Object();
|
||||||
|
|
||||||
public MapManager(ConfigurationNode configuration) {
|
public MapManager(DynmapPlugin plugin, ConfigurationNode configuration) {
|
||||||
this.tileQueue = new AsynchronousQueue<MapTile>(new Handler<MapTile>() {
|
this.tileQueue = new AsynchronousQueue<MapTile>(new Handler<MapTile>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(MapTile t) {
|
public void handle(MapTile t) {
|
||||||
@ -38,15 +37,34 @@ public class MapManager {
|
|||||||
}
|
}
|
||||||
}, (int) (configuration.getDouble("renderinterval", 0.5) * 1000));
|
}, (int) (configuration.getDouble("renderinterval", 0.5) * 1000));
|
||||||
|
|
||||||
mapTypes = loadMapTypes(configuration);
|
for(Object worldConfigurationObj : (List<?>)configuration.getProperty("worlds")) {
|
||||||
|
Map<?, ?> worldConfiguration = (Map<?, ?>)worldConfigurationObj;
|
||||||
|
String worldName = (String)worldConfiguration.get("name");
|
||||||
|
DynmapWorld world = new DynmapWorld();
|
||||||
|
if (worldConfiguration.get("maps") != null) {
|
||||||
|
for(MapType map : loadMapTypes((List<?>)worldConfiguration.get("maps"))) {
|
||||||
|
world.maps.add(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inactiveworlds.put(worldName, world);
|
||||||
|
|
||||||
|
World bukkitWorld = plugin.getServer().getWorld(worldName);
|
||||||
|
if (bukkitWorld != null)
|
||||||
|
activateWorld(bukkitWorld);
|
||||||
|
}
|
||||||
|
|
||||||
tileQueue.start();
|
tileQueue.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderFullWorld(Location l) {
|
void renderFullWorld(Location l) {
|
||||||
World world = l.getWorld();
|
DynmapWorld world = worlds.get(l.getWorld().getName());
|
||||||
log.info("Full render starting...");
|
if (world == null) {
|
||||||
for (MapType map : mapTypes) {
|
log.severe("Could not render: world '" + l.getWorld().getName() + "' not defined in configuration.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
World w = world.world;
|
||||||
|
log.info("Full render starting on world '" + w.getName() + "'...");
|
||||||
|
for (MapType map : world.maps) {
|
||||||
int requiredChunkCount = 200;
|
int requiredChunkCount = 200;
|
||||||
HashSet<MapTile> found = new HashSet<MapTile>();
|
HashSet<MapTile> found = new HashSet<MapTile>();
|
||||||
HashSet<MapTile> rendered = new HashSet<MapTile>();
|
HashSet<MapTile> rendered = new HashSet<MapTile>();
|
||||||
@ -69,13 +87,13 @@ public class MapManager {
|
|||||||
// Unload old chunks.
|
// Unload old chunks.
|
||||||
while (loadedChunks.size() >= requiredChunkCount - requiredChunks.length) {
|
while (loadedChunks.size() >= requiredChunkCount - requiredChunks.length) {
|
||||||
DynmapChunk c = loadedChunks.pollFirst();
|
DynmapChunk c = loadedChunks.pollFirst();
|
||||||
world.unloadChunk(c.x, c.z, false, true);
|
w.unloadChunk(c.x, c.z, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the required chunks.
|
// Load the required chunks.
|
||||||
for (DynmapChunk chunk : requiredChunks) {
|
for (DynmapChunk chunk : requiredChunks) {
|
||||||
boolean wasLoaded = world.isChunkLoaded(chunk.x, chunk.z);
|
boolean wasLoaded = w.isChunkLoaded(chunk.x, chunk.z);
|
||||||
world.loadChunk(chunk.x, chunk.z, false);
|
w.loadChunk(chunk.x, chunk.z, false);
|
||||||
if (!wasLoaded)
|
if (!wasLoaded)
|
||||||
loadedChunks.add(chunk);
|
loadedChunks.add(chunk);
|
||||||
}
|
}
|
||||||
@ -97,23 +115,35 @@ public class MapManager {
|
|||||||
// Unload remaining chunks to clean-up.
|
// Unload remaining chunks to clean-up.
|
||||||
while (!loadedChunks.isEmpty()) {
|
while (!loadedChunks.isEmpty()) {
|
||||||
DynmapChunk c = loadedChunks.pollFirst();
|
DynmapChunk c = loadedChunks.pollFirst();
|
||||||
world.unloadChunk(c.x, c.z, false, true);
|
w.unloadChunk(c.x, c.z, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("Full render finished.");
|
log.info("Full render finished.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private MapType[] loadMapTypes(ConfigurationNode configuration) {
|
public void activateWorld(World w) {
|
||||||
|
DynmapWorld world = inactiveworlds.get(w.getName());
|
||||||
|
if (world == null) {
|
||||||
|
world = worlds.get(w.getName());
|
||||||
|
} else {
|
||||||
|
inactiveworlds.remove(w.getName());
|
||||||
|
}
|
||||||
|
if (world != null) {
|
||||||
|
world.world = w;
|
||||||
|
worlds.put(w.getName(), world);
|
||||||
|
log.info("Activated world '" + w.getName() + "' in Dynmap.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private MapType[] loadMapTypes(List<?> mapConfigurations) {
|
||||||
Event.Listener<MapTile> invalitateListener = new Event.Listener<MapTile>() {
|
Event.Listener<MapTile> invalitateListener = new Event.Listener<MapTile>() {
|
||||||
@Override
|
@Override
|
||||||
public void triggered(MapTile t) {
|
public void triggered(MapTile t) {
|
||||||
invalidateTile(t);
|
invalidateTile(t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
List<?> configuredMaps = (List<?>) configuration.getProperty("maps");
|
|
||||||
ArrayList<MapType> mapTypes = new ArrayList<MapType>();
|
ArrayList<MapType> mapTypes = new ArrayList<MapType>();
|
||||||
for (Object configuredMapObj : configuredMaps) {
|
for (Object configuredMapObj : mapConfigurations) {
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> configuredMap = (Map<String, Object>) configuredMapObj;
|
Map<String, Object> configuredMap = (Map<String, Object>) configuredMapObj;
|
||||||
@ -135,9 +165,11 @@ public class MapManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void touch(Location l) {
|
public void touch(Location l) {
|
||||||
Debug.debug("Touched " + l.toString());
|
DynmapWorld world = worlds.get(l.getWorld().getName());
|
||||||
for (int i = 0; i < mapTypes.length; i++) {
|
if (world == null)
|
||||||
MapTile[] tiles = mapTypes[i].getTiles(l);
|
return;
|
||||||
|
for (int i = 0; i < world.maps.size(); i++) {
|
||||||
|
MapTile[] tiles = world.maps.get(i).getTiles(l);
|
||||||
for (int j = 0; j < tiles.length; j++) {
|
for (int j = 0; j < tiles.length; j++) {
|
||||||
invalidateTile(tiles[j]);
|
invalidateTile(tiles[j]);
|
||||||
}
|
}
|
||||||
@ -177,9 +209,8 @@ public class MapManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void pushUpdate(Object update) {
|
public void pushUpdate(Object update) {
|
||||||
for(int i=0;i<worlds.size();i++) {
|
for(DynmapWorld world : worlds.values()) {
|
||||||
UpdateQueue queue = worldUpdateQueues.get(worlds.get(i));
|
world.updates.pushUpdate(update);
|
||||||
queue.pushUpdate(update);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,19 +218,15 @@ public class MapManager {
|
|||||||
pushUpdate(world.getName(), update);
|
pushUpdate(world.getName(), update);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pushUpdate(String world, Object update) {
|
public void pushUpdate(String worldName, Object update) {
|
||||||
UpdateQueue updateQueue = worldUpdateQueues.get(world);
|
DynmapWorld world = worlds.get(worldName);
|
||||||
if (updateQueue == null) {
|
world.updates.pushUpdate(update);
|
||||||
worldUpdateQueues.put(world, updateQueue = new UpdateQueue());
|
|
||||||
worlds.add(world);
|
|
||||||
}
|
|
||||||
updateQueue.pushUpdate(update);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getWorldUpdates(String worldName, long since) {
|
public Object[] getWorldUpdates(String worldName, long since) {
|
||||||
UpdateQueue queue = worldUpdateQueues.get(worldName);
|
DynmapWorld world = worlds.get(worldName);
|
||||||
if (queue == null)
|
if (world == null)
|
||||||
return new Object[0];
|
return new Object[0];
|
||||||
return queue.getUpdatedObjects(since);
|
return world.updates.getUpdatedObjects(since);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user