2011-04-16 00:42:43 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
|
|
|
import java.io.File;
|
2011-11-21 01:55:26 +00:00
|
|
|
import java.util.Locale;
|
2011-04-16 00:42:43 +00:00
|
|
|
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-06-01 10:40:12 +00:00
|
|
|
private final 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-11-21 01:55:26 +00:00
|
|
|
String itemname = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
2011-04-16 17:26:32 +00:00
|
|
|
double result;
|
2011-10-25 21:18:28 +00:00
|
|
|
result = config.getDouble("worth." + itemname + "." + itemStack.getDurability(), Double.NaN);
|
|
|
|
if (Double.isNaN(result))
|
|
|
|
{
|
|
|
|
result = config.getDouble("worth." + itemname + ".0", Double.NaN);
|
2011-04-16 14:39:31 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
if (Double.isNaN(result))
|
|
|
|
{
|
|
|
|
result = config.getDouble("worth." + itemname, Double.NaN);
|
2011-04-16 06:28:56 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
if (Double.isNaN(result))
|
|
|
|
{
|
|
|
|
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-10-25 21:18:28 +00:00
|
|
|
if (itemStack.getType().getData() == null)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
config.setProperty("worth." + itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), price);
|
2011-10-25 21:18:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-16 14:39:31 +00:00
|
|
|
// Bukkit-bug: getDurability still contains the correct value, while getData().getData() is 0.
|
2011-11-21 01:55:26 +00:00
|
|
|
config.setProperty("worth." + itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "") + "." + itemStack.getDurability(), price);
|
2011-04-16 06:28:56 +00:00
|
|
|
}
|
2011-10-25 21:18:28 +00:00
|
|
|
config.removeProperty("worth-" + itemStack.getTypeId());
|
2011-04-16 00:42:43 +00:00
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:07:28 +00:00
|
|
|
@Override
|
2011-04-16 00:42:43 +00:00
|
|
|
public void reloadConfig()
|
|
|
|
{
|
|
|
|
config.load();
|
|
|
|
}
|
|
|
|
}
|