package modtweaker.mods.imc.handler;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Scanner;

import cpw.mods.fml.common.event.FMLInterModComms;

public class Message {

	public static String destination;
	public File[] files;
	public Scanner fileReader;

	public Message(String destination) {
		this.destination = destination;

		files = new File(destination).listFiles(new FilenameFilter() {

			@Override
			public boolean accept(File dir, String name) {
				if (name.toLowerCase().endsWith(".imc")) {
					return true;
				}
				return false;
			}
		});

		for (File file : files) {
			try {
				this.fileReader = new Scanner(file);
				while (fileReader.hasNextLine()) {
					String command = fileReader.nextLine().trim();
					if (command.toLowerCase().startsWith("sendimc(") && command.substring(command.length() - 1).equals(";")) {
						command = command.substring("sendimc(".length()).replace(command.substring(command.length() - 1), "").replace(command.substring(command.length() - 1), "").replaceAll("\"", "");

						String[] input = command.split(",");
						FMLInterModComms.sendMessage(input[0], input[1], input[2]);
						System.out.println(input[0] + ", " + input[1] + ", " + input[2]);
					}
				}
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}

		}
	}
}

@@ -640,17 +640,25 @@
 %7D%0A%09%09%7D);%0A
-%0A
+%09%09try %7B%0A%09
 %09%09for (F
@@ -681,16 +681,8 @@
 ) %7B%0A
-%09%09%09try %7B
 %0A%09%09%09
@@ -1304,16 +1304,20 @@
 %09%09%7D%0A%09%09%09%7D
+%0A%09%09%7D
  catch (
@@ -1346,17 +1346,16 @@
 e) %7B%0A%09%09%09
-%09
 e.printS
@@ -1373,16 +1373,11 @@
 ;%0A%09%09
-%09
 %7D%0A%0A
-%09%09%7D%0A
 %09%7D%0A%7D

Fix IMC crash