mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2025-02-15 02:51:20 +01:00
* OPT: The map database is now thread-safe.
This commit is contained in:
parent
b192214609
commit
860fed25e5
@ -86,31 +86,32 @@ public class ImageRendererExecutor extends Worker
|
||||
|
||||
static private ImageMap RenderSingle(final BufferedImage image, final UUID playerUUID) throws Throwable
|
||||
{
|
||||
final short mapID = instance.submitToMainThread(new Callable<Short>()
|
||||
Future<Short> futureMapID = instance.submitToMainThread(new Callable<Short>()
|
||||
{
|
||||
@Override
|
||||
public Short call() throws Exception
|
||||
{
|
||||
return MapManager.getNewMapsIds(1)[0];
|
||||
}
|
||||
}).get();
|
||||
});
|
||||
|
||||
final BufferedImage finalImage = ResizeImage(image, ImageMap.WIDTH, ImageMap.HEIGHT);
|
||||
|
||||
final short mapID = futureMapID.get();
|
||||
ImageIOExecutor.saveImage(mapID, finalImage);
|
||||
|
||||
final ImageMap newMap = instance.submitToMainThread(new Callable<ImageMap>()
|
||||
instance.submitToMainThread(new Callable<Void>()
|
||||
{
|
||||
@Override
|
||||
public ImageMap call() throws Exception
|
||||
public Void call() throws Exception
|
||||
{
|
||||
Renderer.installRenderer(finalImage, mapID);
|
||||
return MapManager.createMap(playerUUID, mapID);
|
||||
return null;
|
||||
}
|
||||
|
||||
}).get();
|
||||
});
|
||||
|
||||
return newMap;
|
||||
return MapManager.createMap(playerUUID, mapID);
|
||||
}
|
||||
|
||||
static private ImageMap RenderPoster(final BufferedImage image, final UUID playerUUID) throws Throwable
|
||||
@ -133,18 +134,18 @@ public class ImageRendererExecutor extends Worker
|
||||
|
||||
ImageIOExecutor.saveImage(mapsIDs, poster);
|
||||
|
||||
final ImageMap newMap = instance.submitToMainThread(new Callable<ImageMap>()
|
||||
instance.submitToMainThread(new Callable<Void>()
|
||||
{
|
||||
@Override
|
||||
public ImageMap call() throws Exception
|
||||
public Void call() throws Exception
|
||||
{
|
||||
Renderer.installRenderer(poster, mapsIDs);
|
||||
return MapManager.createMap(poster, playerUUID, mapsIDs);
|
||||
return null;
|
||||
}
|
||||
|
||||
}).get();
|
||||
});
|
||||
|
||||
return newMap;
|
||||
return MapManager.createMap(poster, playerUUID, mapsIDs);
|
||||
}
|
||||
|
||||
static private BufferedImage ResizeImage(BufferedImage source, int destinationW, int destinationH)
|
||||
|
@ -119,9 +119,9 @@ public abstract class ImageMap implements ConfigurationSerializable
|
||||
public Map<String, Object> serialize()
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("id", id);
|
||||
map.put("id", getId());
|
||||
map.put("type", mapType.toString());
|
||||
map.put("name", name);
|
||||
map.put("name", getName());
|
||||
this.postSerialize(map);
|
||||
return map;
|
||||
}
|
||||
@ -153,17 +153,17 @@ public abstract class ImageMap implements ConfigurationSerializable
|
||||
return userUUID;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
public synchronized String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
public synchronized String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void rename(String id, String name)
|
||||
public synchronized void rename(String id, String name)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
@ -171,8 +171,7 @@ public abstract class ImageMap implements ConfigurationSerializable
|
||||
|
||||
public void rename(String name)
|
||||
{
|
||||
if(this.name.equals(name)) return;
|
||||
this.id = MapManager.getNextAvailableMapID(name, userUUID);
|
||||
this.name = name;
|
||||
if(getName().equals(name)) return;
|
||||
rename(MapManager.getNextAvailableMapID(name, getUserUUID()), name);
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class PlayerMapStore implements ConfigurationSerializable
|
||||
this.playerUUID = playerUUID;
|
||||
}
|
||||
|
||||
public boolean managesMap(short mapID)
|
||||
public synchronized boolean managesMap(short mapID)
|
||||
{
|
||||
for(ImageMap map : mapList)
|
||||
{
|
||||
@ -54,7 +54,7 @@ public class PlayerMapStore implements ConfigurationSerializable
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean managesMap(ItemStack item)
|
||||
public synchronized boolean managesMap(ItemStack item)
|
||||
{
|
||||
for(ImageMap map : mapList)
|
||||
{
|
||||
@ -63,19 +63,19 @@ public class PlayerMapStore implements ConfigurationSerializable
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addMap(ImageMap map)
|
||||
public synchronized void addMap(ImageMap map)
|
||||
{
|
||||
mapList.add(map);
|
||||
notifyModification();
|
||||
}
|
||||
|
||||
public void deleteMap(ImageMap map)
|
||||
public synchronized void deleteMap(ImageMap map)
|
||||
{
|
||||
mapList.remove(map);
|
||||
notifyModification();
|
||||
}
|
||||
|
||||
public boolean mapExists(String id)
|
||||
public synchronized boolean mapExists(String id)
|
||||
{
|
||||
for(ImageMap map : mapList)
|
||||
{
|
||||
@ -98,12 +98,12 @@ public class PlayerMapStore implements ConfigurationSerializable
|
||||
return mapId + "-" + id;
|
||||
}
|
||||
|
||||
public List<ImageMap> getMapList()
|
||||
public synchronized List<ImageMap> getMapList()
|
||||
{
|
||||
return new ArrayList(mapList);
|
||||
}
|
||||
|
||||
public ImageMap getMap(String mapId)
|
||||
public synchronized ImageMap getMap(String mapId)
|
||||
{
|
||||
for(ImageMap map : mapList)
|
||||
{
|
||||
@ -120,12 +120,12 @@ public class PlayerMapStore implements ConfigurationSerializable
|
||||
return playerUUID;
|
||||
}
|
||||
|
||||
public boolean isModified()
|
||||
public synchronized boolean isModified()
|
||||
{
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void notifyModification()
|
||||
public synchronized void notifyModification()
|
||||
{
|
||||
this.modified = true;
|
||||
}
|
||||
@ -137,7 +137,7 @@ public class PlayerMapStore implements ConfigurationSerializable
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
ArrayList<Map> list = new ArrayList<Map>();
|
||||
synchronized(mapList)
|
||||
synchronized(this)
|
||||
{
|
||||
for(ImageMap tMap : mapList)
|
||||
{
|
||||
@ -153,18 +153,17 @@ public class PlayerMapStore implements ConfigurationSerializable
|
||||
if(section == null) return;
|
||||
List<Map<String, Object>> list = (List<Map<String, Object>>) section.getList("mapList");
|
||||
if(list == null) return;
|
||||
synchronized(mapList)
|
||||
|
||||
for(Map<String, Object> tMap : list)
|
||||
{
|
||||
for(Map<String, Object> tMap : list)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
mapList.add(ImageMap.fromConfig(tMap, playerUUID));
|
||||
}
|
||||
catch(InvalidConfigurationException ex)
|
||||
{
|
||||
PluginLogger.LogWarning("Could not load map data : " + ex.getMessage());
|
||||
}
|
||||
ImageMap newMap = ImageMap.fromConfig(tMap, playerUUID);
|
||||
synchronized(this) {mapList.add(newMap);}
|
||||
}
|
||||
catch(InvalidConfigurationException ex)
|
||||
{
|
||||
PluginLogger.LogWarning("Could not load map data : " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -205,6 +204,6 @@ public class PlayerMapStore implements ConfigurationSerializable
|
||||
PluginLogger.LogError("Could not save maps file for player " + playerUUID.toString(), ex);
|
||||
}
|
||||
PluginLogger.LogInfo("Saving maps file for " + playerUUID.toString());
|
||||
modified = false;
|
||||
synchronized(this) {modified = false;}
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
||||
|
||||
public class PosterMap extends ImageMap
|
||||
{
|
||||
protected short[] mapsIDs;
|
||||
protected int columnCount;
|
||||
protected int rowCount;
|
||||
protected final short[] mapsIDs;
|
||||
protected final int columnCount;
|
||||
protected final int rowCount;
|
||||
|
||||
public PosterMap(UUID userUUID, short[] mapsIDs, int columnCount, int rowCount)
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
||||
|
||||
public class SingleMap extends ImageMap
|
||||
{
|
||||
protected short mapID;
|
||||
protected final short mapID;
|
||||
|
||||
public SingleMap(UUID ownerUUID, short mapID)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user