package irc.bot;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Socket;

public class reciveMessageEvent implements CustomEvent,Runnable{
	
	Socket server;
	BufferedReader reader;
	
	public reciveMessageEvent() throws IOException{
		server=JIRCBOTPlugin.getServer();
		reader=new BufferedReader( new InputStreamReader( server.getInputStream() ) );
	}
	
	@Override
	public String getEventName() {
		final String name="reciveMessageEvent";
		return name;
	}

	@Override
	public void Do() {
		
		for(  JIRCBOTListener event :  JIRCBOTPlugin.jircbotlistenerlist ){
			Method[] methods=event.getClass().getMethods();
			for( Method method : methods ){
				if( method.getParameterTypes().equals(this) ){ //為什麼沒有contains?
					try {
						method.invoke(this); //觸發了自己寫的Method
					} catch (IllegalAccessException | IllegalArgumentException
							| InvocationTargetException e) {
						e.printStackTrace();
					}
				}
			}
		}
		
	}

	@Override
	public void run() {
		
		String readline;
		
		try {
			readline = reader.readLine();
				while( readline != null ){
			
					Do();
			
					if( readline.matches(".* PRIVMSG .*")){
						System.out.println(readline.substring( readline.indexOf("PRIVMSG")+9 ));
					}
					else{
						System.out.println( readline );
					}
				}
		}
		catch(IOException e1){
			e1.printStackTrace();
		}
	}
	
	
	
}

@@ -1221,195 +1221,10 @@
 %0A%09%09%09
-%0A
 %09%09
-%09%09%09if( readline.matches(%22.* PRIVMSG .*%22))%7B%0A%09%09%09%09%09%09System.out.println(readline.substring( readline.indexOf(%22PRIVMSG%22)+9 ));%0A%09%09%09%09%09%7D%0A%09%09%09%09%09else%7B%0A%09%09%09%09%09%09System.out.println( readline );%0A%09%09%09%09%09%7D
 %0A%09%09%09

remove display message subscribe