content: package us.ajg0702.queue.spigot.utils;
  
  import org.bukkit.Bukkit;
  import org.bukkit.entity.Player;
  
  import java.lang.reflect.Field;
  import java.lang.reflect.Method;
  
  /**
   * A cross-version actionbar class
   * @author Based on ActionBarAPI from <a href="https://github.com/ConnorLinfoot">ConnorLinfoot</a>
   *
   */
  public class ActionBar {
  
      public static void send(Player player, String message) {
  		if(player == null) return;
  		if(!player.isOnline()) return;
  
          String version = Bukkit.getServer().getClass().getPackage().getName();
          version = version.substring(version.lastIndexOf(".") + 1);
  
          boolean old = version.equalsIgnoreCase("v1_8_R1") || version.startsWith("v1_7_");
  		
  		try {
              Class<?> craftPlayerClass = Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftPlayer");
              Object craftPlayer = craftPlayerClass.cast(player);
              Object packet;
              Class<?> packetPlayOutChatClass = Class.forName("net.minecraft.server." + version + ".PacketPlayOutChat");
              Class<?> packetClass = Class.forName("net.minecraft.server." + version + ".Packet");
              if (old) {
                  Class<?> chatSerializerClass = Class.forName("net.minecraft.server." + version + ".ChatSerializer");
                  Class<?> iChatBaseComponentClass = Class.forName("net.minecraft.server." + version + ".IChatBaseComponent");
                  Method m3 = chatSerializerClass.getDeclaredMethod("a", String.class);
                  Object cbc = iChatBaseComponentClass.cast(m3.invoke(chatSerializerClass, "{\"text\": \"" + message + "\"}"));
                  packet = packetPlayOutChatClass.getConstructor(new Class<?>[]{iChatBaseComponentClass, byte.class}).newInstance(cbc, (byte) 2);
              } else {
                  Class<?> chatComponentTextClass = Class.forName("net.minecraft.server." + version + ".ChatComponentText");
                  Class<?> iChatBaseComponentClass = Class.forName("net.minecraft.server." + version + ".IChatBaseComponent");
                  try {
                      Class<?> chatMessageTypeClass = Class.forName("net.minecraft.server." + version + ".ChatMessageType");
                      Object[] chatMessageTypes = chatMessageTypeClass.getEnumConstants();
                      Object chatMessageType = null;
                      for (Object o : chatMessageTypes) {
                          if (o.toString().equals("GAME_INFO")) {
                              chatMessageType = o;
                          }
                      }
                      Object chatCompontentText = chatComponentTextClass.getConstructor(new Class<?>[]{String.class}).newInstance(message);
                      packet = packetPlayOutChatClass.getConstructor(new Class<?>[]{iChatBaseComponentClass, chatMessageTypeClass}).newInstance(chatCompontentText, chatMessageType);
                  } catch (ClassNotFoundException e) {
                      Object chatCompontentText = chatComponentTextClass.getConstructor(new Class<?>[]{String.class}).newInstance(message);
                      packet = packetPlayOutChatClass.getConstructor(new Class<?>[]{iChatBaseComponentClass, byte.class}).newInstance(chatCompontentText, (byte) 2);
                  }
              }
              Method craftPlayerHandleMethod = craftPlayerClass.getDeclaredMethod("getHandle");
              Object craftPlayerHandle = craftPlayerHandleMethod.invoke(craftPlayer);
              Field playerConnectionField = craftPlayerHandle.getClass().getDeclaredField("playerConnection");
              Object playerConnection = playerConnectionField.get(craftPlayerHandle);
              Method sendPacketMethod = playerConnection.getClass().getDeclaredMethod("sendPacket", packetClass);
              sendPacketMethod.invoke(playerConnection, packet);
              
  		} catch (Exception e) {
  			e.printStackTrace();
  		}
  	}
  	
  }