mirror of
https://github.com/EpicEricEE/ShopChest.git
synced 2024-09-28 23:27:41 +02:00
Add config properties to API
This commit is contained in:
parent
f7d7691bc1
commit
bd3dd17621
@ -0,0 +1,75 @@
|
||||
package de.epiceric.shopchest.api.config;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import de.epiceric.shopchest.api.database.DatabaseType;
|
||||
|
||||
/**
|
||||
* Class to access configuration properties
|
||||
*
|
||||
* @since 1.13
|
||||
*/
|
||||
public class Config {
|
||||
private Config() {}
|
||||
|
||||
public static final Property<String> CORE_MAIN_COMMAND_NAME = new Property<>(String.class, "core", "main_command_name", "shop");
|
||||
public static final Property<String> CORE_LANGUAGE_FILE = new Property<>(String.class, "core", "language_file", "en_US");
|
||||
public static final Property<Boolean> CORE_ENABLE_UPDATE_CHECKER = new Property<>(Boolean.class, "core", "enable_update_checker", true);
|
||||
public static final Property<Boolean> CORE_REMOVE_SHOP_ON_ERROR = new Property<>(Boolean.class, "core", "remove_shop_on_error", true);
|
||||
public static final Property<Boolean> CORE_INVERT_MOUSE_BUTTONS = new Property<>(Boolean.class, "core", "invert_mouse_buttons", false);
|
||||
public static final Property<Integer> CORE_DEFAULT_SHOP_LIMIT = new Property<>(Integer.class, "core", "default_shop_limit", 5);
|
||||
public static final Property<Material> CORE_SHOP_INFO_ITEM = new Property<>(Material.class, "core", "shop_info_item", Material.STICK);
|
||||
|
||||
public static final Property<Double> SHOP_CREATION_PRICE = new Property<>(Double.class, "shop_creation", "price", 5d);
|
||||
public static final Property<Boolean> SHOP_CREATION_ALLOW_DECIMAL_PRICES = new Property<>(Boolean.class, "shop_creation", "allow_decimal_prices", true);
|
||||
public static final Property<Boolean> SHOP_CREATION_ALLOW_BROKEN_ITEMS = new Property<>(Boolean.class, "shop_creation", "allow_broken_items", false);
|
||||
public static final Property<MaterialList> SHOP_CREATION_BLACKLIST = new Property<>(MaterialList.class, "shop_creation", "blacklist", new MaterialList());
|
||||
|
||||
public static final Property<MaterialDoubleMap> SHOP_CREATION_MINIMUM_PRICES = new Property<>(MaterialDoubleMap.class, "shop_creation", "minimum_prices", new MaterialDoubleMap());
|
||||
public static final Property<MaterialDoubleMap> SHOP_CREATION_MAXIMUM_PRICES = new Property<>(MaterialDoubleMap.class, "shop_creation", "maximum_prices", new MaterialDoubleMap());
|
||||
|
||||
public static final Property<Boolean> FEATURES_CONFIRM_SHOPPING = new Property<>(Boolean.class, "feature", "confirm_shopping", false);
|
||||
public static final Property<Boolean> FEATURES_CREATIVE_ITEM_SELECTION = new Property<>(Boolean.class, "feature", "creative_item_selection", true);
|
||||
public static final Property<Boolean> FEATURES_REFUND_SHOP_CREATION = new Property<>(Boolean.class, "feature", "refund_shop_creation", false);
|
||||
public static final Property<Boolean> FEATURES_VENDOR_MESSAGES = new Property<>(Boolean.class, "feature", "vendor_messages", true);
|
||||
public static final Property<Boolean> FEATURES_VENDOR_MONEY_PROTECTION = new Property<>(Boolean.class, "feature", "vendor_money_protection", true);
|
||||
public static final Property<Boolean> FEATURES_AUTO_ADJUST_ITEM_AMOUNT = new Property<>(Boolean.class, "feature", "auto_adjust_item_amount", false);
|
||||
|
||||
public static final Property<Double> HOLOGRAM_MAXIMUM_DISTANCE = new Property<>(Double.class, "hologram", "maximum_distance", 2.5);
|
||||
public static final Property<Double> HOLOGRAM_ADDITIONAL_LIFT = new Property<>(Double.class, "hologram", "additional_lift", 0d);
|
||||
|
||||
public static final Property<Boolean> ECONOMY_LOG_ENABLE = new Property<>(Boolean.class, "economy_log", "enable", true);
|
||||
public static final Property<Boolean> ECONOMY_LOG_CLEANUP = new Property<>(Boolean.class, "economy_log", "cleanup", true);
|
||||
public static final Property<Integer> ECONOMY_LOG_CLEANUP_DAYS = new Property<>(Integer.class, "economy_log", "cleanup_days", 30);
|
||||
|
||||
public static final Property<Boolean> PLUGINS_ENABLE_AREASHOP = new Property<>(Boolean.class, "plugins.enable", "areashop", true);
|
||||
public static final Property<Boolean> PLUGINS_ENABLE_ASKYBLOCK = new Property<>(Boolean.class, "plugins.enable", "askyblock", true);
|
||||
public static final Property<Boolean> PLUGINS_ENABLE_AUTHME = new Property<>(Boolean.class, "plugins.enable", "authme", true);
|
||||
public static final Property<Boolean> PLUGINS_ENABLE_GRIEFPREVENTION = new Property<>(Boolean.class, "plugins.enable", "griefprevention", true);
|
||||
public static final Property<Boolean> PLUGINS_ENABLE_ISLANDWORLD = new Property<>(Boolean.class, "plugins.enable", "islandworld", true);
|
||||
public static final Property<Boolean> PLUGINS_ENABLE_PLOTSQUARED = new Property<>(Boolean.class, "plugins.enable", "plotsquared", true);
|
||||
public static final Property<Boolean> PLUGINS_ENABLE_USKYBLOCK = new Property<>(Boolean.class, "plugins.enable", "uskyblock", true);
|
||||
public static final Property<Boolean> PLUGINS_ENABLE_WORLDGUARD = new Property<>(Boolean.class, "plugins.enable", "worldguard", true);
|
||||
|
||||
public static final Property<Boolean> PLUGINS_WORLDGUARD_ALLOW_CREATE_SHOP = new Property<>(Boolean.class, "plugins.worldguard", "default_allow_create_shop", false);
|
||||
public static final Property<Boolean> PLUGINS_WORLDGUARD_ALLOW_USE_SHOP = new Property<>(Boolean.class, "plugins.worldguard", "default_allow_use_shop", true);
|
||||
public static final Property<Boolean> PLUGINS_WORLDGUARD_ALLOW_USE_ADMIN_SHOP = new Property<>(Boolean.class, "plugins.worldguard", "default_allow_use_admin_shop", true);
|
||||
|
||||
public static final Property<Boolean> PLUGINS_AREASHOP_REMOVE_ON_DELETE = new Property<>(Boolean.class, "plugins.areashop", "remove_shops_on_delete", true);
|
||||
public static final Property<Boolean> PLUGINS_AREASHOP_REMOVE_ON_UNRENT = new Property<>(Boolean.class, "plugins.areashop", "remove_shops_on_unrent", true);
|
||||
public static final Property<Boolean> PLUGINS_AREASHOP_REMOVE_ON_RESELL = new Property<>(Boolean.class, "plugins.areashop", "remove_shops_on_resell", true);
|
||||
public static final Property<Boolean> PLUGINS_AREASHOP_REMOVE_ON_SELL = new Property<>(Boolean.class, "plugins.areashop", "remove_shops_on_sell", true);
|
||||
|
||||
public static final Property<StringList> PLUGINS_TOWNY_PLOTS_FOR_RESIDENTS = new Property<>(StringList.class, "plugins.towny", "shop_plots_for_residents", new StringList("commercial"));
|
||||
public static final Property<StringList> PLUGINS_TOWNY_PLOTS_FOR_MAYOR = new Property<>(StringList.class, "plugins.towny", "shop_plots_for_mayor", new StringList("commercial"));
|
||||
public static final Property<StringList> PLUGINS_TOWNY_PLOTS_FOR_KING = new Property<>(StringList.class, "plugins.towny", "shop_plots_for_king", new StringList("commercial"));
|
||||
|
||||
public static final Property<DatabaseType> DATABASE_TYPE = new Property<>(DatabaseType.class, "database", "type", DatabaseType.SQLITE);
|
||||
public static final Property<String> DATABASE_TABLE_PREFIX = new Property<>(String.class, "database", "table_prefix", "shopchest_");
|
||||
public static final Property<String> DATABASE_MYSQL_HOSTNAME = new Property<>(String.class, "database.mysql", "hostname", "");
|
||||
public static final Property<Integer> DATABASE_MYSQL_PORT = new Property<>(Integer.class, "database.mysql", "port", 3306);
|
||||
public static final Property<String> DATABASE_MYSQL_DATABASE = new Property<>(String.class, "database.mysql", "database", "");
|
||||
public static final Property<String> DATABASE_MYSQL_USERNAME = new Property<>(String.class, "database.mysql", "username", "");
|
||||
public static final Property<String> DATABASE_MYSQL_PASSWORD = new Property<>(String.class, "database.mysql", "password", "");
|
||||
public static final Property<Integer> DATABASE_MYSQL_PING_INTERVAL = new Property<>(Integer.class, "database.mysql", "ping_interval", 3600);
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package de.epiceric.shopchest.api.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* A wrapper for {@code Map<Material, Double>}, optimised for config
|
||||
* serialization
|
||||
*
|
||||
* @since 1.13
|
||||
*/
|
||||
public class MaterialDoubleMap {
|
||||
private Map<Material, Double> map;
|
||||
|
||||
/**
|
||||
* Creates a map with the given map's entries
|
||||
*
|
||||
* @param map the map to wrap
|
||||
* @since 1.13
|
||||
*/
|
||||
public MaterialDoubleMap(Map<Material, Double> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty map
|
||||
*
|
||||
* @since 1.13
|
||||
*/
|
||||
public MaterialDoubleMap() {
|
||||
this(new EnumMap<>(Material.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a comma seperated list of {@code <Material, Double>} map entries
|
||||
* <p>
|
||||
* Format: {@code a=b,c=d,e=f}
|
||||
* <p>
|
||||
* The materials are not case sensitive.
|
||||
*
|
||||
* @param str the comma seperated list of map entries
|
||||
* @return the parsed map
|
||||
* @since 1.13
|
||||
*/
|
||||
public static MaterialDoubleMap valueOf(String str) {
|
||||
if (str.isEmpty()) {
|
||||
return new MaterialDoubleMap(Collections.emptyMap());
|
||||
}
|
||||
|
||||
Map<Material, Double> ret = new EnumMap<>(Material.class);
|
||||
|
||||
if (str.contains(",")) {
|
||||
Arrays.stream(str.split("\\,")).forEach(entry -> {
|
||||
String[] spl = entry.split("\\=");
|
||||
Material key = Material.valueOf(spl[0].toUpperCase(Locale.US));
|
||||
double value = Double.parseDouble(spl[1]);
|
||||
ret.put(key, value);
|
||||
});
|
||||
} else {
|
||||
String[] spl = str.split("\\=");
|
||||
Material key = Material.valueOf(spl[0].toUpperCase(Locale.US));
|
||||
double value = Double.parseDouble(spl[1]);
|
||||
ret.put(key, value);
|
||||
}
|
||||
|
||||
return new MaterialDoubleMap(ret);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return map.entrySet().stream().map(entry -> {
|
||||
String key = entry.getKey().name().toLowerCase(Locale.US);
|
||||
double val = entry.getValue();
|
||||
return key + "=" + ((val == (int) val) ? String.valueOf((int) val) : String.valueOf(val));
|
||||
}).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of the map
|
||||
*
|
||||
* @return the map
|
||||
* @since 1.13
|
||||
*/
|
||||
public Map<Material, Double> getMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package de.epiceric.shopchest.api.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* A wrapped for {@code List<Material>}, optimised for config serialization
|
||||
*
|
||||
* @since 1.13
|
||||
*/
|
||||
public class MaterialList {
|
||||
private List<Material> list;
|
||||
|
||||
/**
|
||||
* Creates a list with the given list's entries
|
||||
*
|
||||
* @param list the list to wrap
|
||||
* @since 1.13
|
||||
*/
|
||||
public MaterialList(List<Material> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list with the given materials
|
||||
*
|
||||
* @param materials the materials
|
||||
* @since 1.13
|
||||
*/
|
||||
public MaterialList(Material... materials) {
|
||||
this(Arrays.asList(materials));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a comma seperated list of materials
|
||||
* <p>
|
||||
* The materials are not case sensitive.
|
||||
*
|
||||
* @param str the comma seperated list
|
||||
* @return the parsed list
|
||||
* @since 1.13
|
||||
*/
|
||||
public static MaterialList valueOf(String str) {
|
||||
if (str.isEmpty()) {
|
||||
return new MaterialList();
|
||||
}
|
||||
|
||||
if (str.contains(",")) {
|
||||
return new MaterialList(Arrays.stream(str.split("\\,"))
|
||||
.map(entry -> Material.valueOf(entry.toUpperCase(Locale.US))).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return new MaterialList(Material.valueOf(str.toUpperCase(Locale.US)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return list.stream().map(mat -> mat.name().toLowerCase(Locale.US)).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of the list
|
||||
*
|
||||
* @return the list
|
||||
* @since 1.13
|
||||
*/
|
||||
public List<Material> getList() {
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package de.epiceric.shopchest.api.config;
|
||||
|
||||
/**
|
||||
* Represents a configurable property
|
||||
*
|
||||
* @since 1.13
|
||||
*/
|
||||
public class Property<T> {
|
||||
private final Class<T> type;
|
||||
private final String section;
|
||||
private final String key;
|
||||
private T value;
|
||||
|
||||
/* package-private */ Property(Class<T> type, String section, String key, T defaultValue) {
|
||||
this.type = type;
|
||||
this.section = section;
|
||||
this.key = key;
|
||||
this.value = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the section of this property
|
||||
*
|
||||
* @return the section
|
||||
* @since 1.13
|
||||
*/
|
||||
public String getSection() {
|
||||
return section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key of this property
|
||||
*
|
||||
* @return the key
|
||||
* @since 1.13
|
||||
*/
|
||||
public String getKey() {
|
||||
return section + "." + key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class of this property's type
|
||||
*
|
||||
* @return the type
|
||||
* @since 1.13
|
||||
*/
|
||||
public Class<T> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current value of this property
|
||||
*
|
||||
* @return the value
|
||||
* @since 1.13
|
||||
*/
|
||||
public T get() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this property
|
||||
* <p>
|
||||
* The value is not stored until the config is saved by the plugin.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws IllegalArgumentException if {@code value} is null
|
||||
* @since 1.13
|
||||
*/
|
||||
public void set(T value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException("Property value cannot be null");
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package de.epiceric.shopchest.api.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A wrapped for {@code List<String>}, optimised for config serialization
|
||||
*
|
||||
* @since 1.13
|
||||
*/
|
||||
public class StringList {
|
||||
private List<String> list;
|
||||
|
||||
/**
|
||||
* Creates a list with the given list's entries
|
||||
*
|
||||
* @param list the list to wrap
|
||||
* @since 1.13
|
||||
*/
|
||||
public StringList(List<String> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list with the given strings
|
||||
*
|
||||
* @param strings the strings
|
||||
* @since 1.13
|
||||
*/
|
||||
public StringList(String... strings) {
|
||||
this(Arrays.asList(strings));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a comma seperated list of strings
|
||||
*
|
||||
* @param str the comma seperated list
|
||||
* @return the parsed list
|
||||
* @since 1.13
|
||||
*/
|
||||
public static StringList valueOf(String str) {
|
||||
if (str.isEmpty()) {
|
||||
return new StringList();
|
||||
}
|
||||
|
||||
if (str.contains(",")) {
|
||||
return new StringList((str.split("\\,")));
|
||||
}
|
||||
|
||||
return new StringList(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.join(",", list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of the list
|
||||
*
|
||||
* @return the list
|
||||
* @since 1.13
|
||||
*/
|
||||
public List<String> getList() {
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package de.epiceric.shopchest.api.database;
|
||||
|
||||
public enum DatabaseType {
|
||||
SQLITE, MYSQL
|
||||
}
|
Loading…
Reference in New Issue
Block a user