/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package me.ferrybig.javacoding.teamspeakconnector;

import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.Future;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import me.ferrybig.javacoding.teamspeakconnector.event.ClientEnterViewEvent;
import me.ferrybig.javacoding.teamspeakconnector.event.ClientLeftViewEvent;
import me.ferrybig.javacoding.teamspeakconnector.event.ServerEditEvent;
import me.ferrybig.javacoding.teamspeakconnector.event.ServerListener;
import org.junit.Test;

/**
 *
 *
 */
public class TeamspeakConnectionIT {

	private static final Logger LOG = Logger.getLogger(TeamspeakConnectionIT.class.getName());

	@Test
	public void testSomeMethod() throws InterruptedException, ExecutionException {
		Logger.getGlobal().getParent().setLevel(Level.ALL);
		Logger.getLogger(TeamspeakConnection.class.getName()).setLevel(Level.ALL);
		NioEventLoopGroup group = new NioEventLoopGroup();
		try {
			System.out.println("Creating!");
			TeamspeakApi api = new TeamspeakApi(group);
			Future<TeamspeakConnection> connect = api.connect(new InetSocketAddress("127.0.0.1", 10011), "serveradmin", "test1234");

			System.out.println("Connected!");
			TeamspeakConnection con = connect.sync().get();

			System.out.println("Selecting server!");
			con.getUnresolvedServerById(1).select().sync().get();

			System.out.println("Creating!");
			con.getServer();
			con.getServer();
//			con.getServer();
//			con.getServer();
//			con.getServer();
//			con.getServer();
//			con.getServer();
//			con.getServer();
//			con.getServer();
//			con.getServer();
//			con.getServer();
//			con.getServer();
//			con.getServer();
//			con.getServer();

			System.out.println("Queue make!");
			System.out.println(con.getServer().sync().get());

			System.out.println("Username seting....");
			con.setOwnName("TestingBot").sync().get();

			System.out.println("User list!");
			List<User> users = con.getUsersList().sync().get();
			for (User user : users) {
				if (user.getType() == ClientType.QUERY) {
					continue;
				}
				user.poke("Hello: " + user.getNickname() + ", Your ip address: " + user.getIp());
				user.sendMessage("Hello: " + user.getNickname() + ", Your ip address: " + user.getIp());
			}

			System.out.println("Waiting for messages!");
			con.getPrivateMessageHandler().addHandler(evt -> {
				System.out.println("Message received! " + evt);
				evt.getInvoker().sendMessage("You said: " + evt.getMessage());
			});

			System.out.println("Waiting for eserver events!");
			con.getServerHandler().addHandler(new ServerListener() {
				@Override
				public void onClientEnterView(ClientEnterViewEvent event) {
					LOG.log(Level.INFO, "ClientEnterViewEvent: {0}", event);
					event.getClient().sendMessage("Hello " + event.getClient().getNickname() + "!");
					event.getClient().getChannel().resolv().addListener((Future<Channel> channel) -> {
						event.getClient().sendMessage("Welcome to channel " + channel.get().getName() + "!");
					});
				}

				@Override
				public void onClientLeaveView(ClientLeftViewEvent event) {
					LOG.log(Level.INFO, "ClientLeftViewEvent: {0}", event);
				}

				@Override
				public void onEditServer(ServerEditEvent event) {
					LOG.log(Level.INFO, "ServerEditEvent: {0}", event);
				}

			});

			Thread.sleep(100000);

			System.out.println("Closing...!");
			con.quit().sync().get();

		} finally {
			group.shutdownGracefully();
		}
	}

}

@@ -1171,16 +1171,92 @@
 l.ALL);%0A
+%09%09Logger.getLogger(TeamspeakBootstrap.class.getName()).setLevel(Level.ALL);%0A
 %09%09NioEve
@@ -1360,15 +1360,20 @@
 peak
-Api api
+Bootstrap ts
  = n
@@ -1388,11 +1388,17 @@
 peak
-Api
+Bootstrap
 (gro
@@ -1409,164 +1409,214 @@
 %0A%09%09%09
-Future%3CTeamspeakConnection%3E connect = api.connect(new InetSocketAddress(%22127.0.0.1%22, 10011), %22serveradmin%22, %22test1234%22);%0A%0A%09%09%09System.out.println(%22Connected!%22
+ts.login(%22serveradmin%22, %22test1234%22);%0A%09%09%09ts.selectServerID(1);%0A%09%09%09ts.clientName(%22TestingBot%22);%0A%0A%0A%09%09%09System.out.println(%22Connecting...%22);%0A%09%09%09Future%3CTeamspeakConnection%3E connect = ts.connect(%22localhost%22, 10011
 );%0A%09
@@ -1658,32 +1658,34 @@
 .sync().get();%0A%0A
+//
 %09%09%09System.out.pr
@@ -1708,24 +1708,26 @@
  server!%22);%0A
+//
 %09%09%09con.getUn
@@ -1796,28 +1796,31 @@
 intln(%22C
-reating
+onnected
 !%22);%0A
+//
 %09%09%09con.g
@@ -1831,16 +1831,18 @@
 rver();%0A
+//
 %09%09%09con.g
@@ -2113,25 +2113,29 @@
 etServer();%0A
-%0A
+//%0A//
 %09%09%09System.ou
@@ -2160,16 +2160,18 @@
 ake!%22);%0A
+//
 %09%09%09Syste
@@ -2215,17 +2215,21 @@
 get());%0A
-%0A
+//%0A//
 %09%09%09Syste
@@ -2262,24 +2262,26 @@
 ting....%22);%0A
+//
 %09%09%09con.setOw

Use new api