From 37530f97ae5d9d30a2a65d565db92e2437cd25bd Mon Sep 17 00:00:00 2001 From: Li REN Date: Thu, 13 Jun 2013 20:23:26 -0400 Subject: [PATCH] Update ThemePluginImpl, know the client can randomly choose images in plugins/plugin.data/background/, nothing will be effect if there is no image files. --- .../java/org/mage/plugins/theme/ThemePluginImpl.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Mage.Plugins/Mage.Theme.Plugin/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java b/Mage.Plugins/Mage.Theme.Plugin/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java index d26a8298d6..3fecc7dee5 100644 --- a/Mage.Plugins/Mage.Theme.Plugin/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java +++ b/Mage.Plugins/Mage.Theme.Plugin/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java @@ -42,6 +42,7 @@ public class ThemePluginImpl implements ThemePlugin { public boolean loadimages(){ File filedir = new File(BackgroundDir); File[] filelist = filedir.listFiles(); + if(filelist == null) return false; if(filelist.length == 0) return false; for(File f:filelist){ String filename = f.getName().toLowerCase(); @@ -55,14 +56,19 @@ public class ThemePluginImpl implements ThemePlugin { } public void applyInGame(Map ui) { String filename; + BufferedImage background; + try { if(loadimages()){ int it = (int)Math.abs(Math.random()*(flist.getItemCount())); - filename = BackgroundDir + flist.getItem(it); + filename = BackgroundDir + flist.getItem(it); + background = ImageIO.read(new File(filename)); }else{ filename = "/dragon.png"; + InputStream is = this.getClass().getResourceAsStream(filename); + if (is == null) + throw new FileNotFoundException("Couldn't find " + filename + " in resources."); + background = ImageIO.read(is); } - try { - BufferedImage background = ImageIO.read(new File(filename)); if (background == null) { throw new FileNotFoundException("Couldn't find " + filename + " in resources.");