package in.twizmwaz.cardinal.module.modules.filter.type;

import in.twizmwaz.cardinal.module.modules.filter.FilterModule;
import in.twizmwaz.cardinal.module.modules.filter.FilterState;
import in.twizmwaz.cardinal.module.modules.filter.parsers.CauseFilterParser;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import static in.twizmwaz.cardinal.module.modules.filter.FilterState.ABSTAIN;
import static in.twizmwaz.cardinal.module.modules.filter.FilterState.ALLOW;
import static in.twizmwaz.cardinal.module.modules.filter.FilterState.DENY;

public class CauseFilter extends FilterModule {

    private final EventCause cause;

    public CauseFilter(final CauseFilterParser parser) {
        super(parser.getName(), parser.getParent());
        this.cause = parser.getCause();
    }

    @Override
    public FilterState evaluate(final Object... objects) {
        for (Object object : objects) {
            EventCause eventCause = null;
            if (object instanceof Player) {
                eventCause = EventCause.PLAYER;
            } else if (object instanceof Entity) {
                if (((Entity) object).getType().equals(EntityType.PRIMED_TNT)) {
                    eventCause = EventCause.TNT;
                }
            }
            if (cause.equals(eventCause))
                return ALLOW;
            else if (eventCause != null)
                return DENY;
        }
        return (getParent() == null ? ABSTAIN : getParent().evaluate(objects));
    }

    public enum EventCause {

        /**
         * The event was generated be a player action.
         */
        PLAYER(),
        /**
         * The event was generated by TNT.
         */
        TNT();

        public static EventCause getEventCause(String string) {
            switch (string.toLowerCase().replaceAll(" ", "")) {
                case "player":
                    return PLAYER;
                case "tnt":
                    return TNT;
                default:
                    return null;
            }
        }

    }

}

@@ -284,240 +284,52 @@
 ity.
-Entity;%0Aimport org.bukkit.entity.EntityType;%0Aimport org.bukkit.entity.Player;%0A%0Aimport static in.twizmwaz.cardinal.module.modules.filter.FilterState.ABSTAIN;%0Aimport static in.twizmwaz.cardinal.module.modules.filter.FilterState.ALLOW;
+Player;%0Aimport org.bukkit.entity.TNTPrimed;%0A
 %0Aimp
@@ -394,20 +394,17 @@
 erState.
-DENY
+*
 ;%0A%0Apubli
@@ -929,22 +929,25 @@
 tanceof 
-Entity
+TNTPrimed
 ) %7B%0A    
@@ -962,139 +962,59 @@
     
-if (((Entity) object).getType().equals(EntityType.PRIMED_TNT)) %7B%0A                    eventCause = EventCause.TNT;%0A                %7D
+return cause.equals(EventCause.TNT) ? ALLOW : DENY;
 %0A   
@@ -1695,16 +1695,50 @@
  %22tnt%22:%0A
+                case %22explosion%22:%0A
         

Add 'explosion' as a cause filter possibility, fixes #605