Checking for operators through an IRC server brings with it some delay. To see if the IRC server in question recognizes a user as an operator, you'll need to wait for the MODE signals from Twitch. In Pircbot(assuming you're using that library) prints these signals in the console if you're using an IDE like Eclipse.
I have been looking for a similar method to quickly catch operators in the channel, but I've abandoned it because I found IRC not fast enough for my application. Instead, I just keep an operator list stored locally with the bot. If somebody executes a command, just check the Operator file. However, if the delay isn't a problem for you, then the following explanation may be of use.
The lines you should trigger on are:
1425158996453 :jtv MODE #yourchannel +o someuser
and:
1425159389131 :jtv MODE #yourchannel -o someuser
As you may have guessed, the +o and -o indicate if the person has gained or has lost operator status.
I am using a custom class which allows me to catch the print stream. Initially, I used it for a different purpose, but this might just be what you're looking for. The class is a JPanel which you can place somewhere in your interface and see the PrintStream it in action. The following code is all placed in one file.
I hope this helps you out. Cheers.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Console extends JPanel implements Consumer
{
private static final long serialVersionUID = 1L;
private JTextArea output;
public Console()
{
setLayout( new BorderLayout() );
output = new JTextArea();
add( new JScrollPane(output) );
setLooks();
PrintStream ps = System.out;
System.setOut( new PrintStream( new StreamCapturer("OUT", this, ps) ) ); // print output
System.setErr( new PrintStream( new StreamCapturer("ERR", this, ps) ) ); // print errors
this.setFont( new Font( "Courier New" , Font.PLAIN ,10 ) );
}
@Override
public void appendText(final String text)
{
if (EventQueue.isDispatchThread())
{
output.append(text);
output.setCaretPosition(output.getText().length());
}
else
{
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
appendText(text);
}
});
}
}
private static Color BACKGROUND = new Color(0.2f,0.2f,0.2f,1.0f);
private static Color FOREGROUND = new Color(0.9f,0.9f,0.9f,1.0f);
public void setLooks()
{
output.setBackground( BACKGROUND );
output.setForeground( FOREGROUND );
output.setFont( new Font( "Courier New" , Font.PLAIN , 12 ) );
output.setCaretColor( FOREGROUND );
}
}
interface Consumer
{
public void appendText(String text);
}
class StreamCapturer extends OutputStream
{
private StringBuilder buffer;
private Consumer consumer;
private PrintStream old;
public StreamCapturer(String prefix, Consumer consumer, PrintStream old)
{
buffer = new StringBuilder(128);
this.old = old;
this.consumer = consumer;
}
@Override
public void write(int b) throws IOException
{
char c = (char) b;
String value = Character.toString(c);
buffer.append(value);
if (value.equals("\n"))
{
consumer.appendText(buffer.toString());
buffer.delete(0, buffer.length());
}
old.print(c);
}
}