ChestShop-3/com/Acrobot/ChestShop/Configuration/MaxPrice.java

62 lines
1.8 KiB
Java
Raw Normal View History

2012-11-23 20:59:12 +01:00
package com.Acrobot.ChestShop.Configuration;
2012-11-23 20:59:12 +01:00
import com.Acrobot.ChestShop.ChestShop;
import org.bukkit.Material;
2012-11-23 20:59:12 +01:00
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.YamlConfiguration;
/**
* @author Acrobot
*/
public class MaxPrice {
2012-11-23 20:59:12 +01:00
private static Configuration config = YamlConfiguration.loadConfiguration(ChestShop.loadFile("config.yml"));
2012-04-19 15:46:05 +02:00
public static boolean canCreate(double buyPrice, double sellPrice, Material mat) {
return buyPriceWithinRange(buyPrice, mat) && sellPriceWithinRange(sellPrice, mat);
}
private static boolean buyPriceWithinRange(double buyPrice, Material material) {
double bPrice = maxBuyPrice(material);
double maxPrice = maxBuyPrice();
return buyPrice <= bPrice && buyPrice <= maxPrice;
}
private static boolean sellPriceWithinRange(double sellPrice, Material material) {
double sPrice = maxSellPrice(material);
double maxPrice = maxSellPrice();
return sellPrice <= sPrice && sellPrice <= maxPrice;
}
public static double maxBuyPrice() {
return getPrice(Price.buy);
}
public static double maxSellPrice() {
return getPrice(Price.sell);
}
public static double maxBuyPrice(Material material) {
return getPrice(Price.buy, material.getId());
}
2012-04-19 15:46:05 +02:00
public static double maxSellPrice(Material material) {
return getPrice(Price.sell, material.getId());
}
2012-04-19 15:46:05 +02:00
public static double getPrice(Price price) {
return getPrice(price, -1);
}
2012-04-19 15:46:05 +02:00
public static double getPrice(Price price, int itemID) {
2012-04-19 16:36:01 +02:00
String node = "max-" + price + "-price" + (itemID > 0 ? "-" + itemID : "");
2012-11-23 20:59:12 +01:00
return config.isSet(node) ? config.getDouble(node) : Double.MAX_VALUE;
}
2012-04-19 15:46:05 +02:00
private static enum Price {
buy,
sell
}
}