Add spout controls (enable/disable, use-existing-textures), load other spout mods first

This commit is contained in:
Mike Primm 2012-08-07 23:20:00 -05:00
parent 38a4d869f6
commit ddf14b7c3b
4 changed files with 92 additions and 51 deletions

View File

@ -96,6 +96,25 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
public SpoutPluginBlocks spb;
public PluginManager pm;
private class BukkitEnableCoreCallback extends DynmapCore.EnableCoreCallbacks {
@Override
public void configurationLoaded() {
/* Check for Spout */
if(detectSpout()) {
if(core.configuration.getBoolean("spout/enabled", true)) {
has_spout = true;
Log.info("Detected Spout");
spb = new SpoutPluginBlocks();
spb.processSpoutBlocks(DynmapPlugin.this, core);
}
else {
Log.info("Detected Spout - Support Disabled");
}
}
}
}
private static class BlockToCheck {
Location loc;
int typeid;
@ -568,14 +587,6 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
if(dataDirectory.exists() == false)
dataDirectory.mkdirs();
/* Check for Spout */
if(detectSpout()) {
has_spout = true;
Log.info("Detected Spout");
spb = new SpoutPluginBlocks();
spb.processSpoutBlocks(dataDirectory);
}
/* Get MC version */
String bukkitver = getServer().getVersion();
String mcver = "1.0.0";
@ -596,7 +607,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
core.setServer(new BukkitServer());
/* Enable core */
if(!core.enableCore()) {
if(!core.enableCore(new BukkitEnableCoreCallback())) {
this.setEnabled(false);
return;
}

View File

@ -14,6 +14,8 @@ import java.util.List;
import javax.imageio.ImageIO;
import org.bukkit.Material;
import org.bukkit.plugin.Plugin;
import org.dynmap.DynmapCore;
import org.dynmap.Log;
import org.getspout.spoutapi.block.design.BlockDesign;
import org.getspout.spoutapi.block.design.GenericBlockDesign;
@ -70,12 +72,25 @@ public class SpoutPluginBlocks {
}
/* Process spout blocks - return true if something changed */
public boolean processSpoutBlocks(File datadir) {
public boolean processSpoutBlocks(DynmapPlugin plugin, DynmapCore core) {
/* First, see if any spout plugins that need to be enabled */
for(Plugin p : plugin.getServer().getPluginManager().getPlugins()) {
List<String> dep = p.getDescription().getDepend();
if((dep != null) && (dep.contains("Spout"))) {
Log.info("Found Spout plugin: " + p.getName());
if(p.isEnabled() == false) {
plugin.getPluginLoader().enablePlugin(p);
}
}
}
File datadir = core.getDataFolder();
if(textYPosField == null) {
if(initSpoutAccess() == false)
return false;
}
HashMap<String, String> texturelist = new HashMap<String, String>();
boolean use_existing_texture = core.configuration.getBoolean("spout/use-existing-textures", true);
int cnt = 0;
File f = new File(datadir, "texturepacks/standard/spout");
@ -125,53 +140,59 @@ public class SpoutPluginBlocks {
String txtid = texturelist.get(txname); /* Get texture */
if(txtid == null) { /* Not found yet */
File imgfile = new File(f, blkid + ".png");
BufferedImage img = null;
boolean urlloaded = false;
try {
URL url = new URL(txname);
img = ImageIO.read(url); /* Load skin for player */
urlloaded = true;
} catch (IOException iox) {
if(txname.startsWith("http") == false) { /* Not URL - try file */
File tf = new File(txname);
if(tf.exists() == false) {
/* Horrible hack - try to find temp file (some SpoutMaterials versions) */
try {
File tmpf = File.createTempFile("dynmap", "test");
tf = new File(tmpf.getParent(), txname);
tmpf.delete();
} catch (IOException iox2) {}
/* If not reusing loaded textures OR not previously loaded */
if((!use_existing_texture) || (!imgfile.exists())) {
BufferedImage img = null;
boolean urlloaded = false;
try {
URL url = new URL(txname);
img = ImageIO.read(url); /* Load skin for player */
urlloaded = true;
} catch (IOException iox) {
if(txname.startsWith("http") == false) { /* Not URL - try file */
File tf = new File(txname);
if(tf.exists() == false) {
/* Horrible hack - try to find temp file (some SpoutMaterials versions) */
try {
File tmpf = File.createTempFile("dynmap", "test");
tf = new File(tmpf.getParent(), txname);
tmpf.delete();
} catch (IOException iox2) {}
}
if(tf.exists()) {
try {
img = ImageIO.read(tf);
urlloaded = true;
} catch (IOException iox3) {
}
}
}
if(tf.exists()) {
try {
img = ImageIO.read(tf);
urlloaded = true;
} catch (IOException iox3) {
if(img == null) {
Log.severe("Error loading texture for custom block '" + blkid + "' (" + b.getCustomId() + ") from " + txname + "(" + iox.getMessage() + ")");
if(imgfile.exists()) {
try {
img = ImageIO.read(imgfile); /* Load existing */
Log.info("Loaded cached texture file for " + blkid);
} catch (IOException iox2) {
Log.severe("Error loading cached texture file for " + blkid + " - " + iox2.getMessage());
}
}
}
}
if(img == null) {
Log.severe("Error loading texture for custom block '" + blkid + "' (" + b.getCustomId() + ") from " + txname + "(" + iox.getMessage() + ")");
if(imgfile.exists()) {
try {
img = ImageIO.read(imgfile); /* Load existing */
Log.info("Loaded cached texture file for " + blkid);
} catch (IOException iox2) {
Log.severe("Error loading cached texture file for " + blkid + " - " + iox2.getMessage());
}
if(img != null) {
try {
if(urlloaded)
ImageIO.write(img, "png", imgfile);
} catch (IOException iox) {
Log.severe("Error writing " + blkid + ".png");
} finally {
img.flush();
}
}
}
if(img != null) {
try {
if(urlloaded)
ImageIO.write(img, "png", imgfile);
} catch (IOException iox) {
Log.severe("Error writing " + blkid + ".png");
} finally {
img.flush();
}
if(imgfile.exists()) { /* If exists now, log it */
String tfid = "txtid" + texturelist.size();
sb.append("texturefile:id=" + tfid + ",filename=spout/" + blkid + ".png,xcount=" + w/sz + ",ycount=" + h/sz + "\n");
texturelist.put(txname, tfid);

View File

@ -377,6 +377,15 @@ url:
# markers base URL
#markers: "tiles/"
# Spout support controls
spout:
# If false, ignore spout even if detected
enabled: true
# If true, previously loaded textures will be assumed to still be valid (faster startup, but
# can result in stale textures if originals are updated - delete files in texturepacks/standard/spoout
# to clean cached textures and force reload on next startup)
use-existing-textures: true
# Set to true to enable verbose startup messages - can help with debugging map configuration problems
# Set to false for a much quieter startup log
verbose: false

View File

@ -2,7 +2,7 @@ name: dynmap
main: org.dynmap.bukkit.DynmapPlugin
version: "${project.version}-${BUILD_NUMBER}"
authors: [FrozenCow, mikeprimm]
softdepend: [ Permissions, PermissionEx, bPermissions, PermissionsBukkit, SpoutMaterials ]
softdepend: [ Permissions, PermissionEx, bPermissions, PermissionsBukkit ]
commands:
dynmap:
description: Controls Dynmap.