mirror of
https://github.com/SydMontague/ImageMaps.git
synced 2024-11-22 02:15:20 +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()) {
|
||||
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);
|
||||
boolean fileExisted = outFile.exists();
|
||||
ImageIO.write(image, "PNG", outFile);
|
||||
|
||||
if (fileExisted) {
|
||||
MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.WARNING, "File already exists, overwriting!");
|
||||
getPlugin().reloadImage(filename);
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.NORMAL, "Download complete.");
|
||||
|
@ -374,21 +374,32 @@ public class ImageMaps extends JavaPlugin implements Listener {
|
||||
|
||||
public boolean deleteImage(String filename) {
|
||||
File file = new File(getDataFolder(), IMAGES_DIR + File.separatorChar + filename);
|
||||
|
||||
boolean fileDeleted = false;
|
||||
if (file.exists()) fileDeleted = file.delete();
|
||||
if (file.exists()) {
|
||||
fileDeleted = file.delete();
|
||||
}
|
||||
|
||||
imageCache.remove(filename.toLowerCase());
|
||||
|
||||
Iterator<Entry<ImageMap, Integer>> it = maps.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<ImageMap, Integer> entry = it.next();
|
||||
ImageMap imageMap = entry.getKey();
|
||||
if (!imageMap.getFilename().equalsIgnoreCase(filename)) continue;
|
||||
Integer id = entry.getValue();
|
||||
if (!imageMap.getFilename().equalsIgnoreCase(filename)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
MapView map = Bukkit.getMap(id);
|
||||
if (map == null) continue;
|
||||
MapView map = Bukkit.getMap(entry.getValue());
|
||||
|
||||
if (map == null) {
|
||||
continue;
|
||||
}
|
||||
map.getRenderers().forEach(map::removeRenderer);
|
||||
it.remove();
|
||||
}
|
||||
|
||||
saveMaps();
|
||||
return fileDeleted;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user