package net.c4k3.Portals;

import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

public class BlockBreak implements Listener {

	@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled=true)
	public void onPlayerDeath(BlockBreakEvent event) {
		if (event.getBlock().getType() != Material.OBSIDIAN)
			return;

		Block block = event.getBlock();
		int id = SQLite.obsidian_checker(block);

		if (id <= 0)
			return;

		Portals.instance.getLogger().info("Query returned positive. "
				+ "Disabling this portal at "
				+ block.getWorld().getName() + " " + block.getX() 
				+ " " + block.getY() + " " + block.getZ());

		SQLite.delete_portal_pair(id);
	}

}

@@ -20,16 +20,74 @@
 rtals;%0A%0A
+import java.util.ArrayList;%0A%0Aimport org.bukkit.ChatColor;%0A
 import o
@@ -296,16 +296,192 @@
 Event;%0A%0A
+/**%0A * Checks all broken obsidian blocks, checking that they were not part of%0A * a portal that now will have to be deactivated. If they were, deactivate%0A * said portal(s).%0A */%0A
 public c
@@ -608,19 +608,18 @@
 d on
-PlayerDeath
+BlockBreak
 (Blo
@@ -747,14 +747,41 @@
 ;%0A%09%09
-int id
+ArrayList%3CPortalLocation%3E portals
  = S
@@ -818,33 +818,118 @@
 %0A%0A%09%09
-if (id %3C= 0)%0A%09%09%09return;%0A%0A
+for (PortalLocation portal : portals) %7B%0A%09%09%09if (PortalCheck.is_valid_portal(portal.block, block) == false) %7B%0A%09%09
 %09%09Po
@@ -992,16 +992,18 @@
 . %22%0A%09%09%09%09
+%09%09
 + %22Disab
@@ -1023,23 +1023,33 @@
 tal at %22
-%0A
+ %0A%09
 %09%09%09%09
+%09
 + 
+portal.
 block.ge
@@ -1065,34 +1065,48 @@
 getName() + %22 %22 
-+ 
+%0A%09%09%09%09%09%09+ portal.
 block.getX() %0A%09%09
@@ -1106,21 +1106,30 @@
 X() 
-%0A%09%09%09%09
 + %22 %22 
-+ 
+%0A%09%09%09%09%09%09+ portal.
 bloc
@@ -1143,18 +1143,32 @@
 ) + %22 %22 
-+ 
+%0A%09%09%09%09%09%09+ portal.
 block.ge
@@ -1174,17 +1174,18 @@
 etZ());%0A
-%0A
+%09%09
 %09%09SQLite
@@ -1208,15 +1208,115 @@
 air(
-id);%0A%09%7D%0A
+portal.id);%0A%09%09%09%09event.getPlayer().sendMessage(ChatColor.RED + %22You have deactivated a portal.%22);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

Update BlockBreak event to work in both directions and with multiple portals