package nl.tomudding.plugins.visibility.managers;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import nl.tomudding.plugins.visibility.Visibility;

public class ChatManager {
	private static ChatManager instance = new ChatManager();

	public static ChatManager getInstance() {
		return instance;
	}

	public void log(String s) {
		Bukkit.getConsoleSender().sendMessage(ChatColor.BLUE + "Player Visibility >> " + ChatColor.translateAlternateColorCodes('&', s));
	}

	public void sendMessage(Player player, String s) {
		player.sendMessage(ChatColor.translateAlternateColorCodes('&', Visibility.messagePrefix + s));
	}
	
	public void sendCommandMessage(Player player, String s) {
		player.sendMessage(ChatColor.translateAlternateColorCodes('&', s));
	}
}

@@ -340,226 +340,1760 @@
 %0A%09%7D%0A
-%0A%09public void log(String s) %7B%0A%09%09Bukkit.getConsoleSender().sendMessage(ChatColor.BLUE + %22Player Visibility %3E%3E %22 + ChatColor.translateAlternateColorCodes('&', s));%0A%09%7D%0A%0A%09public void sendMessage(Player player, String s) %7B%0A
+%09%0A%09private Class%3C?%3E getNMSClass(String nmsClassName) throws ClassNotFoundException %7B%0A%09%09%09return Class.forName(%22net.minecraft.server.%22 + Bukkit.getServer().getClass().getPackage().getName().replace(%22.%22, %22,%22).split(%22,%22)%5B3%5D + %22.%22 + nmsClassName);%0A%09%7D%0A%0A%09public void log(String s) %7B%0A%09%09Bukkit.getConsoleSender().sendMessage(ChatColor.BLUE + %22Player Visibility %3E%3E %22 + ChatColor.translateAlternateColorCodes('&', s));%0A%09%7D%0A%0A%09public void sendMessage(Player player, String message) %7B%0A%09%09if (Visibility.actionBar) %7B%0A%09%09%09try %7B%0A%09%09%09%09if ((Visibility.getServerVersion().equalsIgnoreCase(%22v1_9_R1%22)) %7C%7C (Visibility.getServerVersion().equalsIgnoreCase(%22v1_9_R2%22)) %7C%7C (Visibility.getServerVersion().equalsIgnoreCase(%22v1_10_R1%22))) %7B%0A%09%09%09%09%09// if the server does not use this version it should have been disabled%0A%09%09%09%09%09Object chatComponentText = getNMSClass(%22ChatComponentText%22).getConstructor(new Class%5B%5D %7B String.class %7D).newInstance(new Object%5B%5D %7B ChatColor.translateAlternateColorCodes('&', message)%7D);%0A%09%09%09%09%09Class%3C?%3E iChatBaseComponent = getNMSClass(%22IChatBaseComponent%22);%0A%09%09%09%09%09Object packetPlayOutChat = getNMSClass(%22PacketPlayOutChat%22).getConstructor(new Class%5B%5D %7B iChatBaseComponent, Byte.TYPE %7D).newInstance(new Object%5B%5D %7B chatComponentText, Byte.valueOf((byte) 2) %7D);%0A%09%09%09%09%09%0A%09%09%09%09%09Object playerNMS = player.getClass().getMethod(%22getHandle%22, new Class%5B0%5D).invoke(player, new Object%5B0%5D);%0A%09%09%09%09%09Object playerConnection = playerNMS.getClass().getField(%22playerConnection%22).get(playerNMS);%0A%09%09%09%09%09Class%3C?%3E playerPacket = getNMSClass(%22Packet%22);%0A%09%09%09%09%09playerConnection.getClass().getMethod(%22sendPacket%22, new Class%5B%5D %7B playerPacket %7D).invoke(playerConnection, new Object%5B%5D %7B packetPlayOutChat %7D);%0A%09%09%09%09%7D%0A%09%09%09%7D catch (Exception exception) %7B%0A%09%09%09%09exception.printStackTrace();%0A%09%09%09%7D%0A%09%09%7D else %7B%0A%09
 %09%09pl
@@ -2180,20 +2180,30 @@
 refix + 
-s));
+message));%0A%09%09%7D
 %0A%09%7D%0A%09%0A%09p
@@ -2250,25 +2250,31 @@
 yer, String 
-s
+message
 ) %7B%0A%09%09player
@@ -2326,22 +2326,28 @@
 rCodes('&', 
-s
+message
 ));%0A%09%7D%0A%7D%0A

Update ChatManager.java to v2.2