package com.alttd.easter.config; import lombok.extern.slf4j.Slf4j; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.inventory.ItemStack; import java.io.File; import java.util.ArrayList; import java.util.List; @Slf4j public class Config extends AbstractConfig { static Config config; Config() { super( new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "Easter"), "config.yml"); } public static void reload() { log.info("Reloading config"); config = new Config(); config.readConfig(Config.class, null); } public static class EGGS { private static final String prefix = "eggs."; public static double SPAWN_CHANCE = 0.02; // ~2 per night per player @SuppressWarnings("unused") private static void load() { SPAWN_CHANCE = config.getDouble(prefix, "spawn-chance", SPAWN_CHANCE); } } public static class RABBIT { private static final String prefix = "rabbit."; public static String WORLD = "world"; public static double X = 0, Y = 64, Z = 0; public static float YAW = 0, PITCH = 0; public static double INTERACT_RADIUS = 2.5; @SuppressWarnings("unused") private static void load() { WORLD = config.getString(prefix, "world", WORLD); X = config.getDouble(prefix, "x", X); Y = config.getDouble(prefix, "y", Y); Z = config.getDouble(prefix, "z", Z); YAW = (float) config.getDouble(prefix, "yaw", YAW); PITCH = (float) config.getDouble(prefix, "pitch", PITCH); INTERACT_RADIUS = config.getDouble(prefix, "interact-radius", INTERACT_RADIUS); } public static Location getLocation(org.bukkit.Server server) { World world = server.getWorld(WORLD); if (world == null) { return null; } return new Location(world, X, Y, Z, YAW, PITCH); } } public static class PRIZES { private static final String prefix = "prizes."; public static List LIST = new ArrayList<>(); @SuppressWarnings("unused") private static void load() { List raw = config.yaml.getList(prefix + "list"); LIST = new ArrayList<>(); if (raw != null) { for (Object o : raw) { if (o instanceof ItemStack item) { LIST.add(item); } } } // ensure path exists config.yaml.addDefault(prefix + "list", LIST); } public static void addPrize(ItemStack item) { LIST.add(item); config.set(prefix, "list", LIST); } public static ItemStack getRandomPrize() { if (LIST.isEmpty()) { return null; } return LIST.get((int) (Math.random() * LIST.size())).clone(); } } }