package nallar.tickprofiler.minecraft.commands;

import nallar.tickprofiler.Log;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;

import java.util.*;

public abstract class Command extends CommandBase {
	protected boolean requireOp() {
		return false;
	}

	@Override
	public boolean canCommandSenderUseCommand(ICommandSender commandSender) {
		return !requireOp() || super.canCommandSenderUseCommand(commandSender);
	}

	public static void sendChat(ICommandSender commandSender, String message) {
		if (commandSender == MinecraftServer.getServer()) {
			Log.info('\n' + message);
			return;
		}
		while (message != null) {
			int nlIndex = message.indexOf('\n');
			String sent;
			if (nlIndex == -1) {
				sent = message;
				message = null;
			} else {
				sent = message.substring(0, nlIndex);
				message = message.substring(nlIndex + 1);
			}
			commandSender.addChatMessage(new ChatComponentText(sent));
		}
	}

	@Override
	public final void processCommand(ICommandSender commandSender, String... argumentsArray) {
		processCommand(commandSender, new ArrayList<String>(Arrays.asList(argumentsArray)));
	}

	protected abstract void processCommand(ICommandSender commandSender, List<String> arguments);

	@Override
	public int compareTo(Object o) {
		return super.compareTo((ICommand) o);
		// Necessary because generic types are stripped in minecraft, and deobfuscation doesn't add them back.
		// This confuses javac for some reason - compareTo(object) actually is implemented in the superclass.
	}
}

@@ -124,48 +124,8 @@
 e;%0D%0A
-import net.minecraft.command.ICommand;%0D%0A
 impo
@@ -1377,313 +1377,8 @@
 s);%0D
-%0A%0D%0A%09@Override%0D%0A%09public int compareTo(Object o) %7B%0D%0A%09%09return super.compareTo((ICommand) o);%0D%0A%09%09// Necessary because generic types are stripped in minecraft, and deobfuscation doesn't add them back.%0D%0A%09%09// This confuses javac for some reason - compareTo(object) actually is implemented in the superclass.%0D%0A%09%7D%0D
 %0A%7D%0D%0A

Remove now unneeded workaround for 1.6 compilation bug