mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2025-03-11 05:59:30 +01:00
Fixes config.yml not being read and adds save-full-image option
Closes Issue #36
This commit is contained in:
parent
2bd7562539
commit
4883120a4f
@ -35,12 +35,12 @@ import fr.zcraft.zlib.tools.PluginLogger;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public final class ImageOnMap extends ZPlugin
|
||||
{
|
||||
static private final String IMAGES_DIRECTORY_NAME = "images";
|
||||
static private final String MAPS_DIRECTORY_NAME = "maps";
|
||||
static private ImageOnMap plugin;
|
||||
|
||||
private File imagesDirectory;
|
||||
private final File mapsDirectory;
|
||||
|
||||
@ -63,6 +63,11 @@ public final class ImageOnMap extends ZPlugin
|
||||
return new File(imagesDirectory, "map"+mapID+".png");
|
||||
}
|
||||
|
||||
public File getFullImageFile(short mapIDstart, short mapIDend)
|
||||
{
|
||||
return new File(imagesDirectory, "_"+mapIDstart+"-"+mapIDend+".png");
|
||||
}
|
||||
|
||||
@SuppressWarnings ("unchecked")
|
||||
@Override
|
||||
public void onEnable()
|
||||
@ -79,14 +84,17 @@ public final class ImageOnMap extends ZPlugin
|
||||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
saveDefaultConfig();
|
||||
|
||||
loadComponents(I18n.class, Gui.class, Commands.class, PluginConfiguration.class, ImageIOExecutor.class, ImageRendererExecutor.class);
|
||||
|
||||
PluginConfiguration.initialize();
|
||||
|
||||
//Init all the things !
|
||||
MetricsLite.startMetrics();
|
||||
I18n.setPrimaryLocale(PluginConfiguration.LANG.get());
|
||||
I18n.setPrimaryLocale(PluginConfiguration.LANG);
|
||||
|
||||
MapManager.init();
|
||||
MapInitEvent.init();
|
||||
|
@ -57,7 +57,7 @@ public class MetricsLite
|
||||
*/
|
||||
static public void startMetrics()
|
||||
{
|
||||
if(!PluginConfiguration.COLLECT_DATA.get()) return;
|
||||
if(!PluginConfiguration.COLLECT_DATA) return;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -21,6 +21,7 @@ package fr.moribus.imageonmap;
|
||||
import fr.zcraft.zlib.components.configuration.Configuration;
|
||||
import fr.zcraft.zlib.components.configuration.ConfigurationItem;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Locale;
|
||||
|
||||
import static fr.zcraft.zlib.components.configuration.ConfigurationItem.item;
|
||||
@ -28,10 +29,93 @@ import static fr.zcraft.zlib.components.configuration.ConfigurationItem.item;
|
||||
|
||||
public final class PluginConfiguration extends Configuration
|
||||
{
|
||||
static public ConfigurationItem<Locale> LANG = item("lang", Locale.class);
|
||||
static public Locale LANG = Locale.ENGLISH;
|
||||
|
||||
static public ConfigurationItem<Boolean> COLLECT_DATA = item("collect-data", true);
|
||||
static public Boolean COLLECT_DATA = false;
|
||||
|
||||
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 Integer MAP_GLOBAL_LIMIT = 0;
|
||||
static public Integer MAP_PLAYER_LIMIT = 0;
|
||||
|
||||
static public Integer LIMIT_SIZE_X = 0;
|
||||
static public Integer LIMIT_SIZE_Y= 0;
|
||||
static public Boolean SAVE_FULL_IMAGE = false;
|
||||
FileInputStream in = null;
|
||||
|
||||
public static void initialize() {
|
||||
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(new File(ImageOnMap.getPlugin().getDataFolder(), "config.yml"));
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
||||
String line = null;
|
||||
line = br.readLine();//2
|
||||
line = br.readLine();//3
|
||||
line = br.readLine();//4
|
||||
line = br.readLine();//5
|
||||
line = br.readLine(); //We're now at line 6.
|
||||
line = br.readLine(); //lang is in Line.
|
||||
|
||||
if(line.contains("en_US")) LANG = Locale.ENGLISH;
|
||||
if(line.contains("fr_FR")) LANG = Locale.FRENCH;
|
||||
else LANG = Locale.ENGLISH;
|
||||
|
||||
line = br.readLine();//8
|
||||
line = br.readLine();//9
|
||||
line = br.readLine();//10
|
||||
line = br.readLine();//11
|
||||
line = br.readLine();//Collect-data in line.
|
||||
|
||||
if(line.contains("true")) COLLECT_DATA = true;
|
||||
|
||||
line = br.readLine();//13
|
||||
line = br.readLine();//14
|
||||
line = br.readLine();//15
|
||||
line = br.readLine();//16
|
||||
line = br.readLine();//17
|
||||
line = br.readLine();//map-global-limit
|
||||
|
||||
line = line.substring(17, line.length() - 1);
|
||||
try{MAP_GLOBAL_LIMIT = Integer.parseInt(line);}
|
||||
catch(NumberFormatException e) {MAP_GLOBAL_LIMIT = 0;}
|
||||
|
||||
//It's even the same line length! Nothing new needs to be done.
|
||||
line = br.readLine();//map-player-limit
|
||||
//map-player-limit: 172
|
||||
//012345678901234567890
|
||||
line = line.substring(17, line.length() - 1);
|
||||
try{MAP_PLAYER_LIMIT = Integer.parseInt(line);}
|
||||
catch(NumberFormatException e) {MAP_PLAYER_LIMIT = 0;}
|
||||
|
||||
line = br.readLine();//20
|
||||
line = br.readLine();//21
|
||||
line = br.readLine();//22
|
||||
|
||||
line = br.readLine();//limit-map-size-x
|
||||
//Lucky break! same code. Again!
|
||||
line = line.substring(17, line.length() - 1);
|
||||
try{LIMIT_SIZE_X = Integer.parseInt(line);}
|
||||
catch(NumberFormatException e) {LIMIT_SIZE_X = 0;}
|
||||
|
||||
line = br.readLine();//limit-map-size-x
|
||||
//Lucky break! same code. Again!
|
||||
line = line.substring(17, line.length() - 1);
|
||||
try{LIMIT_SIZE_Y = Integer.parseInt(line);}
|
||||
catch(NumberFormatException e) {LIMIT_SIZE_Y = 0;}
|
||||
|
||||
line = br.readLine();//25
|
||||
line = br.readLine();//26
|
||||
line = br.readLine();//27
|
||||
|
||||
line = br.readLine();//line holds save-full-image.
|
||||
if(line.contains("true")) {
|
||||
SAVE_FULL_IMAGE = true;
|
||||
}
|
||||
br.close();
|
||||
fis.close();
|
||||
}
|
||||
catch(IOException e){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -125,8 +125,8 @@ public class MapListGui extends ExplorerGui<ImageMap>
|
||||
int imagesCount = MapManager.getMapList(getPlayer().getUniqueId()).size();
|
||||
int mapPartCount = MapManager.getMapPartCount(getPlayer().getUniqueId());
|
||||
|
||||
int mapGlobalLimit = PluginConfiguration.MAP_GLOBAL_LIMIT.get();
|
||||
int mapPersonalLimit = PluginConfiguration.MAP_PLAYER_LIMIT.get();
|
||||
int mapGlobalLimit = PluginConfiguration.MAP_GLOBAL_LIMIT;
|
||||
int mapPersonalLimit = PluginConfiguration.MAP_PLAYER_LIMIT;
|
||||
|
||||
int mapPartGloballyLeft = mapGlobalLimit - MapManager.getMapCount();
|
||||
int mapPartPersonallyLeft = mapPersonalLimit - mapPartCount;
|
||||
|
@ -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,8 +29,13 @@ import fr.zcraft.zlib.components.worker.WorkerCallback;
|
||||
import fr.zcraft.zlib.components.worker.WorkerRunnable;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.security.auth.login.Configuration;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
@ -64,7 +71,18 @@ 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 > 0 || PluginConfiguration.LIMIT_SIZE_Y > 0) && !Bukkit.getPlayer(playerUUID).hasPermission("imageonmap.bypasssize")) {
|
||||
if(PluginConfiguration.LIMIT_SIZE_X > 0) {
|
||||
if(image.getWidth() > PluginConfiguration.LIMIT_SIZE_X) throw new IOException(I.t("The image is too wide!"));
|
||||
}
|
||||
if(PluginConfiguration.LIMIT_SIZE_Y > 0) {
|
||||
if(image.getHeight() > PluginConfiguration.LIMIT_SIZE_Y) throw new IOException(I.t("The image is too tall!"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (scaling) return RenderSingle(image, playerUUID);
|
||||
else return RenderPoster(image, playerUUID);
|
||||
}
|
||||
@ -123,6 +141,11 @@ public class ImageRendererExecutor extends Worker
|
||||
|
||||
ImageIOExecutor.saveImage(mapsIDs, poster);
|
||||
|
||||
if(PluginConfiguration.SAVE_FULL_IMAGE) {
|
||||
ImageIOExecutor.saveImage(ImageOnMap.getPlugin().getFullImageFile(mapsIDs[0], mapsIDs[mapsIDs.length - 1]), image);
|
||||
|
||||
}
|
||||
|
||||
submitToMainThread(new Callable<Void>()
|
||||
{
|
||||
@Override
|
||||
|
@ -18,12 +18,13 @@
|
||||
|
||||
package fr.moribus.imageonmap.map;
|
||||
|
||||
import fr.moribus.imageonmap.ImageOnMap;
|
||||
import fr.moribus.imageonmap.PluginConfiguration;
|
||||
import fr.moribus.imageonmap.image.ImageIOExecutor;
|
||||
import fr.moribus.imageonmap.image.PosterImage;
|
||||
import fr.moribus.imageonmap.map.MapManagerException.Reason;
|
||||
import fr.zcraft.zlib.tools.PluginLogger;
|
||||
import fr.moribus.imageonmap.ImageOnMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -281,7 +282,7 @@ abstract public class MapManager
|
||||
|
||||
static public void checkMapLimit(int newMapsCount, UUID userUUID) throws MapManagerException
|
||||
{
|
||||
int limit = PluginConfiguration.MAP_GLOBAL_LIMIT.get();
|
||||
int limit = PluginConfiguration.MAP_GLOBAL_LIMIT;
|
||||
|
||||
if (limit > 0 && getMapCount() + newMapsCount > limit)
|
||||
throw new MapManagerException(Reason.MAXIMUM_SERVER_MAPS_EXCEEDED);
|
||||
|
@ -18,10 +18,11 @@
|
||||
|
||||
package fr.moribus.imageonmap.map;
|
||||
|
||||
import fr.moribus.imageonmap.ImageOnMap;
|
||||
import fr.moribus.imageonmap.PluginConfiguration;
|
||||
import fr.moribus.imageonmap.map.MapManagerException.Reason;
|
||||
import fr.zcraft.zlib.tools.PluginLogger;
|
||||
import fr.moribus.imageonmap.ImageOnMap;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
@ -154,7 +155,7 @@ public class PlayerMapStore implements ConfigurationSerializable
|
||||
|
||||
public void checkMapLimit(int newMapsCount) throws MapManagerException
|
||||
{
|
||||
int limit = PluginConfiguration.MAP_PLAYER_LIMIT.get();
|
||||
int limit = PluginConfiguration.MAP_PLAYER_LIMIT;
|
||||
if(limit <= 0) return;
|
||||
|
||||
if(getMapCount() + newMapsCount > limit)
|
||||
|
@ -8,7 +8,7 @@ lang:
|
||||
|
||||
# Allows collection of anonymous statistics on plugin environment and usage
|
||||
# The statistics are publicly visible here: http://mcstats.org/plugin/ImageOnMap
|
||||
collect-data: true
|
||||
collect-data: false
|
||||
|
||||
|
||||
# Images rendered on maps consume Minecraft maps ID, and there are only 32 767 of them.
|
||||
@ -16,3 +16,12 @@ collect-data: true
|
||||
# 0 means unlimited.
|
||||
map-global-limit: 0
|
||||
map-player-limit: 0
|
||||
|
||||
|
||||
#Maximum size in pixels for an image to be. 0 is unlimited.
|
||||
limit-map-size-x: 0
|
||||
limit-map-size-y: 0
|
||||
|
||||
|
||||
#Should the full image be saved when a map is rendered?
|
||||
save-full-image: false;
|
@ -3,6 +3,7 @@ new: Creates a new ImageOnMap
|
||||
delete: Deletes a map.
|
||||
delete-noconfirm: Deletes a map. Deletion is permanent and made without confirmation
|
||||
get: Gives you a map.
|
||||
getother: Opens another's MapTool GUI
|
||||
getremaining: Gives you the remaining maps that could not fit in your inventory
|
||||
list: Lists all the map you currently have.
|
||||
explore: Opens a GUI to see and manage your maps.
|
||||
|
8
src/main/resources/help/maptool/getother.txt
Normal file
8
src/main/resources/help/maptool/getother.txt
Normal file
@ -0,0 +1,8 @@
|
||||
Opens a GUI to list and manage others' maps.
|
||||
|
||||
From there, you can:
|
||||
- list all the maps you rendered on this server;
|
||||
- get copies of maps you rendered;
|
||||
- get parts of posters in case of need;
|
||||
- delete or rename your maps (organization!);
|
||||
- see their statistics (maps rendered, left...).
|
1
src/main/resources/help/maptool/listother.txt
Normal file
1
src/main/resources/help/maptool/listother.txt
Normal file
@ -0,0 +1 @@
|
||||
Lists another player's maps.
|
Loading…
Reference in New Issue
Block a user