FriendBoard.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.communityserver.communityboard.boards;
  16. import java.util.logging.Logger;
  17. import javolution.text.TextBuilder;
  18. import com.l2jserver.communityserver.cache.HtmCache;
  19. import com.l2jserver.communityserver.communityboard.CommunityBoard;
  20. import com.l2jserver.communityserver.communityboard.CommunityBoardManager;
  21. import com.l2jserver.communityserver.model.L2Player;
  22. public final class FriendBoard extends CommunityBoard
  23. {
  24. private static Logger _log = Logger.getLogger(FriendBoard.class.getName());
  25. public FriendBoard(final CommunityBoardManager mgr)
  26. {
  27. super(mgr);
  28. }
  29. @Override
  30. public void parseCmd(final int playerObjId, final String cmd)
  31. {
  32. if (cmd.equals("_bbsfriend"))
  33. showMainPage(playerObjId, false);
  34. else if (cmd.split(";")[1].equalsIgnoreCase("mail"))
  35. {
  36. showMailWrite(playerObjId);
  37. }
  38. else if (cmd.split(";")[1].equalsIgnoreCase("select"))
  39. {
  40. L2Player player = super.getCommunityBoardManager().getPlayer(playerObjId);
  41. Integer friendId = Integer.valueOf(cmd.split(";")[2]);
  42. if (!player.getSelectedFriendsList().contains(friendId))
  43. player.selectFriend(friendId);
  44. showMainPage(playerObjId, false);
  45. }
  46. else if (cmd.split(";")[1].equalsIgnoreCase("deselect"))
  47. {
  48. L2Player player = super.getCommunityBoardManager().getPlayer(playerObjId);
  49. player.deSelectFriend(Integer.valueOf(cmd.split(";")[2]));
  50. showMainPage(playerObjId, false);
  51. }
  52. else if (cmd.split(";")[1].equalsIgnoreCase("delconfirm"))
  53. {
  54. showMainPage(playerObjId, true);
  55. }
  56. else
  57. _log.info("Friend command missing: " + cmd.split(";")[1]);
  58. }
  59. public final void showMainPage(final int playerObjId, boolean delMsg)
  60. {
  61. String content = HtmCache.getInstance().getHtm("data/staticfiles/html/friend.htm");
  62. TextBuilder fList = new TextBuilder();
  63. L2Player player = super.getCommunityBoardManager().getPlayer(playerObjId);
  64. for (int f:player.getFriendList())
  65. {
  66. L2Player friend = super.getCommunityBoardManager().getPlayer(f);
  67. fList.append("<a action=\"bypass _bbsfriend;select;" + friend.getObjId() + "\">" + friend.getName() + "</a> (" + (friend.isOnline() ? "On":"Off") + ") &nbsp;");
  68. }
  69. content = content.replaceAll("%friendslist%", fList.toString());
  70. fList.clear();
  71. for (int f:player.getSelectedFriendsList())
  72. {
  73. L2Player friend = super.getCommunityBoardManager().getPlayer(f);
  74. fList.append("<a action=\"bypass _bbsfriend;deselect;" + friend.getObjId() + "\">" + friend.getName() + "</a>;");
  75. }
  76. content = content.replaceAll("%selectedFriendsList%", fList.toString());
  77. if (delMsg)
  78. content = content.replaceAll("%deleteMSG%", "<br>\nAre you sure you want to delete all messages from your Friends List? <button value = \"OK\" action=\"bypass _bssfriend;delall\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
  79. else
  80. content = content.replaceAll("%deleteMSG%", "");
  81. super.send(playerObjId, content);
  82. }
  83. public final void showMailWrite(final int playerObjId)
  84. {
  85. String title = " ";
  86. String message = " ";
  87. String content = HtmCache.getInstance().getHtm("data/staticfiles/html/mail-write.htm");
  88. content = content.replaceAll("%maillink%", "<a action=\"bypass _bbsfriend\">&\\$904;</a> > &\\$915;");
  89. content = content.replaceAll("%playerObjId%", String.valueOf(playerObjId));
  90. content = content.replaceAll("%postId%", "-1");
  91. String toList = "";
  92. L2Player player = super.getCommunityBoardManager().getPlayer(playerObjId);
  93. for (int f:player.getSelectedFriendsList())
  94. {
  95. if (toList.equals(""))
  96. toList += super.getCommunityBoardManager().getPlayer(f).getName();
  97. else
  98. toList += (";" + super.getCommunityBoardManager().getPlayer(f).getName());
  99. }
  100. super.sendWrite(playerObjId, content, message, title, toList);
  101. }
  102. @Override
  103. public final void parseWrite(final int playerObjId, final String ar1, final String ar2, final String ar3, final String ar4, final String ar5)
  104. {
  105. }
  106. }