Workaround Spout custom block URL-that-are-temp-filename insanity

This commit is contained in:
Mike Primm 2012-01-26 17:12:49 -06:00
parent aae09c54db
commit a1e27a63ed

View File

@ -41,18 +41,41 @@ public class SpoutPluginBlocks {
File imgfile = new File(f, blkid + ".png"); File imgfile = new File(f, blkid + ".png");
BufferedImage img = null; BufferedImage img = null;
boolean urlloaded = false; boolean urlloaded = false;
String txname = bd.getTexureURL();
try { try {
URL url = new URL(bd.getTexureURL()); URL url = new URL(txname);
img = ImageIO.read(url); /* Load skin for player */ img = ImageIO.read(url); /* Load skin for player */
urlloaded = true; urlloaded = true;
} catch (IOException iox) { } catch (IOException iox) {
Log.severe("Error loading texture for custom block '" + blkid + "' (" + b.getCustomId() + ") from " + bd.getTexureURL() + "(" + iox.getMessage() + ")"); if(txname.startsWith("http") == false) { /* Not URL - try file */
if(imgfile.exists()) { File tf = new File(txname);
try { if(tf.exists() == false) {
img = ImageIO.read(imgfile); /* Load existing */ /* Horrible hack - try to find temp file (some SpoutMaterials versions) */
Log.info("Loaded cached texture file for " + blkid); try {
} catch (IOException iox2) { File tmpf = File.createTempFile("dynmap", "test");
Log.severe("Error loading cached texture file for " + blkid + " - " + iox2.getMessage());
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(img == null) {
Log.severe("Error loading texture for custom block '" + blkid + "' (" + b.getCustomId() + ") from " + bd.getTexureURL() + "(" + 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());
}
} }
} }
} }