Better Management for missing maps.

* NEW: Migration now ignores maps that are missing from the save.
* BUG: Fix NPEs being thrown when trying to handle missing maps.
* BUG: Fix some typos in the french translation.
This commit is contained in:
Adrien Prokopowicz 2016-07-08 01:15:02 +02:00
parent 97e62c1a14
commit 225c76de7c
6 changed files with 72 additions and 7 deletions

View File

@ -18,6 +18,7 @@
package fr.moribus.imageonmap.image;
import fr.zcraft.zlib.tools.PluginLogger;
import java.awt.image.BufferedImage;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -29,6 +30,7 @@ public class Renderer extends MapRenderer
{
static public boolean isHandled(MapView map)
{
if(map == null) return false;
for(MapRenderer renderer : map.getRenderers())
{
if(renderer instanceof Renderer) return true;
@ -46,7 +48,15 @@ public class Renderer extends MapRenderer
static public void installRenderer(BufferedImage image, short mapID)
{
installRenderer(Bukkit.getMap(mapID)).setImage(image);
MapView map = Bukkit.getMap(mapID);
if(map == null)
{
PluginLogger.warning("Could not install renderer for map {0} : the Minecraft map does not exist", mapID);
}
else
{
installRenderer(map).setImage(image);
}
}
static public Renderer installRenderer(MapView map)

View File

@ -307,6 +307,23 @@ abstract public class MapManager
return mapCount;
}
/**
* Returns if the given map ID is valid and exists in the current save.
* @param mapId the map ID.
* @return true if the given map ID is valid and exists in the current save, false otherwise.
*/
static public boolean mapIdExists(short mapId)
{
try
{
return Bukkit.getMap(mapId) != null;
}
catch(Throwable ex)
{
return false;
}
}
static private PlayerMapStore getPlayerMapStore(UUID playerUUID)
{
PlayerMapStore store;

View File

@ -19,6 +19,7 @@
package fr.moribus.imageonmap.migration;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.SingleMap;
import java.util.ArrayList;
import java.util.List;
@ -73,6 +74,11 @@ class OldSavedMap
configuration.set(mapName, data);
}
public boolean isMapValid()
{
return MapManager.mapIdExists(mapId);
}
public short getMapId() {return mapId;}
public String getUserName() {return userName;}
}

View File

@ -19,6 +19,7 @@
package fr.moribus.imageonmap.migration;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.PosterMap;
import java.util.ArrayList;
import java.util.List;
@ -94,5 +95,16 @@ class OldSavedPoster
}
public String getUserName() {return userName;}
public boolean isMapValid()
{
for(short mapId : mapsIds)
{
if(!MapManager.mapIdExists(mapId))
return false;
}
return true;
}
public String getUserName() {return userName;}
public short[] getMapsIds() {return mapsIds;}
}

View File

@ -39,9 +39,12 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
/**
* This class represents and executes the ImageOnMap v3.x migration process
@ -241,7 +244,7 @@ public class V3Migrator implements Runnable
*/
private void backupMapData() throws IOException
{
PluginLogger.info("Backing up map data before migrating...");
PluginLogger.info(I.t("Backing up map data before migrating..."));
if(!backupsPrev3Directory.exists()) backupsPrev3Directory.mkdirs();
if(!backupsPostv3Directory.exists()) backupsPostv3Directory.mkdirs();
@ -265,7 +268,7 @@ public class V3Migrator implements Runnable
verifiedBackupCopy(mapFile, backupFile);
}
PluginLogger.info("Backup complete.");
PluginLogger.info(I.t("Backup complete."));
}
/**
@ -307,7 +310,7 @@ public class V3Migrator implements Runnable
}
catch(InvalidConfigurationException ex)
{
PluginLogger.warning("Could not read poster data for key '{0}'", ex, key);
PluginLogger.warning("Could not read poster data for key {0}", ex, key);
}
}
}
@ -424,6 +427,8 @@ public class V3Migrator implements Runnable
ArrayDeque<OldSavedMap> remainingMaps = new ArrayDeque<>();
ArrayDeque<OldSavedPoster> remainingPosters = new ArrayDeque<>();
ArrayDeque<Short> missingMapIds = new ArrayDeque<>();
UUID playerUUID;
OldSavedMap map;
while(!mapsToMigrate.isEmpty())
@ -434,6 +439,10 @@ public class V3Migrator implements Runnable
{
remainingMaps.add(map);
}
else if(!map.isMapValid())
{
missingMapIds.add(map.getMapId());
}
else
{
MapManager.insertMap(map.toImageMap(playerUUID));
@ -450,12 +459,23 @@ public class V3Migrator implements Runnable
{
remainingPosters.add(poster);
}
else if(!poster.isMapValid())
{
missingMapIds.addAll(Arrays.asList(ArrayUtils.toObject(poster.getMapsIds())));
}
else
{
MapManager.insertMap(poster.toImageMap(playerUUID));
}
}
postersToMigrate.addAll(remainingPosters);
if(!missingMapIds.isEmpty())
{
PluginLogger.warning(I.tn("{0} registered minecraft map is missing from the save.", "{0} registered minecraft maps are missing from the save.", missingMapIds.size()));
PluginLogger.warning(I.t("These maps will not be migrated, but this could mean the save has been altered or corrupted."));
PluginLogger.warning(I.t("The following maps are missing : {0} ", StringUtils.join(missingMapIds, ',')));
}
}
private void saveChanges()

View File

@ -403,7 +403,7 @@ msgstr "Terminé."
#: src/main/java/fr/moribus/imageonmap/migration/V3Migrator.java:229
msgid "Backup directories already exists."
msgstr "Les répertoires de sauvegarde existe déjà."
msgstr "Les répertoires de sauvegarde existent déjà."
#: src/main/java/fr/moribus/imageonmap/migration/V3Migrator.java:230
msgid ""
@ -441,7 +441,7 @@ msgstr "Le processus de migration a été interrompu."
msgid "Fetching done. {0} UUID have been retrieved."
msgid_plural "Fetching done. {0} UUIDs have been retrieved."
msgstr[0] "Récupération achevée. {0} UUID a été retrouvé."
msgstr[1] "Récupération achevée. {0} UUID ont été retrouvé."
msgstr[1] "Récupération achevée. {0} UUIDs ont été retrouvés."
#: src/main/java/fr/moribus/imageonmap/migration/V3Migrator.java:371
#, java-format
@ -511,7 +511,7 @@ msgstr[1] "{0} posters n'ont pas pu être migrés."
msgid "Data that has not been migrated will be kept in the old data files."
msgstr ""
"Les données qui n'ont pas été migrées seront conservées dans les vieux "
"fichiers de donnée."
"fichiers de données."
#. The name of a map item given to a player, if splatter maps are not used. 0 = map name; 1 = row; 2 = column.
#: src/main/java/fr/moribus/imageonmap/ui/MapItemManager.java:118