package com.bitnix.dirtcryptostore.util;

import com.bitnix.dirtcryptostore.DirtCryptoStorePlugin;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;

public final class EffectUtil {

    private EffectUtil() {
    }

    public static void playEffect(DirtCryptoStorePlugin plugin, Player player, String key) {
        if (!plugin.getConfig().getBoolean("effects.enabled", true)) {
            return;
        }

        ConfigurationSection section = plugin.getConfig().getConfigurationSection("effects." + key);
        if (section == null || !section.getBoolean("enabled", false)) {
            return;
        }

        try {
            Particle particle = Particle.valueOf(section.getString("type", "VILLAGER_HAPPY"));
            int count = section.getInt("count", 10);
            double offsetX = section.getDouble("offset-x", 0.3D);
            double offsetY = section.getDouble("offset-y", 0.6D);
            double offsetZ = section.getDouble("offset-z", 0.3D);
            double extra = section.getDouble("extra", 0.0D);

            Location location = player.getLocation().clone().add(0, 1, 0);
            player.getWorld().spawnParticle(particle, location, count, offsetX, offsetY, offsetZ, extra);
        } catch (IllegalArgumentException ignored) {
        }
    }
}
