mirror of
https://github.com/SydMontague/ImageMaps.git
synced 2024-11-26 04:15:16 +01:00
Reinstated null check and did some cleanup
This commit is contained in:
parent
af5804c92b
commit
84a014605a
@ -80,15 +80,21 @@ public class ImageMapDownloadCommand extends ImageMapSubCommand {
|
|||||||
|
|
||||||
try (InputStream str = connection.getInputStream()) {
|
try (InputStream str = connection.getInputStream()) {
|
||||||
BufferedImage image = ImageIO.read(str);
|
BufferedImage image = ImageIO.read(str);
|
||||||
|
if (image == null) {
|
||||||
|
MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.WARNING, "Downloaded file is not an image!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
File outFile = new File(plugin.getDataFolder(), "images" + File.separatorChar + filename);
|
File outFile = new File(plugin.getDataFolder(), "images" + File.separatorChar + filename);
|
||||||
boolean fileExisted = outFile.exists();
|
boolean fileExisted = outFile.exists();
|
||||||
ImageIO.write(image, "PNG", outFile);
|
ImageIO.write(image, "PNG", outFile);
|
||||||
|
|
||||||
if (fileExisted) {
|
if (fileExisted) {
|
||||||
MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.WARNING, "File already exists, overwriting!");
|
MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.WARNING, "File already exists, overwriting!");
|
||||||
getPlugin().reloadImage(filename);
|
getPlugin().reloadImage(filename);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.WARNING, "Downloaded file is not an image!");
|
MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.WARNING, "Received no data");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.NORMAL, "Download complete.");
|
MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.NORMAL, "Download complete.");
|
||||||
|
@ -374,21 +374,32 @@ public class ImageMaps extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
public boolean deleteImage(String filename) {
|
public boolean deleteImage(String filename) {
|
||||||
File file = new File(getDataFolder(), IMAGES_DIR + File.separatorChar + filename);
|
File file = new File(getDataFolder(), IMAGES_DIR + File.separatorChar + filename);
|
||||||
|
|
||||||
boolean fileDeleted = false;
|
boolean fileDeleted = false;
|
||||||
if (file.exists()) fileDeleted = file.delete();
|
if (file.exists()) {
|
||||||
|
fileDeleted = file.delete();
|
||||||
|
}
|
||||||
|
|
||||||
imageCache.remove(filename.toLowerCase());
|
imageCache.remove(filename.toLowerCase());
|
||||||
|
|
||||||
Iterator<Entry<ImageMap, Integer>> it = maps.entrySet().iterator();
|
Iterator<Entry<ImageMap, Integer>> it = maps.entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Entry<ImageMap, Integer> entry = it.next();
|
Entry<ImageMap, Integer> entry = it.next();
|
||||||
ImageMap imageMap = entry.getKey();
|
ImageMap imageMap = entry.getKey();
|
||||||
if (!imageMap.getFilename().equalsIgnoreCase(filename)) continue;
|
if (!imageMap.getFilename().equalsIgnoreCase(filename)) {
|
||||||
Integer id = entry.getValue();
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
MapView map = Bukkit.getMap(id);
|
MapView map = Bukkit.getMap(entry.getValue());
|
||||||
if (map == null) continue;
|
|
||||||
|
if (map == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
map.getRenderers().forEach(map::removeRenderer);
|
map.getRenderers().forEach(map::removeRenderer);
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
saveMaps();
|
saveMaps();
|
||||||
return fileDeleted;
|
return fileDeleted;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user