package com.elmakers.mine.bukkit.effect;

import de.slikey.effectlib.Effect;
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.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 sourcePlayer = player.getOriginEntity();
        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 (sourcePlayer != null && sourcePlayer instanceof Player) {
            nameMap.put("$name", ((Player)sourcePlayer).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();
            }
        }
    }
}

@@ -108,24 +108,50 @@
 ectManager;%0A
+import org.bukkit.Bukkit;%0A
 import org.b
@@ -1518,136 +1518,413 @@
     
-return effectManager.start(configuration.getString(%22class%22), configuration, origin, target, sourceEntity, targetEntity, nameMap)
+Effect%5B%5D effects = null;%0A        String effectClass = configuration.getString(%22class%22);%0A        try %7B%0A            effectManager.start(effectClass, configuration, origin, target, sourceEntity, targetEntity, nameMap);%0A        %7D catch (Throwable ex) %7B%0A            Bukkit.getLogger().warning(%22Error playing effects of class: %22 + effectClass);%0A            ex.printStackTrace();%0A        %7D%0A        return effects
 ;%0A  
@@ -2058,24 +2058,24 @@
 t.cancel();%0A
-
             
@@ -2091,32 +2091,104 @@
 Throwable ex) %7B%0A
+                Bukkit.getLogger().warning(%22Error cancelling effects%22);%0A
                 

Add some safety checks around EffectLib calls