mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2024-11-25 11:35:35 +01:00
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:
parent
97e62c1a14
commit
225c76de7c
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package fr.moribus.imageonmap.image;
|
package fr.moribus.imageonmap.image;
|
||||||
|
|
||||||
|
import fr.zcraft.zlib.tools.PluginLogger;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -29,6 +30,7 @@ public class Renderer extends MapRenderer
|
|||||||
{
|
{
|
||||||
static public boolean isHandled(MapView map)
|
static public boolean isHandled(MapView map)
|
||||||
{
|
{
|
||||||
|
if(map == null) return false;
|
||||||
for(MapRenderer renderer : map.getRenderers())
|
for(MapRenderer renderer : map.getRenderers())
|
||||||
{
|
{
|
||||||
if(renderer instanceof Renderer) return true;
|
if(renderer instanceof Renderer) return true;
|
||||||
@ -46,7 +48,15 @@ public class Renderer extends MapRenderer
|
|||||||
|
|
||||||
static public void installRenderer(BufferedImage image, short mapID)
|
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)
|
static public Renderer installRenderer(MapView map)
|
||||||
|
@ -307,6 +307,23 @@ abstract public class MapManager
|
|||||||
return mapCount;
|
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)
|
static private PlayerMapStore getPlayerMapStore(UUID playerUUID)
|
||||||
{
|
{
|
||||||
PlayerMapStore store;
|
PlayerMapStore store;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package fr.moribus.imageonmap.migration;
|
package fr.moribus.imageonmap.migration;
|
||||||
|
|
||||||
import fr.moribus.imageonmap.map.ImageMap;
|
import fr.moribus.imageonmap.map.ImageMap;
|
||||||
|
import fr.moribus.imageonmap.map.MapManager;
|
||||||
import fr.moribus.imageonmap.map.SingleMap;
|
import fr.moribus.imageonmap.map.SingleMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -73,6 +74,11 @@ class OldSavedMap
|
|||||||
configuration.set(mapName, data);
|
configuration.set(mapName, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMapValid()
|
||||||
|
{
|
||||||
|
return MapManager.mapIdExists(mapId);
|
||||||
|
}
|
||||||
|
|
||||||
public short getMapId() {return mapId;}
|
public short getMapId() {return mapId;}
|
||||||
public String getUserName() {return userName;}
|
public String getUserName() {return userName;}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package fr.moribus.imageonmap.migration;
|
package fr.moribus.imageonmap.migration;
|
||||||
|
|
||||||
import fr.moribus.imageonmap.map.ImageMap;
|
import fr.moribus.imageonmap.map.ImageMap;
|
||||||
|
import fr.moribus.imageonmap.map.MapManager;
|
||||||
import fr.moribus.imageonmap.map.PosterMap;
|
import fr.moribus.imageonmap.map.PosterMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -94,5 +95,16 @@ class OldSavedPoster
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMapValid()
|
||||||
|
{
|
||||||
|
for(short mapId : mapsIds)
|
||||||
|
{
|
||||||
|
if(!MapManager.mapIdExists(mapId))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUserName() {return userName;}
|
public String getUserName() {return userName;}
|
||||||
|
public short[] getMapsIds() {return mapsIds;}
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,12 @@ import java.security.MessageDigest;
|
|||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
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
|
* 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
|
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(!backupsPrev3Directory.exists()) backupsPrev3Directory.mkdirs();
|
||||||
if(!backupsPostv3Directory.exists()) backupsPostv3Directory.mkdirs();
|
if(!backupsPostv3Directory.exists()) backupsPostv3Directory.mkdirs();
|
||||||
@ -265,7 +268,7 @@ public class V3Migrator implements Runnable
|
|||||||
verifiedBackupCopy(mapFile, backupFile);
|
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)
|
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<OldSavedMap> remainingMaps = new ArrayDeque<>();
|
||||||
ArrayDeque<OldSavedPoster> remainingPosters = new ArrayDeque<>();
|
ArrayDeque<OldSavedPoster> remainingPosters = new ArrayDeque<>();
|
||||||
|
|
||||||
|
ArrayDeque<Short> missingMapIds = new ArrayDeque<>();
|
||||||
|
|
||||||
UUID playerUUID;
|
UUID playerUUID;
|
||||||
OldSavedMap map;
|
OldSavedMap map;
|
||||||
while(!mapsToMigrate.isEmpty())
|
while(!mapsToMigrate.isEmpty())
|
||||||
@ -434,6 +439,10 @@ public class V3Migrator implements Runnable
|
|||||||
{
|
{
|
||||||
remainingMaps.add(map);
|
remainingMaps.add(map);
|
||||||
}
|
}
|
||||||
|
else if(!map.isMapValid())
|
||||||
|
{
|
||||||
|
missingMapIds.add(map.getMapId());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MapManager.insertMap(map.toImageMap(playerUUID));
|
MapManager.insertMap(map.toImageMap(playerUUID));
|
||||||
@ -450,12 +459,23 @@ public class V3Migrator implements Runnable
|
|||||||
{
|
{
|
||||||
remainingPosters.add(poster);
|
remainingPosters.add(poster);
|
||||||
}
|
}
|
||||||
|
else if(!poster.isMapValid())
|
||||||
|
{
|
||||||
|
missingMapIds.addAll(Arrays.asList(ArrayUtils.toObject(poster.getMapsIds())));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MapManager.insertMap(poster.toImageMap(playerUUID));
|
MapManager.insertMap(poster.toImageMap(playerUUID));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
postersToMigrate.addAll(remainingPosters);
|
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()
|
private void saveChanges()
|
||||||
|
@ -403,7 +403,7 @@ msgstr "Terminé."
|
|||||||
|
|
||||||
#: src/main/java/fr/moribus/imageonmap/migration/V3Migrator.java:229
|
#: src/main/java/fr/moribus/imageonmap/migration/V3Migrator.java:229
|
||||||
msgid "Backup directories already exists."
|
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
|
#: src/main/java/fr/moribus/imageonmap/migration/V3Migrator.java:230
|
||||||
msgid ""
|
msgid ""
|
||||||
@ -441,7 +441,7 @@ msgstr "Le processus de migration a été interrompu."
|
|||||||
msgid "Fetching done. {0} UUID have been retrieved."
|
msgid "Fetching done. {0} UUID have been retrieved."
|
||||||
msgid_plural "Fetching done. {0} UUIDs 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[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
|
#: src/main/java/fr/moribus/imageonmap/migration/V3Migrator.java:371
|
||||||
#, java-format
|
#, 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."
|
msgid "Data that has not been migrated will be kept in the old data files."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Les données qui n'ont pas été migrées seront conservées dans les vieux "
|
"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.
|
#. 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
|
#: src/main/java/fr/moribus/imageonmap/ui/MapItemManager.java:118
|
||||||
|
Loading…
Reference in New Issue
Block a user