mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-24 02:56:02 +01:00
Added a new config system
This commit is contained in:
parent
028a18179c
commit
513aeef7b7
72
com/Acrobot/Breeze/Configuration/Configuration.java
Normal file
72
com/Acrobot/Breeze/Configuration/Configuration.java
Normal file
@ -0,0 +1,72 @@
|
||||
package com.Acrobot.Breeze.Configuration;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Configuration {
|
||||
public static void loadFileIntoClass(File file, Class clazz) {
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
try {
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (!Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String path = field.getName();
|
||||
|
||||
try {
|
||||
if (config.isSet(path)) {
|
||||
field.set(null, config.get(path));
|
||||
} else {
|
||||
configureProperty(bw, field);
|
||||
}
|
||||
} catch (IllegalAccessException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
bw.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void configureProperty(BufferedWriter writer, Field field) {
|
||||
try {
|
||||
writer.write('\n' + field.getName() + ": " + retrieveValue(field.get(null)));
|
||||
|
||||
if (field.isAnnotationPresent(ConfigurationComment.class)) {
|
||||
writer.write('\n' + "#" + field.getAnnotation(ConfigurationComment.class).value());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static String retrieveValue(Object value) {
|
||||
StringBuilder toReturn = new StringBuilder(30);
|
||||
|
||||
if (value instanceof Number || value instanceof Boolean) {
|
||||
toReturn.append(String.valueOf(value));
|
||||
} else {
|
||||
toReturn.append('\"').append(String.valueOf(value)).append('\"');
|
||||
}
|
||||
|
||||
return toReturn.toString();
|
||||
}
|
||||
}
|
19
com/Acrobot/Breeze/Configuration/ConfigurationComment.java
Normal file
19
com/Acrobot/Breeze/Configuration/ConfigurationComment.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.Acrobot.Breeze.Configuration;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Annotation for a configuration value
|
||||
*
|
||||
* @author Acrobot
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ConfigurationComment {
|
||||
/**
|
||||
* This option's comment
|
||||
*
|
||||
* @return Comment
|
||||
*/
|
||||
public String value();
|
||||
}
|
7
com/Acrobot/Breeze/Configuration/FieldParser.java
Normal file
7
com/Acrobot/Breeze/Configuration/FieldParser.java
Normal file
@ -0,0 +1,7 @@
|
||||
package com.Acrobot.Breeze.Configuration;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class FieldParser {
|
||||
}
|
7
com/Acrobot/Breeze/Configuration/ValueParser.java
Normal file
7
com/Acrobot/Breeze/Configuration/ValueParser.java
Normal file
@ -0,0 +1,7 @@
|
||||
package com.Acrobot.Breeze.Configuration;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class ValueParser {
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.Acrobot.Breeze.Utils;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Language;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class MessageUtil {
|
||||
public static void sendMessage(CommandSender sender, Language message) {
|
||||
String toSend = Config.getLocal(message);
|
||||
|
||||
sender.sendMessage(toSend);
|
||||
}
|
||||
|
||||
public static boolean sendMessage(String playerName, Language message) {
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
|
||||
if (player != null) {
|
||||
sendMessage(player, message);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class BreezeConfiguration extends YamlConfiguration {
|
||||
protected final File file;
|
||||
protected final Map<String, Value> defaultValues = new LinkedHashMap<String, Value>();
|
||||
|
||||
protected BreezeConfiguration(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds default values for the config
|
||||
*
|
||||
* @param map The default values to add
|
||||
*/
|
||||
public void addDefaultValues(Map<String, ? extends Value> map) {
|
||||
defaultValues.putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new BreezeConfiguration object
|
||||
*
|
||||
* @param file file to load config from
|
||||
* @return BreezeConfiguration object
|
||||
*/
|
||||
public static BreezeConfiguration loadConfiguration(File file) {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException("File cannot be null");
|
||||
}
|
||||
|
||||
BreezeConfiguration config = new BreezeConfiguration(file);
|
||||
|
||||
config.load();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new BreezeConfiguration object
|
||||
*
|
||||
* @param file file to load config from
|
||||
* @param defaults default values
|
||||
* @return BreezeConfiguration object
|
||||
*/
|
||||
public static BreezeConfiguration loadConfiguration(File file, Map<String, Value> defaults) {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException("File cannot be null");
|
||||
}
|
||||
|
||||
BreezeConfiguration config = new BreezeConfiguration(file);
|
||||
|
||||
config.addDefaultValues(defaults);
|
||||
|
||||
config.load();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the config
|
||||
*/
|
||||
public void load() {
|
||||
try {
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdir();
|
||||
}
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
super.load(file);
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (createDefaultValues()) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads (saves and loads) the config
|
||||
*/
|
||||
public void reload() {
|
||||
save();
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates default values
|
||||
*
|
||||
* @return were any values added?
|
||||
*/
|
||||
private boolean createDefaultValues() {
|
||||
boolean changed = false;
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||
|
||||
for (Map.Entry<String, Value> entry : defaultValues.entrySet()) {
|
||||
if (this.contains(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
changed = true;
|
||||
bw.write('\n' + entry.getKey() + ": " + entry.getValue().retrieveValue());
|
||||
}
|
||||
|
||||
bw.close();
|
||||
|
||||
if (changed) {
|
||||
load();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the config
|
||||
*/
|
||||
public void save() {
|
||||
try {
|
||||
super.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Utils.uName;
|
||||
import com.nijikokun.register.payment.forChestShop.Methods;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Config {
|
||||
private static BreezeConfiguration normalConfig;
|
||||
private static BreezeConfiguration languageConfig;
|
||||
|
||||
public static void setup() {
|
||||
File configFolder = ChestShop.getFolder();
|
||||
|
||||
normalConfig = BreezeConfiguration.loadConfiguration(new File(configFolder, "config.yml"), Property.getValues());
|
||||
languageConfig = BreezeConfiguration.loadConfiguration(new File(configFolder, "local.yml"), Language.getValues());
|
||||
|
||||
uName.config = BreezeConfiguration.loadConfiguration(new File(configFolder, "longName.storage"));
|
||||
|
||||
Methods.setPreferred(Config.getString(Property.PREFERRED_ECONOMY_PLUGIN));
|
||||
}
|
||||
|
||||
public static boolean getBoolean(Property value) {
|
||||
return (Boolean) getValue(value.name());
|
||||
}
|
||||
|
||||
public static float getFloat(Property value) {
|
||||
return getFloat(value.name());
|
||||
}
|
||||
|
||||
public static float getFloat(String value) {
|
||||
return new Float(getValue(value).toString());
|
||||
}
|
||||
|
||||
public static String getString(Property value) {
|
||||
return (String) getValue(value.name());
|
||||
}
|
||||
|
||||
public static int getInteger(Property value) {
|
||||
return Integer.parseInt(getValue(value.name()).toString());
|
||||
}
|
||||
|
||||
public static double getDouble(Property value) {
|
||||
return getDouble(value.name());
|
||||
}
|
||||
|
||||
public static double getDouble(String value) {
|
||||
return new Double(getValue(value).toString());
|
||||
}
|
||||
|
||||
private static String getColored(String msg) {
|
||||
return ChatColor.translateAlternateColorCodes('&', msg);
|
||||
}
|
||||
|
||||
public static String getLocal(Language lang) {
|
||||
return getColored(languageConfig.getString(Language.prefix.name()) + languageConfig.getString(lang.name()));
|
||||
}
|
||||
|
||||
public static boolean exists(String value) {
|
||||
return getValue(value) != null;
|
||||
}
|
||||
|
||||
private static Object getValue(String node) {
|
||||
return normalConfig.get(node);
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public enum Language {
|
||||
prefix("&a[Shop] &f"),
|
||||
iteminfo("&aItem Information:&f"),
|
||||
|
||||
ACCESS_DENIED("You don't have permission to do that!"),
|
||||
|
||||
NOT_ENOUGH_MONEY("You don't have enough money!"),
|
||||
NOT_ENOUGH_MONEY_SHOP("Shop owner doesn't have enough money!"),
|
||||
|
||||
NO_BUYING_HERE("You can't buy here!"),
|
||||
NO_SELLING_HERE("You can't sell here!"),
|
||||
|
||||
NOT_ENOUGH_SPACE_IN_INVENTORY("You haven't got enough space in inventory!"),
|
||||
NOT_ENOUGH_SPACE_IN_CHEST("There isn't enough space in chest!"),
|
||||
NOT_ENOUGH_ITEMS_TO_SELL("You don't have enough items to sell!"),
|
||||
|
||||
NOT_ENOUGH_STOCK("This shop is out of stock."),
|
||||
NOT_ENOUGH_STOCK_IN_YOUR_SHOP("Your %material shop is out of stock!"),
|
||||
|
||||
YOU_BOUGHT_FROM_SHOP("You bought %item from %owner for %price."),
|
||||
SOMEBODY_BOUGHT_FROM_YOUR_SHOP("%buyer bought %item for %price from you."),
|
||||
|
||||
YOU_SOLD_TO_SHOP("You sold %item to %buyer for %price."),
|
||||
SOMEBODY_SOLD_TO_YOUR_SHOP("%seller sold %item for %price to you."),
|
||||
|
||||
YOU_CANNOT_CREATE_SHOP("You can't create this type of shop!"),
|
||||
NO_CHEST_DETECTED("Couldn't find a chest!"),
|
||||
INVALID_SHOP_DETECTED("The shop cannot be used! (It might lack a chest!)"),
|
||||
ANOTHER_SHOP_DETECTED("Another player's shop detected!"),
|
||||
CANNOT_ACCESS_THE_CHEST("You don't have permissions to access this chest!"),
|
||||
|
||||
PROTECTED_SHOP("Successfully protected the shop with LWC!"),
|
||||
SHOP_CREATED("Shop successfully created!"),
|
||||
SHOP_REFUNDED("You have been refunded %amount."),
|
||||
|
||||
RESTRICTED_SIGN_CREATED("Sign succesfully created!"),
|
||||
|
||||
NO_PERMISSION("You don't have permissions to do that!"),
|
||||
INCORRECT_ITEM_ID("You have specified invalid item id!"),
|
||||
NOT_ENOUGH_PROTECTIONS("You have reached the protection limit!"),
|
||||
|
||||
CANNOT_CREATE_SHOP_HERE("You can't create shop here!");
|
||||
|
||||
|
||||
private final String text;
|
||||
private static final Map<String, Value> LANGUAGE_STRINGS = new LinkedHashMap<String, Value>();
|
||||
|
||||
private Language(String def) {
|
||||
text = def;
|
||||
}
|
||||
|
||||
public Value getValue() {
|
||||
return new Value(text);
|
||||
}
|
||||
|
||||
public static Map<String, Value> getValues() {
|
||||
return LANGUAGE_STRINGS;
|
||||
}
|
||||
|
||||
static {
|
||||
for (Language property : Language.values()) {
|
||||
LANGUAGE_STRINGS.put(property.name(), property.getValue());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public enum Property {
|
||||
//I put \n here, so the properties are nicely spaced out
|
||||
PREFERRED_ECONOMY_PLUGIN("", "WHEN NOT USING VAULT. Preferred (if not found, uses any other) economy plugin (iConomy, BOSEconomy, Essentials).\n"),
|
||||
|
||||
SHOP_INTERACTION_INTERVAL(100, "(In 1/1000th of a second) How often can a player use the shop sign?"),
|
||||
IGNORE_CREATIVE_MODE(true, "Do you want to allow using shops to people in creative mode?"),
|
||||
REVERSE_BUTTONS(false, "If true, people will buy with left-click and sell with right-click."),
|
||||
SHIFT_SELLS_EVERYTHING(false, "If true, people will be able to sell/buy everything available of the same type."),
|
||||
ALLOW_SIGN_CHEST_OPEN(true, "Can shop's chest be opened by owner with right-clicking a shop's sign?"),
|
||||
ALLOW_LEFT_CLICK_DESTROYING(true, "If true, if you left-click your own shop sign you won't open chest's inventory, but instead you will start destroying the sign.\n"),
|
||||
|
||||
REMOVE_EMPTY_SHOPS(false, "If true, if the shop is empty, the sign is destroyed and put into the chest, so the shop isn't usable anymore."),
|
||||
REMOVE_EMPTY_CHESTS(false, "If true, if the REMOVE_EMPTY_SHOPS option is turned on, the chest is also destroyed.\n"),
|
||||
|
||||
ADMIN_SHOP_NAME("Admin Shop", "First line of your Admin Shop's sign should look like this"),
|
||||
SERVER_ECONOMY_ACCOUNT("", "The economy account which Admin Shops should use and to which all taxes will go"),
|
||||
TAX_AMOUNT(0, "Percent of the price that should go to the server's account. (100 = 100 percent)"),
|
||||
SERVER_TAX_AMOUNT(0, "Percent of the price that should go to the server's account when buying from an Admin Shop\n"),
|
||||
|
||||
SHOP_CREATION_PRICE(0, "Amount of money player must pay to create a shop"),
|
||||
SHOP_REFUND_PRICE(0, "How much money do you get back when destroying a sign?\n"),
|
||||
|
||||
BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE(true, "Should we block shops that sell things for more than they buy? (This prevents newbies from creating shops that would be exploited)\n"),
|
||||
|
||||
ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK(false, "Do you want to allow other players to build a shop on a block where there's one already?"),
|
||||
ALLOW_PARTIAL_TRANSACTIONS(true, "Can shops be used even when the seller doesn't have enough items? (The price will be scaled adequatly to the item amount)\n"),
|
||||
|
||||
SHOW_MESSAGE_OUT_OF_STOCK(true, "Do you want to show \"Out of stock\" messages?"),
|
||||
SHOW_TRANSACTION_INFORMATION_CLIENT(true, "Do you want to show \"You bought/sold... \" messages?"),
|
||||
SHOW_TRANSACTION_INFORMATION_OWNER(true, "Do you want to show \"Somebody bought/sold... \" messages?\n"),
|
||||
|
||||
LOG_TO_FILE(false, "If true, plugin will log transactions in its own file"),
|
||||
LOG_TO_CONSOLE(true, "Do you want ChestShop's messages to show up in console?"),
|
||||
LOG_TO_DATABASE(false, "If true, plugin will log transactions in EBean database"),
|
||||
RECORD_TIME_TO_LIVE(600, "How long should transaction information be stored in the database (in seconds, -1 means forever)?\n"),
|
||||
|
||||
USE_BUILT_IN_PROTECTION(true, "Do you want to use built-in protection against chest destruction?"),
|
||||
STICK_SIGNS_TO_CHESTS(false, "Do you want to have shop signs \"stick\" to chests?"),
|
||||
TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY(false, "EXPERIMENTAL: Do you want to turn off the default protection when another plugin is protecting the block? (Will leave the chest visually open - CraftBukkit bug!)"),
|
||||
TURN_OFF_SIGN_PROTECTION(false, "Do you want to turn off the default sign protection? Warning! Other players will be able to destroy other people's shops!"),
|
||||
PROTECT_CHEST_WITH_LWC(false, "Do you want to protect shop chests with LWC?"),
|
||||
PROTECT_SIGN_WITH_LWC(false, "Do you want to protect shop signs with LWC?\n"),
|
||||
|
||||
//Statistics page
|
||||
GENERATE_STATISTICS_PAGE(false, "If true, plugin will generate shop statistics webpage."),
|
||||
STATISTICS_PAGE_PATH("plugins/ChestShop/website.html", "Where should your generated website be saved?"),
|
||||
STATISTICS_PAGE_GENERATION_INTERVAL(60, "How often should the website be generated?\n"),
|
||||
|
||||
//Towny stuff
|
||||
TOWNY_INTEGRATION(false, "Do you want to only let people build inside shop plots?"),
|
||||
TOWNY_SHOPS_FOR_OWNERS_ONLY(true, "If true, only plot owners are able to build inside a shop plot. If false, every town's resident is able to build there.\n"),
|
||||
|
||||
//WorldGuard stuff
|
||||
WORLDGUARD_INTEGRATION(false, "Do you want to only let people build inside regions?"),
|
||||
WORLDGUARD_USE_FLAG(true, "Do you want to only let poeple build inside region flagged by doing /region regionName flag chestshop allow?"),
|
||||
WORLDGUARD_USE_PROTECTION(false, "Do you want ChestShop to respect WorldGuard's chest protection?\n"),
|
||||
|
||||
//Heroes stuff
|
||||
HEROES_EXP(100, "How much Heroes exp should people get for creating a ChestShop?\n");
|
||||
|
||||
|
||||
private final Object value;
|
||||
private final String comment;
|
||||
|
||||
private static final Map<String, Value> PROPERTIES = new LinkedHashMap<String, Value>();
|
||||
|
||||
private Property(Object value, String comment) {
|
||||
this.value = value;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public Value getValue() {
|
||||
return new Value(value, comment);
|
||||
}
|
||||
|
||||
public static Map<String, Value> getValues() {
|
||||
return PROPERTIES;
|
||||
}
|
||||
|
||||
static {
|
||||
for (Property property : Property.values()) {
|
||||
PROPERTIES.put(property.name(), property.getValue());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Value {
|
||||
public final Object value;
|
||||
public final String comment;
|
||||
|
||||
public Value(Object value, String comment) {
|
||||
this.value = value;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public Value(Object value) {
|
||||
this(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value of that Value
|
||||
*
|
||||
* @return The value
|
||||
*/
|
||||
public String retrieveValue() {
|
||||
StringBuilder toReturn = new StringBuilder(30);
|
||||
|
||||
if (value instanceof Number || value instanceof Boolean) {
|
||||
toReturn.append(String.valueOf(value));
|
||||
} else {
|
||||
toReturn.append('\"').append(String.valueOf(value)).append('\"');
|
||||
}
|
||||
|
||||
if (comment != null) {
|
||||
toReturn.append('\n').append('#').append(comment);
|
||||
}
|
||||
|
||||
return toReturn.toString();
|
||||
}
|
||||
}
|
@ -1,11 +1,16 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
package com.Acrobot.ChestShop.Configuration;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class MaxPrice {
|
||||
private static Configuration config = YamlConfiguration.loadConfiguration(ChestShop.loadFile("config.yml"));
|
||||
|
||||
public static boolean canCreate(double buyPrice, double sellPrice, Material mat) {
|
||||
return buyPriceWithinRange(buyPrice, mat) && sellPriceWithinRange(sellPrice, mat);
|
||||
}
|
||||
@ -46,7 +51,7 @@ public class MaxPrice {
|
||||
|
||||
public static double getPrice(Price price, int itemID) {
|
||||
String node = "max-" + price + "-price" + (itemID > 0 ? "-" + itemID : "");
|
||||
return Config.exists(node) ? Config.getDouble(node) : Double.MAX_VALUE;
|
||||
return config.isSet(node) ? config.getDouble(node) : Double.MAX_VALUE;
|
||||
}
|
||||
|
||||
private static enum Price {
|
78
com/Acrobot/ChestShop/Configuration/Messages.java
Normal file
78
com/Acrobot/ChestShop/Configuration/Messages.java
Normal file
@ -0,0 +1,78 @@
|
||||
package com.Acrobot.ChestShop.Configuration;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Messages {
|
||||
public static String prefix = ChatColor.GREEN + "[Shop] " + ChatColor.RESET;
|
||||
public static String iteminfo = ChatColor.GREEN + "Item Information: " + ChatColor.RESET;
|
||||
|
||||
public static byte NEWLINE_1; ///////////////////////////////////////////////////
|
||||
|
||||
public static String ACCESS_DENIED = "You don't have permission to do that!";
|
||||
|
||||
public static byte NEWLINE_2; ///////////////////////////////////////////////////
|
||||
|
||||
public static String NOT_ENOUGH_MONEY = "You don't have enough money!";
|
||||
public static String NOT_ENOUGH_MONEY_SHOP = "Shop owner doesn't have enough money!";
|
||||
|
||||
public static byte NEWLINE_3; ///////////////////////////////////////////////////
|
||||
|
||||
public static String NO_BUYING_HERE = "You can't buy here!";
|
||||
public static String NO_SELLING_HERE = "You can't sell here!";
|
||||
|
||||
public static byte NEWLINE_4; ///////////////////////////////////////////////////
|
||||
|
||||
public static String NOT_ENOUGH_SPACE_IN_INVENTORY = "You haven't got enough space in inventory!";
|
||||
public static String NOT_ENOUGH_SPACE_IN_CHEST = "There isn't enough space in chest!";
|
||||
public static String NOT_ENOUGH_ITEMS_TO_SELL = "You don't have enough items to sell!";
|
||||
|
||||
public static byte NEWLINE_5; ///////////////////////////////////////////////////
|
||||
|
||||
public static String NOT_ENOUGH_STOCK = "This shop is out of stock.";
|
||||
public static String NOT_ENOUGH_STOCK_IN_YOUR_SHOP = "Your %material shop is out of stock!";
|
||||
|
||||
public static byte NEWLINE_6; ///////////////////////////////////////////////////
|
||||
|
||||
public static String YOU_BOUGHT_FROM_SHOP = "You bought %item from %owner for %price.";
|
||||
public static String SOMEBODY_BOUGHT_FROM_YOUR_SHOP = "%buyer bought %item for %price from you.";
|
||||
|
||||
public static byte NEWLINE_7; ///////////////////////////////////////////////////
|
||||
|
||||
public static String YOU_SOLD_TO_SHOP = "You sold %item to %buyer for %price.";
|
||||
public static String SOMEBODY_SOLD_TO_YOUR_SHOP = "%seller sold %item for %price to you.";
|
||||
|
||||
public static byte NEWLINE_8; ///////////////////////////////////////////////////
|
||||
|
||||
public static String YOU_CANNOT_CREATE_SHOP = "You can't create this type of shop!";
|
||||
public static String NO_CHEST_DETECTED = "Couldn't find a chest!";
|
||||
public static String INVALID_SHOP_DETECTED = "The shop cannot be used! (It might lack a chest!)";
|
||||
public static String ANOTHER_SHOP_DETECTED = "Another player's shop detected!";
|
||||
public static String CANNOT_ACCESS_THE_CHEST = "You don't have permissions to access this chest!";
|
||||
|
||||
public static byte NEWLINE_9; ///////////////////////////////////////////////////
|
||||
|
||||
public static String PROTECTED_SHOP = "Successfully protected the shop with LWC!";
|
||||
public static String SHOP_CREATED = "Shop successfully created!";
|
||||
public static String SHOP_REFUNDED = "You have been refunded %amount.";
|
||||
|
||||
public static byte NEWLINE_10; ///////////////////////////////////////////////////
|
||||
|
||||
public static String RESTRICTED_SIGN_CREATED = "Sign succesfully created!";
|
||||
|
||||
public static byte NEWLINE_11; ///////////////////////////////////////////////////
|
||||
|
||||
public static String NO_PERMISSION = "You don't have permissions to do that!";
|
||||
public static String INCORRECT_ITEM_ID = "You have specified invalid item id!";
|
||||
public static String NOT_ENOUGH_PROTECTIONS = "You have reached the protection limit!";
|
||||
|
||||
public static byte NEWLINE_12; ///////////////////////////////////////////////////
|
||||
|
||||
public static String CANNOT_CREATE_SHOP_HERE = "You can't create shop here!";
|
||||
|
||||
public static String getMessage(String message) {
|
||||
return prefix + message;
|
||||
}
|
||||
}
|
152
com/Acrobot/ChestShop/Configuration/Properties.java
Normal file
152
com/Acrobot/ChestShop/Configuration/Properties.java
Normal file
@ -0,0 +1,152 @@
|
||||
package com.Acrobot.ChestShop.Configuration;
|
||||
|
||||
import com.Acrobot.Breeze.Configuration.ConfigurationComment;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Properties {
|
||||
@ConfigurationComment("(When not using Vault) Preferred economy plugin to use (iConomy/BOSEconomy/Essentials).")
|
||||
public static String PREFERRED_ECONOMY_PLUGIN = "";
|
||||
|
||||
public static byte NEWLINE_1; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("(In 1/1000th of a second) How often can a player use the shop sign?")
|
||||
public static int SHOP_INTERACTION_INTERVAL = 100;
|
||||
|
||||
@ConfigurationComment("Do you want to allow using shops to people in creative mode?")
|
||||
public static boolean IGNORE_CREATIVE_MODE = true;
|
||||
|
||||
@ConfigurationComment("If true, people will buy with left-click and sell with right-click.")
|
||||
public static boolean REVERSE_BUTTONS = false;
|
||||
|
||||
@ConfigurationComment("If true, people will be able to sell/buy everything available of the same type.")
|
||||
public static boolean SHIFT_SELLS_EVERYTHING = false;
|
||||
|
||||
@ConfigurationComment("Can shop's chest be opened by owner with right-clicking a shop's sign?")
|
||||
public static boolean ALLOW_SIGN_CHEST_OPEN = true;
|
||||
|
||||
@ConfigurationComment("If true, when you left-click your own shop sign you won't open chest's inventory, but instead you will start destroying the sign.")
|
||||
public static boolean ALLOW_LEFT_CLICK_DESTROYING = true;
|
||||
|
||||
public static byte NEWLINE_2; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("If true, if the shop is empty, the sign is destroyed and put into the chest, so the shop isn't usable anymore.")
|
||||
public static boolean REMOVE_EMPTY_SHOPS = false;
|
||||
|
||||
@ConfigurationComment("If true, if the REMOVE_EMPTY_SHOPS option is turned on, the chest is also destroyed.")
|
||||
public static boolean REMOVE_EMPTY_CHESTS = false;
|
||||
|
||||
public static byte NEWLINE_3; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("First line of your Admin Shop's sign should look like this:")
|
||||
public static String ADMIN_SHOP_NAME = "Admin Shop";
|
||||
|
||||
@ConfigurationComment("The economy account which Admin Shops should use and to which all taxes will go")
|
||||
public static String SERVER_ECONOMY_ACCOUNT = "";
|
||||
|
||||
@ConfigurationComment("Percent of the price that should go to the server's account. (100 = 100 percent)")
|
||||
public static int TAX_AMOUNT = 0;
|
||||
|
||||
@ConfigurationComment("Percent of the price that should go to the server's account when buying from an Admin Shop.")
|
||||
public static int SERVER_TAX_AMOUNT = 0;
|
||||
|
||||
@ConfigurationComment("Amount of money player must pay to create a shop")
|
||||
public static double SHOP_CREATION_PRICE = 0;
|
||||
|
||||
@ConfigurationComment("How much money do you get back when destroying a sign?")
|
||||
public static double SHOP_REFUND_PRICE = 0;
|
||||
|
||||
public static byte NEWLINE_4; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("Should we block shops that sell things for more than they buy? (This prevents newbies from creating shops that would be exploited)")
|
||||
public static boolean BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE = true;
|
||||
|
||||
public static byte NEWLINE_5; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("Do you want to allow other players to build a shop on a block where there's one already?")
|
||||
public static boolean ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK = false;
|
||||
|
||||
@ConfigurationComment("Can shops be used even when the seller doesn't have enough items? (The price will be scaled adequatly to the item amount)")
|
||||
public static boolean ALLOW_PARTIAL_TRANSACTIONS = true;
|
||||
|
||||
public static byte NEWLINE_6; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("Do you want to show \"Out of stock\" messages?")
|
||||
public static boolean SHOW_MESSAGE_OUT_OF_STOCK = true;
|
||||
|
||||
@ConfigurationComment("Do you want to show \"You bought/sold... \" messages?")
|
||||
public static boolean SHOW_TRANSACTION_INFORMATION_CLIENT = true;
|
||||
|
||||
@ConfigurationComment("Do you want to show \"Somebody bought/sold... \" messages?")
|
||||
public static boolean SHOW_TRANSACTION_INFORMATION_OWNER = true;
|
||||
|
||||
public static byte NEWLINE_7; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("If true, plugin will log transactions in its own file")
|
||||
public static boolean LOG_TO_FILE = false;
|
||||
|
||||
@ConfigurationComment("Do you want ChestShop's messages to show up in console?")
|
||||
public static boolean LOG_TO_CONSOLE = true;
|
||||
|
||||
@ConfigurationComment("If true, plugin will log transactions in EBean database")
|
||||
public static boolean LOG_TO_DATABASE = false;
|
||||
|
||||
@ConfigurationComment("How long should transaction information be stored in the database (in seconds, -1 means forever)?")
|
||||
public static int RECORD_TIME_TO_LIVE = 600;
|
||||
|
||||
public static byte NEWLINE_8; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("Do you want to use built-in protection against chest destruction?")
|
||||
public static boolean USE_BUILT_IN_PROTECTION = true;
|
||||
|
||||
@ConfigurationComment("Do you want to have shop signs \"stick\" to chests?")
|
||||
public static boolean STICK_SIGNS_TO_CHESTS = false;
|
||||
|
||||
@ConfigurationComment("EXPERIMENTAL: Do you want to turn off the default protection when another plugin is protecting the block? (Will leave the chest visually open - CraftBukkit bug!)")
|
||||
public static boolean TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY = false;
|
||||
|
||||
@ConfigurationComment("Do you want to turn off the default sign protection? Warning! Other players will be able to destroy other people's shops!")
|
||||
public static boolean TURN_OFF_SIGN_PROTECTION = false;
|
||||
|
||||
@ConfigurationComment("Do you want to protect shop chests with LWC?")
|
||||
public static boolean PROTECT_CHEST_WITH_LWC = false;
|
||||
|
||||
@ConfigurationComment("Do you want to protect shop signs with LWC?")
|
||||
public static boolean PROTECT_SIGN_WITH_LWC = false;
|
||||
|
||||
public static byte NEWLINE_9; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("If true, plugin will generate shop statistics webpage.")
|
||||
public static boolean GENERATE_STATISTICS_PAGE = false;
|
||||
|
||||
@ConfigurationComment("Where should your generated website be saved?")
|
||||
public static String STATISTICS_PAGE_PATH = "plugins/ChestShop/website.html";
|
||||
|
||||
@ConfigurationComment("How often should the website be generated?")
|
||||
public static long STATISTICS_PAGE_GENERATION_INTERVAL = 60;
|
||||
|
||||
public static byte NEWLINE_10; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("Do you want to only let people build inside shop plots?")
|
||||
public static boolean TOWNY_INTEGRATION = false;
|
||||
|
||||
@ConfigurationComment("If true, only plot owners are able to build inside a shop plot. If false, every town's resident is able to build there.")
|
||||
public static boolean TOWNY_SHOPS_FOR_OWNERS_ONLY = true;
|
||||
|
||||
public static byte NEWLINE_11; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("Do you want to only let people build inside regions?")
|
||||
public static boolean WORLDGUARD_INTEGRATION = false;
|
||||
|
||||
@ConfigurationComment("Do you want to only let poeple build inside region flagged by doing /region regionName flag chestshop allow?")
|
||||
public static boolean WORLDGUARD_USE_FLAG = true;
|
||||
|
||||
@ConfigurationComment("Do you want ChestShop to respect WorldGuard's chest protection?")
|
||||
public static boolean WORLDGUARD_USE_PROTECTION = false;
|
||||
|
||||
public static byte NEWLINE_12; ///////////////////////////////////////////////////
|
||||
|
||||
@ConfigurationComment("How much Heroes exp should people get for creating a ChestShop?")
|
||||
public static double HEROES_EXP = 100;
|
||||
}
|
Loading…
Reference in New Issue
Block a user