Add support world-type-specific templates, to allow automatic

initializing of worlds (make configuration.txt work unmodified for
most folks, while still supporting per-world customizations)
This commit is contained in:
Mike Primm 2011-05-22 17:28:12 -05:00
parent d44c3620cc
commit 19fca36bac
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 defaultzoom: 0
defaultworld: world defaultworld: world
# The maptypes Dynmap will use to render. # template world - this is used for worlds that exist but aren't defined in the worlds section.
worlds: # Also, it supplies the "maps" section for worlds lacking a maps section, and the "center"
- name: world # for worlds lacking a "center" section.
title: "World" template:
# Template for normal world
normal:
center: center:
x: 0 x: 0
y: 64 y: 64
@ -147,8 +149,8 @@ worlds:
title: "Cave" title: "Cave"
prefix: ct prefix: ct
maximumheight: 127 maximumheight: 127
- name: nether # Nether world template
title: "Nether" nether:
center: center:
x: 0 x: 0
y: 64 y: 64
@ -168,6 +170,76 @@ worlds:
maximumheight: 127 maximumheight: 127
colorscheme: default 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. # Enables debugging.
#debuggers: #debuggers:
# - class: org.dynmap.debug.LogDebugger # - class: org.dynmap.debug.LogDebugger

View File

@ -1,8 +1,7 @@
package org.dynmap; package org.dynmap;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.util.HashMap;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.net.InetAddress; import java.net.InetAddress;
@ -13,10 +12,9 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Timer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -80,6 +78,8 @@ public class DynmapPlugin extends JavaPlugin {
bukkitConfiguration.load(); bukkitConfiguration.load();
configuration = new ConfigurationNode(bukkitConfiguration); configuration = new ConfigurationNode(bukkitConfiguration);
processWorldTemplates(configuration);
loadDebuggers(); loadDebuggers();
tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles")); tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles"));
@ -366,4 +366,77 @@ public class DynmapPlugin extends JavaPlugin {
} }
return true; 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);
}
}
} }