mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2024-11-29 05:26:18 +01:00
The plugin configuration now uses the zLib config mecanisms.
* NEW: now using the zLib configuration component to manage the configuration.
This commit is contained in:
parent
578ea39479
commit
987efea203
@ -86,10 +86,11 @@ public final class ImageOnMap extends ZPlugin
|
||||
return;
|
||||
}
|
||||
|
||||
loadComponents(Gui.class, Commands.class, ImageIOExecutor.class, ImageRendererExecutor.class);
|
||||
saveDefaultConfig();
|
||||
|
||||
loadComponents(Gui.class, Commands.class, PluginConfiguration.class, ImageIOExecutor.class, ImageRendererExecutor.class);
|
||||
|
||||
//Init all the things !
|
||||
PluginConfiguration.init(this);
|
||||
MetricsLite.startMetrics();
|
||||
MapManager.init();
|
||||
MapInitEvent.init();
|
||||
|
@ -55,10 +55,10 @@ public class MetricsLite
|
||||
/**
|
||||
* Starts MetricsLite, unless disabled in config
|
||||
*/
|
||||
|
||||
static public void startMetrics()
|
||||
{
|
||||
if(!PluginConfiguration.COLLECT_DATA.getBoolean()) return;
|
||||
if(!PluginConfiguration.COLLECT_DATA.get()) return;
|
||||
|
||||
try
|
||||
{
|
||||
MetricsLite metrics = new MetricsLite(ImageOnMap.getPlugin());
|
||||
|
@ -18,108 +18,16 @@
|
||||
|
||||
package fr.moribus.imageonmap;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import fr.zcraft.zlib.components.configuration.Configuration;
|
||||
import fr.zcraft.zlib.components.configuration.ConfigurationItem;
|
||||
|
||||
public enum PluginConfiguration
|
||||
import static fr.zcraft.zlib.components.configuration.ConfigurationItem.item;
|
||||
|
||||
|
||||
public final class PluginConfiguration extends Configuration
|
||||
{
|
||||
//Configuration field Names, with default values
|
||||
COLLECT_DATA("collect-data", true),
|
||||
MAP_GLOBAL_LIMIT("map-global-limit", 0, "Limit-map-by-server"),
|
||||
MAP_PLAYER_LIMIT("map-player-limit", 0, "Limit-map-by-player");
|
||||
static public ConfigurationItem<Boolean> COLLECT_DATA = item("collect-data", true);
|
||||
|
||||
private final String fieldName;
|
||||
private final Object defaultValue;
|
||||
private final String[] deprecatedNames;
|
||||
|
||||
private PluginConfiguration(String fieldName, Object defaultValue, String ... deprecatedNames)
|
||||
{
|
||||
this.fieldName = fieldName;
|
||||
this.defaultValue = defaultValue;
|
||||
this.deprecatedNames = deprecatedNames;
|
||||
}
|
||||
|
||||
public Object get()
|
||||
{
|
||||
return getConfig().get(fieldName, defaultValue);
|
||||
}
|
||||
|
||||
public Object getDefaultValue()
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public boolean isDefined()
|
||||
{
|
||||
return getConfig().contains(fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return get().toString();
|
||||
}
|
||||
|
||||
public String getString()
|
||||
{
|
||||
return getConfig().getString(fieldName, (String)defaultValue);
|
||||
}
|
||||
|
||||
public int getInteger()
|
||||
{
|
||||
return getConfig().getInt(fieldName, (Integer)defaultValue);
|
||||
}
|
||||
|
||||
public boolean getBoolean()
|
||||
{
|
||||
return getConfig().getBoolean(fieldName, (Boolean)defaultValue);
|
||||
}
|
||||
|
||||
private boolean init()
|
||||
{
|
||||
boolean affected = false;
|
||||
|
||||
if(!isDefined())
|
||||
{
|
||||
getConfig().set(fieldName, defaultValue);
|
||||
affected = true;
|
||||
}
|
||||
|
||||
for(String deprecatedName : deprecatedNames)
|
||||
{
|
||||
if(getConfig().contains(deprecatedName))
|
||||
{
|
||||
getConfig().set(fieldName, getConfig().get(deprecatedName));
|
||||
getConfig().set(deprecatedName, null);
|
||||
affected = true;
|
||||
}
|
||||
}
|
||||
return affected;
|
||||
}
|
||||
|
||||
/* ===== Static API ===== */
|
||||
|
||||
static private Plugin plugin;
|
||||
static public FileConfiguration getConfig()
|
||||
{
|
||||
return plugin.getConfig();
|
||||
}
|
||||
|
||||
static public void init(Plugin plugin)
|
||||
{
|
||||
PluginConfiguration.plugin = plugin;
|
||||
loadDefaultValues();
|
||||
}
|
||||
|
||||
static private void loadDefaultValues()
|
||||
{
|
||||
boolean affected = false;
|
||||
|
||||
for(PluginConfiguration configField : PluginConfiguration.values())
|
||||
{
|
||||
if(configField.init()) affected = true;
|
||||
}
|
||||
|
||||
if(affected) plugin.saveConfig();
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
@ -121,8 +120,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.getInteger();
|
||||
int mapPersonalLimit = PluginConfiguration.MAP_PLAYER_LIMIT.getInteger();
|
||||
int mapGlobalLimit = PluginConfiguration.MAP_GLOBAL_LIMIT.get();
|
||||
int mapPersonalLimit = PluginConfiguration.MAP_PLAYER_LIMIT.get();
|
||||
|
||||
int mapPartGloballyLeft = mapGlobalLimit - MapManager.getMapCount();
|
||||
int mapPartPersonallyLeft = mapPersonalLimit - mapPartCount;
|
||||
|
@ -24,16 +24,17 @@ 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 java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
abstract public class MapManager
|
||||
{
|
||||
static private final long SAVE_DELAY = 200;
|
||||
@ -280,12 +281,11 @@ abstract public class MapManager
|
||||
|
||||
static public void checkMapLimit(int newMapsCount, UUID userUUID) throws MapManagerException
|
||||
{
|
||||
int limit = PluginConfiguration.MAP_GLOBAL_LIMIT.getInteger();
|
||||
if(limit > 0)
|
||||
{
|
||||
if(getMapCount() + newMapsCount > limit)
|
||||
int limit = PluginConfiguration.MAP_GLOBAL_LIMIT.get();
|
||||
|
||||
if (limit > 0 && getMapCount() + newMapsCount > limit)
|
||||
throw new MapManagerException(Reason.MAXIMUM_SERVER_MAPS_EXCEEDED);
|
||||
}
|
||||
|
||||
getPlayerMapStore(userUUID).checkMapLimit(newMapsCount);
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ import fr.moribus.imageonmap.ImageOnMap;
|
||||
import fr.moribus.imageonmap.PluginConfiguration;
|
||||
import fr.moribus.imageonmap.map.MapManagerException.Reason;
|
||||
import fr.zcraft.zlib.tools.PluginLogger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -36,7 +37,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class PlayerMapStore implements ConfigurationSerializable
|
||||
{
|
||||
@ -154,7 +154,7 @@ public class PlayerMapStore implements ConfigurationSerializable
|
||||
|
||||
public void checkMapLimit(int newMapsCount) throws MapManagerException
|
||||
{
|
||||
int limit = PluginConfiguration.MAP_PLAYER_LIMIT.getInteger();
|
||||
int limit = PluginConfiguration.MAP_PLAYER_LIMIT.get();
|
||||
if(limit <= 0) return;
|
||||
|
||||
if(getMapCount() + newMapsCount > limit)
|
||||
|
@ -0,0 +1,13 @@
|
||||
### ImageOnMap configuration file
|
||||
|
||||
|
||||
# Allows collection of anonymous statistics on plugin environment and usage
|
||||
# The statistics are publicly visible here: http://mcstats.org/plugin/ImageOnMap
|
||||
collect-data: true
|
||||
|
||||
|
||||
# Images rendered on maps consume Minecraft maps ID, and there are only 32 767 of them.
|
||||
# You can limit the maximum number of maps a player, or the whole server, can use with ImageOnMap.
|
||||
# 0 means unlimited.
|
||||
map-global-limit: 0
|
||||
map-player-limit: 0
|
Loading…
Reference in New Issue
Block a user