package pl.luxdev.lol.basic;

import java.lang.reflect.Field;

import org.bukkit.entity.Player;

import pl.luxdev.lol.utils.PacketUtils;
import pl.luxdev.lol.utils.Reflection;

public class TabTitle {

	
	private Class<?> ChatSerializer = Reflection.getCraftClass("IChatBaseComponent$ChatSerializer");
	private Class<?> headerfooter = Reflection.getCraftClass("PacketPlayOutPlayerListHeaderFooter");
	private Field header;
	private Field footer;

	public TabTitle(String h){
		Class<?> headerfooter = Reflection.getCraftClass("PacketPlayOutPlayerListHeaderFooter");
		try {
			header = headerfooter.getDeclaredField("a");
			footer = headerfooter.getDeclaredField("b");
		} catch (Exception e) {
			e.printStackTrace();
		}
		header.setAccessible(true);
	    footer.setAccessible(true);
	    setHeader(h);
	}
	
	public TabTitle(String h, String f){
		this(h);
	    setFooter(f);
	}
	
	public void setHeader(String s){
		try {
			header.set(headerfooter, ChatSerializer.getMethod("a").invoke(s));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void setFooter(String s){
		try {
			footer.set(headerfooter, ChatSerializer.getMethod("a").invoke(s));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void send(Player p){
		PacketUtils.sendPacket(p, headerfooter);
	}
}
@@ -23,16 +23,54 @@
 basic;%0A%0A
+import java.lang.reflect.Constructor;%0A
 import j
@@ -233,18 +233,16 @@
 itle %7B%0A%0A
-%09%0A
 %09private
@@ -234,32 +234,39 @@
 tle %7B%0A%0A%09private 
+static 
 Class%3C?%3E ChatSer
@@ -323,23 +323,8 @@
 nent
-$ChatSerializer
 %22);%0A
@@ -332,16 +332,23 @@
 private 
+static 
 Class%3C?%3E
@@ -432,173 +432,77 @@
 %22);%0A
+%0A
 %09p
-rivate Field header;%0A%09private Field footer;%0A%0A%09public TabTitle(String h)%7B%0A%09%09Class%3C?%3E headerfooter = Reflection.getCraftClass(%22PacketPlayOutPlayerListHeaderFooter%22);
+ublic static void sendHeaderFooter(String h, String f, Player p) %7B
 %0A%09%09t
@@ -505,24 +505,31 @@
 %0A%09%09try %7B%0A%09%09%09
+Object 
 header = hea
@@ -521,34 +521,36 @@
 ct header = 
-headerfoot
+ChatSerializ
 er.getDeclar
@@ -555,696 +555,560 @@
 ared
-Field(%22a%22);%0A%09%09%09footer = headerfooter.getDeclaredField(%22b%22);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09header.setAccessible(true);%0A%09    footer.setAccessible(true);%0A%09    setHeader(h);%0A%09%7D%0A%09%0A%09public TabTitle(String h, String f)%7B%0A%09%09this(h);%0A%09    setFooter(f);%0A%09%7D%0A%09%0A%09public void setHeader(String s)%7B%0A%09%09try %7B%0A%09%09%09header.set(headerfooter, ChatSerializer.getMethod(%22a%22).invoke(s));%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%7D%0A%09%0A%09public void setFooter(String s)%7B%0A%09%09try %7B%0A%09%09%09footer.set(headerfooter, ChatSerializer.getMethod(%22a%22).invoke(s));%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%7D%0A%09%0A%09public void send(Player p)%7B%0A%09%09PacketUtils.sendPacket(p, headerfooter);%0A%09
+Classes()%5B0%5D.getMethod(%22a%22, String.class).invoke(null, %22%7B%5C%22text%5C%22:%5C%22%22 + h + %22%5C%22%7D%22);%0A%09%09%09Object footer = ChatSerializer.getDeclaredClasses()%5B0%5D.getMethod(%22a%22, String.class).invoke(null, %22%7B%5C%22text%5C%22:%5C%22%22 + f + %22%5C%22%7D%22);%0A%09%09%09Constructor%3C?%3E contrustor = headerfooter.getConstructor(ChatSerializer);%0A%09%09%09Object packet = contrustor.newInstance(header);%0A%09%09%09Field field = packet.getClass().getDeclaredField(%22b%22);%0A%09%09%09field.setAccessible(true);%0A%09%09%09field.set(packet, footer);;%0A%09%09%09PacketUtils.sendPacket(p, packet);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%7D%0A
 %7D%0A
-%7D

Update TabTitle.java (Jeszcze to zmienie całkowicie)