Add save-full-image and limit-x/y

This commit is contained in:
kirbykirby56 2018-03-24 21:44:06 -04:00 committed by Vlammar
parent 207514dcaf
commit 69fcb0c241
3 changed files with 32 additions and 3 deletions

View File

@ -31,7 +31,10 @@ public final class PluginConfiguration extends Configuration
static public ConfigurationItem<Locale> LANG = item("lang", Locale.class);
static public ConfigurationItem<Boolean> COLLECT_DATA = item("collect-data", true);
static public ConfigurationItem<Boolean> SAVE_FULL_IMAGE = item("save-full-image", true);
static public ConfigurationItem<Integer> MAP_GLOBAL_LIMIT = item("map-global-limit", 0, "Limit-map-by-server");
static public ConfigurationItem<Integer> MAP_PLAYER_LIMIT = item("map-player-limit", 0, "Limit-map-by-player");
static public ConfigurationItem<Integer> LIMIT_SIZE_X = item("limit-map-size-x", 0);
static public ConfigurationItem<Integer> LIMIT_SIZE_Y = item("limit-map-size-y", 0);
}

View File

@ -18,6 +18,8 @@
package fr.moribus.imageonmap.image;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.PluginConfiguration;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.zcraft.zlib.components.i18n.I;
@ -27,6 +29,7 @@ import fr.zcraft.zlib.components.worker.WorkerCallback;
import fr.zcraft.zlib.components.worker.WorkerRunnable;
import javax.imageio.ImageIO;
import org.bukkit.Bukkit;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
@ -63,13 +66,25 @@ public class ImageRendererExecutor extends Worker
final BufferedImage image = ImageIO.read(stream);
if (image == null) throw new IOException(I.t("The given URL is not a valid image"));
//Limits are in place and the player does NOT have rights to avoid them.
if((PluginConfiguration.LIMIT_SIZE_X.get() > 0 || PluginConfiguration.LIMIT_SIZE_Y.get() > 0) && !Bukkit.getPlayer(playerUUID).hasPermission("imageonmap.bypasssize")) {
if(PluginConfiguration.LIMIT_SIZE_X.get() > 0) {
if(image.getWidth() > PluginConfiguration.LIMIT_SIZE_X.get()) throw new IOException(I.t("The image is too wide!"));
}
if(PluginConfiguration.LIMIT_SIZE_Y.get() > 0) {
if(image.getHeight() > PluginConfiguration.LIMIT_SIZE_Y.get()) throw new IOException(I.t("The image is too tall!"));
}
}
if(scaling != ImageUtils.ScalingType.NONE && height <= 1 && width <= 1) {
return renderSingle(scaling.resize(image, ImageMap.WIDTH, ImageMap.HEIGHT), playerUUID);
}
final BufferedImage resizedImage = scaling.resize(image, ImageMap.WIDTH * width, ImageMap.HEIGHT * height);
return renderPoster(resizedImage, playerUUID);
//return RenderPoster(image, playerUUID);
}
}, callback);
}
@ -123,6 +138,11 @@ public class ImageRendererExecutor extends Worker
ImageIOExecutor.saveImage(mapsIDs, poster);
if(PluginConfiguration.SAVE_FULL_IMAGE.get()) {
ImageIOExecutor.saveImage(ImageMap.getFullImageFile(mapsIDs[0], mapsIDs[mapsIDs.length - 1]), image);
}
submitToMainThread(new Callable<Void>()
{
@Override
@ -136,4 +156,4 @@ public class ImageRendererExecutor extends Worker
return MapManager.createMap(poster, playerUUID, mapsIDs);
}
}
}

View File

@ -18,6 +18,7 @@
package fr.moribus.imageonmap.map;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.ui.MapItemManager;
import fr.zcraft.zlib.components.i18n.I;
import org.bukkit.Material;
@ -26,6 +27,7 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@ -47,7 +49,6 @@ public abstract class ImageMap implements ConfigurationSerializable
private final UUID userUUID;
private final Type mapType;
private String name;
protected ImageMap(UUID userUUID, Type mapType)
{
this(userUUID, mapType, null, null);
@ -84,6 +85,11 @@ public abstract class ImageMap implements ConfigurationSerializable
return MapItemManager.give(player, this);
}
public static File getFullImageFile(short mapIDstart, short mapIDend)
{
return new File(ImageOnMap.getPlugin().getImagesDirectory(), "_"+mapIDstart+"-"+mapIDend+".png");
}
/* ====== Serialization methods ====== */
static public ImageMap fromConfig(Map<String, Object> map, UUID userUUID) throws InvalidConfigurationException