package org.mcphoton.impl.server;

import java.util.Scanner;
import org.mcphoton.Photon;
import org.mcphoton.command.Command;
import org.mcphoton.messaging.ChatMessage;
import org.mcphoton.messaging.Messageable;

/**
 *
 * @author TheElectronWill
 */
public class ConsoleThread extends Thread implements Messageable {

	private volatile boolean run = true;
	private final Scanner sc = new Scanner(System.in);

	public ConsoleThread() {
		super("console");
	}

	/**
	 * Stops this Thread nicely, as soon as possible but without any forcing.
	 */
	public void stopNicely() {
		run = false;
	}

	@Override
	public void run() {
		while (run) {
			String line = sc.nextLine();
			String[] parts = line.split(" ", 2);
			Command cmd = Photon.getCommandsRegistry().getRegistered(parts[0]);
			if (parts.length == 1) {
				cmd.execute(this, new String[0]);
			} else {
				cmd.execute(this, parts[1]);
			}
		}
	}

	@Override
	public void sendMessage(CharSequence msg) {
		System.out.println(msg);
	}

	@Override
	public void sendMessage(ChatMessage msg) {
		System.out.println(msg.toConsoleString());
	}

}

@@ -776,16 +776,99 @@
 ts%5B0%5D);%0A
+%09%09%09if (cmd == null) %7B%0A%09%09%09%09System.out.println(%22Unknown command.%22);%0A%09%09%09%09return;%0A%09%09%09%7D%0A
 %09%09%09if (p

Deal with unknown commands