package com.elmakers.mine.bukkit.effect;

import com.elmakers.mine.bukkit.api.effect.ParticleType;
import de.slikey.effectlib.Effect;
import de.slikey.effectlib.EffectLib;
import de.slikey.effectlib.EffectManager;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Manages EffectLib integration
 */
public class EffectLibManager {
    private static EffectManager effectManager;
    private static final Map<String, String> nameMap = new HashMap<String, String>();

    public EffectLibManager() {
    }

    public static EffectLibManager initialize(Plugin plugin) {
        if (effectManager == null) {
            effectManager = new EffectManager(plugin);
        }

        return new EffectLibManager();
    }

    public Effect[] play(Plugin plugin, ConfigurationSection configuration, EffectPlayer player, Location origin, Location target) {
        Entity sourceEntity = player.playAtOrigin ? player.getOriginEntity() : null;
        Entity targetEntity = player.playAtTarget ? player.getTargetEntity() : null;
        origin = player.playAtOrigin ? origin : null;
        target = player.playAtTarget ? target : null;
        if (sourceEntity != null && sourceEntity instanceof Player) {
            nameMap.put("$name", ((Player)sourceEntity).getName());
        } else {
            nameMap.put("$name", "Unknown");
        }

        return effectManager.start(configuration.getString("class"), configuration, origin, target, sourceEntity, targetEntity, nameMap);
    }

    public void cancel(Effect[] effects) {
        for (Effect effect : effects) {
            try {
                effect.cancel();
            } catch (Throwable ex) {
                ex.printStackTrace();
            }
        }
    }
}

@@ -46,129 +46,34 @@
 ort 
-com.elmakers.mine.bukkit.api.effect.ParticleType;%0Aimport de.slikey.effectlib.Effect;%0Aimport de.slikey.effectlib.EffectLib
+de.slikey.effectlib.Effect
 ;%0Aim
@@ -298,140 +298,8 @@
 n;%0A%0A
-import java.lang.reflect.Constructor;%0Aimport java.lang.reflect.Field;%0Aimport java.lang.reflect.Method;%0Aimport java.util.Collection;%0A
 impo
@@ -931,24 +931,80 @@
 n target) %7B%0A
+        Entity sourcePlayer = player.getOriginEntity();%0A
         Enti
@@ -1287,22 +1287,22 @@
  (source
-Entity
+Player
  != null
@@ -1311,22 +1311,22 @@
 & source
-Entity
+Player
  instanc
@@ -1387,22 +1387,22 @@
 r)source
-Entity
+Player
 ).getNam

Fix parameterized text effects