2011-04-16 00:42:43 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.logging.Logger;
|
2011-04-16 06:28:56 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2011-04-16 00:42:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class Worth implements IConf
|
|
|
|
{
|
|
|
|
private static final Logger logger = Logger.getLogger("Minecraft");
|
2011-04-16 05:57:16 +00:00
|
|
|
private EssentialsConf config;
|
2011-04-16 00:42:43 +00:00
|
|
|
|
|
|
|
public Worth(File dataFolder)
|
|
|
|
{
|
|
|
|
config = new EssentialsConf(new File(dataFolder, "worth.yml"));
|
|
|
|
config.setTemplateName("/worth.yml");
|
|
|
|
config.load();
|
|
|
|
}
|
|
|
|
|
2011-04-16 06:28:56 +00:00
|
|
|
public double getPrice(ItemStack itemStack)
|
2011-04-16 00:42:43 +00:00
|
|
|
{
|
2011-04-16 14:39:31 +00:00
|
|
|
double result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase().replace("_", "")+"."+itemStack.getDurability(), Double.NaN);
|
|
|
|
if (Double.isNaN(result)) {
|
|
|
|
result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase().replace("_", "")+".0", Double.NaN);
|
|
|
|
}
|
2011-04-16 06:28:56 +00:00
|
|
|
if (Double.isNaN(result)) {
|
2011-04-16 06:45:37 +00:00
|
|
|
result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase().replace("_", ""), Double.NaN);
|
2011-04-16 06:28:56 +00:00
|
|
|
}
|
|
|
|
if (Double.isNaN(result)) {
|
2011-04-16 15:25:48 +00:00
|
|
|
result = config.getDouble("worth-"+itemStack.getTypeId(), Double.NaN);
|
2011-04-16 06:28:56 +00:00
|
|
|
}
|
|
|
|
return result;
|
2011-04-16 00:42:43 +00:00
|
|
|
}
|
|
|
|
|
2011-04-16 06:28:56 +00:00
|
|
|
public void setPrice(ItemStack itemStack, double price)
|
2011-04-16 00:42:43 +00:00
|
|
|
{
|
2011-04-16 06:28:56 +00:00
|
|
|
if (itemStack.getType().getData() == null) {
|
2011-04-16 06:45:37 +00:00
|
|
|
config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", ""), price);
|
2011-04-16 06:28:56 +00:00
|
|
|
} else {
|
2011-04-16 14:39:31 +00:00
|
|
|
// Bukkit-bug: getDurability still contains the correct value, while getData().getData() is 0.
|
|
|
|
itemStack.getData();
|
|
|
|
config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", "")+"."+itemStack.getDurability(), price);
|
2011-04-16 06:28:56 +00:00
|
|
|
}
|
|
|
|
config.removeProperty("worth-"+itemStack.getTypeId());
|
2011-04-16 00:42:43 +00:00
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reloadConfig()
|
|
|
|
{
|
|
|
|
config.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|