package gg.uhc.fancyfreeze;

import com.google.common.collect.ImmutableList;
import gg.uhc.fancyfreeze.api.CustomEffect;
import gg.uhc.fancyfreeze.api.Freezer;
import gg.uhc.fancyfreeze.api.NMSHandler;
import gg.uhc.fancyfreeze.commands.FreezeCommand;
import gg.uhc.fancyfreeze.commands.GlobalFreezeCommand;
import gg.uhc.fancyfreeze.listeners.DamageListener;
import gg.uhc.fancyfreeze.listeners.InteractListeners;
import gg.uhc.fancyfreeze.listeners.PortalListener;
import gg.uhc.fancyfreeze.listeners.PotionListener;
import gg.uhc.fancyfreeze.effects.ColouredDustParticleEffect;
import gg.uhc.fancyfreeze.effects.wrappers.RingEffect;
import gg.uhc.fancyfreeze.effects.SoundEffect;
import gg.uhc.fancyfreeze.effects.wrappers.VerticalSpreadEffect;
import org.bukkit.Sound;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.List;

public class Entry extends JavaPlugin {

    protected Freezer freezer = null;

    @Override
    public void onEnable() {
        double maxDistance = 3D;

        CustomEffect dust = new ColouredDustParticleEffect(190, 240, 250, 30);
        CustomEffect ring = new RingEffect(dust, maxDistance, 50);
        CustomEffect frozenEffect = new VerticalSpreadEffect(ring, 4D, 6, -.5D);

        NMSHandler handler = getNMSHandler();

        if (handler == null) {
            setEnabled(false);
            getLogger().severe("This version of Spigot is not supported by this plugin");
            return;
        }

        CustomEffect warpEffect = new SoundEffect(Sound.ANVIL_LAND, 1, 0);

        freezer = new DefaultFreezer(this, handler.getFakePotionApplier(), handler.getMovementspeedRemover(), frozenEffect, warpEffect, maxDistance);

        List<Listener> listeners = ImmutableList.<Listener>builder()
                .add(freezer)
                .add(new PotionListener(freezer))
                .add(new DamageListener(freezer))
                .add(new PortalListener(freezer))
                .add(new InteractListeners(freezer))
                .build();

        PluginManager manager = getServer().getPluginManager();
        for (Listener listener : listeners) {
            manager.registerEvents(listener, this);
        }

        getCommand("ff").setExecutor(new FreezeCommand(freezer));
        getCommand("ffg").setExecutor(new GlobalFreezeCommand(freezer));
    }

    public void onDisable() {
        if (freezer != null) {
            // to avoid changes in NMS not carrying over on reload we have to remove all current freezes
            freezer.disableGlobalFreeze();
            freezer.clearAlwaysFreezeList();

            freezer = null;
        }
    }

    protected NMSHandler getNMSHandler() {
        String packageName = getServer().getClass().getPackage().getName();
        String version = packageName.substring(packageName.lastIndexOf(".") + 1);

        switch (version) {
            case "v1_8_R1":
                return new gg.uhc.fancyfreeze.nms.v1_8_R1.NMSHandler();
            case "v1_8_R2":
                return new gg.uhc.fancyfreeze.nms.v1_8_R2.NMSHandler();
            case "v1_8_R3":
                return new gg.uhc.fancyfreeze.nms.v1_8_R3.NMSHandler();
            default:
                return null;
        }
    }
}

@@ -331,32 +331,42 @@
 eze.
-listeners.DamageListener
+effects.ColouredDustParticleEffect
 ;%0Aim
@@ -393,35 +393,30 @@
 eze.
-listeners.InteractListeners
+effects.ParticleEffect
 ;%0Aim
@@ -443,32 +443,27 @@
 eze.
-listeners.PortalListener
+effects.SoundEffect
 ;%0Aim
@@ -490,32 +490,42 @@
 eze.
-listeners.PotionListener
+effects.wrappers.CombinationEffect
 ;%0Aim
@@ -556,36 +556,29 @@
 effects.
-ColouredDustParticle
+wrappers.Ring
 Effect;%0A
@@ -612,36 +612,46 @@
 ffects.wrappers.
-Ring
+VerticalSpread
 Effect;%0Aimport g
@@ -672,86 +672,211 @@
 eze.
-effects.SoundEffect;%0Aimport gg.uhc.fancyfreeze.effects.wrappers.VerticalSpread
+listeners.DamageListener;%0Aimport gg.uhc.fancyfreeze.listeners.InteractListeners;%0Aimport gg.uhc.fancyfreeze.listeners.PortalListener;%0Aimport gg.uhc.fancyfreeze.listeners.PotionListener;%0Aimport org.bukkit.
 Effe
@@ -1689,55 +1689,248 @@
 warp
-Effect = new SoundEffect(Sound.ANVIL_LAND, 1, 0
+Particle = new ParticleEffect(Effect.VILLAGER_THUNDERCLOUD, 0, 0, 1, 1, 1, 0, 10, 30);%0A        CustomEffect warpSound = new SoundEffect(Sound.ANVIL_LAND, 1, 0);%0A        CustomEffect warpEffect = new CombinationEffect(warpParticle, warpSound
 );%0A%0A

add particle effect to warp