From 19fca36bacce7c4df067b0557d9024275ccb8f88 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 22 May 2011 17:28:12 -0500 Subject: [PATCH] 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) --- configuration.txt | 84 ++++++++++++++++++++-- src/main/java/org/dynmap/DynmapPlugin.java | 81 +++++++++++++++++++-- 2 files changed, 155 insertions(+), 10 deletions(-) diff --git a/configuration.txt b/configuration.txt index 928ead55..fa99060b 100644 --- a/configuration.txt +++ b/configuration.txt @@ -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 diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 506c3afd..f7036a68 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -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 worlds = node.getNodes("worlds"); + boolean worldsupdated = false; + /* Initialize even if no worlds section */ + if(worlds == null) { + worlds = new ArrayList(); + 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(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 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(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); + } + } }