Advertisement
Nik

New useful utils.

Nik
Jul 24th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.63 KB | None | 0 0
  1. Index: Util.java
  2. ===================================================================
  3. --- Util.java   (revision 5522)
  4. +++ Util.java   (working copy)
  5. @@ -18,14 +18,18 @@
  6.  import java.text.DateFormat;
  7.  import java.text.SimpleDateFormat;
  8.  import java.util.Date;
  9. +import java.util.List;
  10.  
  11.  import javolution.text.TextBuilder;
  12. +import javolution.util.FastList;
  13.  
  14.  import com.l2jserver.Config;
  15.  import com.l2jserver.gameserver.ThreadPoolManager;
  16.  import com.l2jserver.gameserver.model.L2Object;
  17.  import com.l2jserver.gameserver.model.actor.L2Character;
  18.  import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  20. +import com.l2jserver.gameserver.network.serverpackets.ShowBoard;
  21.  import com.l2jserver.util.file.filter.ExtFilter;
  22.  
  23.  /**
  24. @@ -472,4 +476,106 @@
  25.         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  26.         return dateFormat.format(date.getTime());
  27.     }
  28. +  
  29. +   /**
  30. +    * Sends the given html to the player.
  31. +    * @param activeChar
  32. +    * @param html
  33. +    */
  34. +   public static void sendHtml(L2PcInstance activeChar, String html)
  35. +   {
  36. +       NpcHtmlMessage npcHtml = new NpcHtmlMessage(0);
  37. +       npcHtml.setHtml(html);
  38. +       activeChar.sendPacket(npcHtml);
  39. +   }
  40. +  
  41. +   /**
  42. +    * Sends the html using the community board window.
  43. +    * @param activeChar
  44. +    * @param html
  45. +    */
  46. +   public static void sendCBHtml(L2PcInstance activeChar, String html)
  47. +   {
  48. +       sendCBHtml(activeChar, html, "");
  49. +   }
  50. +  
  51. +   /**
  52. +    * Sends the html using the community board window.
  53. +    * @param activeChar
  54. +    * @param html
  55. +    * @param fillMultiEdit fills the multiedit window (if any) inside the community board.
  56. +    */
  57. +   public static void sendCBHtml(L2PcInstance activeChar, String html, String fillMultiEdit)
  58. +   {
  59. +       if (activeChar == null)
  60. +           return;
  61. +      
  62. +       if (html != null)
  63. +       {
  64. +           activeChar.clearBypass();
  65. +           int len = html.length();
  66. +           for (int i = 0; i < len; i++)
  67. +           {
  68. +               int start = html.indexOf("\"bypass ", i);
  69. +               int finish = html.indexOf("\"", start + 1);
  70. +               if (start < 0 || finish < 0)
  71. +                   break;
  72. +              
  73. +               if (html.substring(start + 8, start + 10).equals("-h"))
  74. +                   start += 11;
  75. +               else
  76. +                   start += 8;
  77. +              
  78. +               i = finish;
  79. +               int finish2 = html.indexOf("$", start);
  80. +               if (finish2 < finish && finish2 > 0)
  81. +                   activeChar.addBypass2(html.substring(start, finish2).trim());
  82. +               else
  83. +                   activeChar.addBypass(html.substring(start, finish).trim());
  84. +           }
  85. +       }
  86. +      
  87. +       if (fillMultiEdit != null)
  88. +       {
  89. +           activeChar.sendPacket(new ShowBoard(html, "1001"));
  90. +           fillMultiEditContent(activeChar, fillMultiEdit);
  91. +       }
  92. +       else
  93. +       {
  94. +           activeChar.sendPacket(new ShowBoard(null, "101"));
  95. +           activeChar.sendPacket(new ShowBoard(html, "101"));
  96. +           activeChar.sendPacket(new ShowBoard(null, "102"));
  97. +           activeChar.sendPacket(new ShowBoard(null, "103"));
  98. +       }
  99. +   }
  100. +  
  101. +   /**
  102. +   *
  103. +   * Fills the community board's multiedit window with text. Must send after sendCBHtml
  104. +   * @param activeChar
  105. +   * @param text
  106. +   */
  107. +   public static void fillMultiEditContent(L2PcInstance activeChar, String text)
  108. +   {
  109. +       text = text.replaceAll("<br>", "\n");
  110. +       List<String> _arg = new FastList<>();
  111. +       _arg.add("0");
  112. +       _arg.add("0");
  113. +       _arg.add("0");
  114. +       _arg.add("0");
  115. +       _arg.add("0");
  116. +       _arg.add("0");
  117. +       _arg.add(activeChar.getName());
  118. +       _arg.add(Integer.toString(activeChar.getObjectId()));
  119. +       _arg.add(activeChar.getAccountName());
  120. +       _arg.add("9");
  121. +       _arg.add(" ");
  122. +       _arg.add(" ");
  123. +       _arg.add(text);
  124. +       _arg.add("0");
  125. +       _arg.add("0");
  126. +       _arg.add("0");
  127. +       _arg.add("0");
  128. +       activeChar.sendPacket(new ShowBoard(_arg));
  129. +   }
  130.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement