Example #1
0
 private void send(CommandSender sender, String jsonString) {
   if (!(sender instanceof Player)) {
     sender.sendMessage(toOldMessageFormat());
     return;
   }
   Player player = (Player) sender;
   try {
     Object handle = Reflection.getHandle(player);
     Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
     Reflection.getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet"))
         .invoke(connection, createChatPacket(jsonString));
   } catch (IllegalArgumentException e) {
     Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
   } catch (IllegalAccessException e) {
     Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
   } catch (InstantiationException e) {
     Bukkit.getLogger().log(Level.WARNING, "Underlying class is abstract.", e);
   } catch (InvocationTargetException e) {
     Bukkit.getLogger().log(Level.WARNING, "A error has occured durring invoking of method.", e);
   } catch (NoSuchMethodException e) {
     Bukkit.getLogger().log(Level.WARNING, "Could not find method.", e);
   } catch (ClassNotFoundException e) {
     Bukkit.getLogger().log(Level.WARNING, "Could not find class.", e);
   }
 }
 /**
  * Sends this message to a player. The player will receive the fully-fledged formatted display of
  * this message.
  *
  * @param player The player who will receive the message.
  */
 public void send(Player player) {
   try {
     Object handle = Reflection.getHandle(player);
     Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
     Reflection.getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet"))
         .invoke(connection, createChatPacket(Message.Colorize(toJSONString())));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }