2021-09-24 23:56:42 +00:00
|
|
|
package com.alttd.config;
|
|
|
|
|
|
|
|
|
|
import com.alttd.VillagerUI;
|
2021-10-23 12:42:55 +00:00
|
|
|
import com.alttd.objects.Price;
|
2021-11-03 15:54:12 +00:00
|
|
|
import com.alttd.util.Logger;
|
2021-09-24 23:56:42 +00:00
|
|
|
import com.alttd.util.Utilities;
|
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2DoubleMap;
|
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;
|
2021-10-23 12:42:55 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
2021-09-24 23:56:42 +00:00
|
|
|
import org.bukkit.Material;
|
|
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
2021-10-23 12:42:55 +00:00
|
|
|
import java.util.HashMap;
|
2021-09-24 23:56:42 +00:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
public class WorthConfig extends AbstractConfig {
|
|
|
|
|
static WorthConfig config;
|
|
|
|
|
static int version;
|
|
|
|
|
|
|
|
|
|
public WorthConfig() {
|
|
|
|
|
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "VillagerShopUI"), "worth.yml");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void reload() {
|
|
|
|
|
config = new WorthConfig();
|
|
|
|
|
|
|
|
|
|
version = config.getInt("config-version", 1);
|
|
|
|
|
config.set("config-version", 1);
|
|
|
|
|
|
|
|
|
|
config.readConfig(WorthConfig.class, null);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-23 12:42:55 +00:00
|
|
|
public static Object2ObjectOpenHashMap<Material, Price> prices = new Object2ObjectOpenHashMap<>();
|
2021-09-24 23:56:42 +00:00
|
|
|
|
|
|
|
|
private static void loadWorth() {
|
|
|
|
|
prices.clear();
|
|
|
|
|
ConfigurationSection worth = config.getConfigurationSection("worth");
|
2021-10-23 12:42:55 +00:00
|
|
|
Set<String> points = worth.getKeys(false);
|
|
|
|
|
for (String point : points) {
|
|
|
|
|
ConfigurationSection pointSection = worth.getConfigurationSection(point);
|
|
|
|
|
Set<String> materials = worth.getConfigurationSection(point).getKeys(false);
|
|
|
|
|
for (String key : materials) {
|
|
|
|
|
Material material = Material.getMaterial(key);
|
|
|
|
|
if (material == null) {
|
2021-11-03 15:54:12 +00:00
|
|
|
Logger.warning("Invalid key in worth.yml: %.", key);
|
2021-10-23 12:42:55 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
prices.put(Material.getMaterial(key), new Price(Utilities.round(pointSection.getDouble(key), 2), Integer.parseInt(point)));
|
2021-09-24 23:56:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|