Add spout controls (enable/disable, use-existing-textures), load other spout mods first
This commit is contained in:
parent
a7740f2dc9
commit
edb6f75014
4 changed files with 92 additions and 51 deletions
|
|
@ -96,6 +96,25 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||||
public SpoutPluginBlocks spb;
|
public SpoutPluginBlocks spb;
|
||||||
public PluginManager pm;
|
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 {
|
private static class BlockToCheck {
|
||||||
Location loc;
|
Location loc;
|
||||||
int typeid;
|
int typeid;
|
||||||
|
|
@ -568,14 +587,6 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||||
if(dataDirectory.exists() == false)
|
if(dataDirectory.exists() == false)
|
||||||
dataDirectory.mkdirs();
|
dataDirectory.mkdirs();
|
||||||
|
|
||||||
/* Check for Spout */
|
|
||||||
if(detectSpout()) {
|
|
||||||
has_spout = true;
|
|
||||||
Log.info("Detected Spout");
|
|
||||||
spb = new SpoutPluginBlocks();
|
|
||||||
spb.processSpoutBlocks(dataDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get MC version */
|
/* Get MC version */
|
||||||
String bukkitver = getServer().getVersion();
|
String bukkitver = getServer().getVersion();
|
||||||
String mcver = "1.0.0";
|
String mcver = "1.0.0";
|
||||||
|
|
@ -596,7 +607,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||||
core.setServer(new BukkitServer());
|
core.setServer(new BukkitServer());
|
||||||
|
|
||||||
/* Enable core */
|
/* Enable core */
|
||||||
if(!core.enableCore()) {
|
if(!core.enableCore(new BukkitEnableCoreCallback())) {
|
||||||
this.setEnabled(false);
|
this.setEnabled(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import java.util.List;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.dynmap.DynmapCore;
|
||||||
import org.dynmap.Log;
|
import org.dynmap.Log;
|
||||||
import org.getspout.spoutapi.block.design.BlockDesign;
|
import org.getspout.spoutapi.block.design.BlockDesign;
|
||||||
import org.getspout.spoutapi.block.design.GenericBlockDesign;
|
import org.getspout.spoutapi.block.design.GenericBlockDesign;
|
||||||
|
|
@ -70,12 +72,25 @@ public class SpoutPluginBlocks {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process spout blocks - return true if something changed */
|
/* 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(textYPosField == null) {
|
||||||
if(initSpoutAccess() == false)
|
if(initSpoutAccess() == false)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HashMap<String, String> texturelist = new HashMap<String, String>();
|
HashMap<String, String> texturelist = new HashMap<String, String>();
|
||||||
|
boolean use_existing_texture = core.configuration.getBoolean("spout/use-existing-textures", true);
|
||||||
|
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
File f = new File(datadir, "texturepacks/standard/spout");
|
File f = new File(datadir, "texturepacks/standard/spout");
|
||||||
|
|
@ -125,53 +140,59 @@ public class SpoutPluginBlocks {
|
||||||
String txtid = texturelist.get(txname); /* Get texture */
|
String txtid = texturelist.get(txname); /* Get texture */
|
||||||
if(txtid == null) { /* Not found yet */
|
if(txtid == null) { /* Not found yet */
|
||||||
File imgfile = new File(f, blkid + ".png");
|
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);
|
/* If not reusing loaded textures OR not previously loaded */
|
||||||
tmpf.delete();
|
if((!use_existing_texture) || (!imgfile.exists())) {
|
||||||
} catch (IOException iox2) {}
|
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()) {
|
if(img == null) {
|
||||||
try {
|
Log.severe("Error loading texture for custom block '" + blkid + "' (" + b.getCustomId() + ") from " + txname + "(" + iox.getMessage() + ")");
|
||||||
img = ImageIO.read(tf);
|
if(imgfile.exists()) {
|
||||||
urlloaded = true;
|
try {
|
||||||
} catch (IOException iox3) {
|
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) {
|
if(img != null) {
|
||||||
Log.severe("Error loading texture for custom block '" + blkid + "' (" + b.getCustomId() + ") from " + txname + "(" + iox.getMessage() + ")");
|
try {
|
||||||
if(imgfile.exists()) {
|
if(urlloaded)
|
||||||
try {
|
ImageIO.write(img, "png", imgfile);
|
||||||
img = ImageIO.read(imgfile); /* Load existing */
|
} catch (IOException iox) {
|
||||||
Log.info("Loaded cached texture file for " + blkid);
|
Log.severe("Error writing " + blkid + ".png");
|
||||||
} catch (IOException iox2) {
|
} finally {
|
||||||
Log.severe("Error loading cached texture file for " + blkid + " - " + iox2.getMessage());
|
img.flush();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(img != null) {
|
if(imgfile.exists()) { /* If exists now, log it */
|
||||||
try {
|
|
||||||
if(urlloaded)
|
|
||||||
ImageIO.write(img, "png", imgfile);
|
|
||||||
} catch (IOException iox) {
|
|
||||||
Log.severe("Error writing " + blkid + ".png");
|
|
||||||
} finally {
|
|
||||||
img.flush();
|
|
||||||
}
|
|
||||||
String tfid = "txtid" + texturelist.size();
|
String tfid = "txtid" + texturelist.size();
|
||||||
sb.append("texturefile:id=" + tfid + ",filename=spout/" + blkid + ".png,xcount=" + w/sz + ",ycount=" + h/sz + "\n");
|
sb.append("texturefile:id=" + tfid + ",filename=spout/" + blkid + ".png,xcount=" + w/sz + ",ycount=" + h/sz + "\n");
|
||||||
texturelist.put(txname, tfid);
|
texturelist.put(txname, tfid);
|
||||||
|
|
|
||||||
|
|
@ -377,6 +377,15 @@ url:
|
||||||
# markers base URL
|
# markers base URL
|
||||||
#markers: "tiles/"
|
#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 true to enable verbose startup messages - can help with debugging map configuration problems
|
||||||
# Set to false for a much quieter startup log
|
# Set to false for a much quieter startup log
|
||||||
verbose: false
|
verbose: false
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ name: dynmap
|
||||||
main: org.dynmap.bukkit.DynmapPlugin
|
main: org.dynmap.bukkit.DynmapPlugin
|
||||||
version: "${project.version}-${BUILD_NUMBER}"
|
version: "${project.version}-${BUILD_NUMBER}"
|
||||||
authors: [FrozenCow, mikeprimm]
|
authors: [FrozenCow, mikeprimm]
|
||||||
softdepend: [ Permissions, PermissionEx, bPermissions, PermissionsBukkit, SpoutMaterials ]
|
softdepend: [ Permissions, PermissionEx, bPermissions, PermissionsBukkit ]
|
||||||
commands:
|
commands:
|
||||||
dynmap:
|
dynmap:
|
||||||
description: Controls Dynmap.
|
description: Controls Dynmap.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue