Merge pull request #160 from mikeprimm/master

Add support for world-type-specific templates in configuration.txt - automatically configure worlds
This commit is contained in:
mikeprimm 2011-05-22 15:41:32 -07:00
commit 3b7e81a729
2 changed files with 155 additions and 10 deletions

View File

@ -108,10 +108,12 @@ spammessage: "You may only chat once every %interval% seconds."
defaultzoom: 0
defaultworld: world
# The maptypes Dynmap will use to render.
worlds:
- name: world
title: "World"
# template world - this is used for worlds that exist but aren't defined in the worlds section.
# Also, it supplies the "maps" section for worlds lacking a maps section, and the "center"
# for worlds lacking a "center" section.
template:
# Template for normal world
normal:
center:
x: 0
y: 64
@ -147,8 +149,8 @@ worlds:
title: "Cave"
prefix: ct
maximumheight: 127
- name: nether
title: "Nether"
# Nether world template
nether:
center:
x: 0
y: 64
@ -168,6 +170,76 @@ worlds:
maximumheight: 127
colorscheme: default
# The maptypes Dynmap will use to render.
worlds:
# Worlds can be handled by templates, based on world type
# To override, provide name and title here. Any other sections that are provided will
# be used instead of the template's value (center, maps).
#- name: world
# title: "World"
# Rest of comes from template - uncomment to tailor for world specifically
# center:
# x: 0
# y: 64
# z: 0
# maps:
# - class: org.dynmap.flat.FlatMap
# name: flat
# title: "Flat"
# prefix: flat
# colorscheme: default
# - class: org.dynmap.kzedmap.KzedMap
# renderers:
# - class: org.dynmap.kzedmap.DefaultTileRenderer
# name: surface
# title: "Surface"
# prefix: t
# maximumheight: 127
# colorscheme: default
# # Add shadows to world (based on top-down shadows from chunk data)
# # shadowstrength: 1.0
# # Sets the icon to 'images/block_custom.png'
# # icon: custom
# #- class: org.dynmap.kzedmap.HighlightTileRenderer
# # prefix: ht
# # maximumheight: 127
# # colorscheme: default
# # highlight: # For highlighting multiple block-types.
# # - 56 # Highlight diamond-ore
# # - 66 # Highlight minecart track
# # highlight: 56 # For highlighting a single block-type.
# - class: org.dynmap.kzedmap.CaveTileRenderer
# name: cave
# title: "Cave"
# prefix: ct
# maximumheight: 127
#
# To just label world, and inherit rest from template, just provide name and title
#-name: world2
# title: "Second World"
#
#- name: nether
# title: "Nether"
# center:
# x: 0
# y: 64
# z: 0
# maps:
# - class: org.dynmap.flat.FlatMap
# name: flat
# title: "Flat"
# prefix: flat
# colorscheme: default
# - class: org.dynmap.kzedmap.KzedMap
# renderers:
# - class: org.dynmap.kzedmap.DefaultTileRenderer
# name: nether
# title: "Surface"
# prefix: nt
# maximumheight: 127
# colorscheme: default
# Enables debugging.
#debuggers:
# - class: org.dynmap.debug.LogDebugger

View File

@ -1,8 +1,7 @@
package org.dynmap;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.InetAddress;
@ -13,10 +12,9 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -80,6 +78,8 @@ public class DynmapPlugin extends JavaPlugin {
bukkitConfiguration.load();
configuration = new ConfigurationNode(bukkitConfiguration);
processWorldTemplates(configuration);
loadDebuggers();
tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles"));
@ -366,4 +366,77 @@ public class DynmapPlugin extends JavaPlugin {
}
return true;
}
/* Prepare for sky worlds... */
private static final String[] templateworldtypes = { "normal", "nether" };
private static final Environment[] templateworldenv = { Environment.NORMAL, Environment.NETHER };
private void processWorldTemplates(ConfigurationNode node) {
ConfigurationNode template = node.getNode("template");
if(template == null)
return;
List<ConfigurationNode> worlds = node.getNodes("worlds");
boolean worldsupdated = false;
/* Initialize even if no worlds section */
if(worlds == null) {
worlds = new ArrayList<ConfigurationNode>();
worldsupdated = true;
}
/* Iternate by world type - so that order in templateworldtypes drives our default order */
for(int wtype = 0; wtype < templateworldtypes.length; wtype++) {
ConfigurationNode typetemplate = template.getNode(templateworldtypes[wtype]);
if(typetemplate == null)
continue;
for(World w : getServer().getWorlds()) { /* Roll through worlds */
String wn = w.getName();
/* Find node for this world, if any */
ConfigurationNode world = null;
int index;
for(index = 0; index < worlds.size(); index++) {
ConfigurationNode ww = worlds.get(index);
if(wn.equals(ww.getString("name", ""))) {
world = ww;
break;
}
}
/* Check type of world - skip if not right for current template */
if(w.getEnvironment() != templateworldenv[wtype])
continue;
/* World not found - need to use template */
if(world == null) {
ConfigurationNode newworldnode = new ConfigurationNode(new HashMap<String,Object>(typetemplate)); /* Copy it */
newworldnode.put("name", w.getName());
newworldnode.put("title", w.getName());
worlds.add(newworldnode);
worldsupdated = true;
Log.info("World '" + w.getName() + "' configuration inherited from template");
}
else { /* Else, definition is there, but may be incomplete */
boolean wupd = false;
List<ConfigurationNode> tempmaps = typetemplate.getList("maps");
if((tempmaps != null) && (world.getNode("maps") == null)) { /* World with no maps section */
world.put("maps", tempmaps);
Log.info("World '" + w.getName() + "' configuration inherited maps from template");
wupd = true;
}
ConfigurationNode tempcenter = typetemplate.getNode("center");
if((tempcenter != null) && (world.getNode("center") == null)) { /* World with no center */
world.put("center", new ConfigurationNode(new HashMap<String,Object>(tempcenter)));
Log.info("World '" + w.getName() + "' configuration inherited center from template");
wupd = true;
}
if(world.getString("title", null) == null) {
world.put("title", w.getName());
wupd = true;
}
if(wupd) {
worldsupdated = true;
worlds.set(index, world);
}
}
}
}
if(worldsupdated) {
node.put("worlds", worlds);
}
}
}