* NEW: The plugin now tries to load images from the old "Image" directory if the new one does not exist.

This commit is contained in:
Prokopyl 2015-04-08 14:17:10 +02:00
parent b87dfdf231
commit aa27636962
2 changed files with 57 additions and 19 deletions

View File

@ -23,8 +23,10 @@ import fr.moribus.imageonmap.image.ImageIOExecutor;
import fr.moribus.imageonmap.image.ImageRendererExecutor;
import fr.moribus.imageonmap.image.MapInitEvent;
import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.migration.V3Migrator;
import fr.moribus.imageonmap.ui.MapItemManager;
import java.io.File;
import java.io.IOException;
import org.bukkit.plugin.java.JavaPlugin;
public final class ImageOnMap extends JavaPlugin
@ -33,7 +35,7 @@ public final class ImageOnMap extends JavaPlugin
static private final String MAPS_DIRECTORY_NAME = "maps";
static private ImageOnMap plugin;
private final File imagesDirectory;
private File imagesDirectory;
private final File mapsDirectory;
public ImageOnMap()
@ -58,27 +60,19 @@ public final class ImageOnMap extends JavaPlugin
@Override
public void onEnable()
{
// Creating the images directory if necessary
if(!imagesDirectory.exists())
// Creating the images and maps directories if necessary
try
{
if(!imagesDirectory.mkdirs())
{
PluginLogger.LogError("FATAL : Could not create the images directory.", null);
this.setEnabled(false);
return;
}
imagesDirectory = checkPluginDirectory(imagesDirectory, V3Migrator.getOldImagesDirectory(this));
checkPluginDirectory(mapsDirectory);
}
catch(IOException ex)
{
PluginLogger.LogError("FATAL : " + ex.getMessage(), null);
this.setEnabled(false);
return;
}
if(!mapsDirectory.exists())
{
if(!mapsDirectory.mkdirs())
{
PluginLogger.LogError("FATAL : Could not create the images directory.", null);
this.setEnabled(false);
return;
}
}
//Init all the things !
PluginConfiguration.init(this);
MetricsLite.startMetrics();
@ -98,5 +92,17 @@ public final class ImageOnMap extends JavaPlugin
MapManager.exit();
MapItemManager.exit();
}
private File checkPluginDirectory(File primaryFile, File... alternateFiles) throws IOException
{
if(primaryFile.exists()) return primaryFile;
for(File file : alternateFiles)
{
if(file.exists()) return file;
}
if(!primaryFile.mkdirs())
throw new IOException("Could not create '" + primaryFile.getName() + "' plugin directory.");
return primaryFile;
}
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2013 Moribus
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.moribus.imageonmap.migration;
import java.io.File;
import org.bukkit.plugin.Plugin;
public class V3Migrator
{
static private final String OLD_IMAGES_DIRECTORY_NAME = "Image";
static public File getOldImagesDirectory(Plugin plugin)
{
return new File(plugin.getDataFolder(), OLD_IMAGES_DIRECTORY_NAME);
}
}