Advertisement
AcaciaX9

Pvp Rank Board

Mar 23rd, 2023 (edited)
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.47 KB | Gaming | 0 0
  1. /*
  2. * This file is part of the L2J Mobius project.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package handlers.communityboard;
  18.  
  19. import org.l2jmobius.commons.database.DatabaseFactory;
  20. import org.l2jmobius.commons.threads.ThreadPool;
  21. import org.l2jmobius.commons.util.StringUtil;
  22. import org.l2jmobius.gameserver.data.sql.ClanTable;
  23. import org.l2jmobius.gameserver.enums.ClassId;
  24. import org.l2jmobius.gameserver.handler.CommunityBoardHandler;
  25. import org.l2jmobius.gameserver.handler.IParseBoardHandler;
  26. import org.l2jmobius.gameserver.model.actor.Player;
  27. import org.l2jmobius.gameserver.model.clan.Clan;
  28. import org.l2jmobius.gameserver.network.serverpackets.ShowBoard;
  29.  
  30. import java.sql.Connection;
  31. import java.sql.PreparedStatement;
  32. import java.sql.ResultSet;
  33.  
  34. /**
  35. * @author Acacia
  36. */
  37. public class PvpBoard implements IParseBoardHandler
  38. {
  39. Player _player = null;
  40. protected static StringBuilder _pvpHTML = null;
  41. protected static StringBuilder _fameHTML = null;
  42. protected static StringBuilder _pkHTML = null;
  43. protected static StringBuilder _onlineHTML = null;
  44. private static final String LOAD_PVP_HTML = "SELECT * FROM characters WHERE accesslevel=0 ORDER BY pvpkills DESC LIMIT 0, 25";
  45. private static final String LOAD_FAME_HTML = "SELECT * FROM characters WHERE accesslevel=0 ORDER BY fame DESC LIMIT 0, 25";
  46. private static final String LOAD_PK_HTML = "SELECT * FROM characters WHERE accesslevel=0 ORDER BY pkkills DESC LIMIT 0, 25";
  47. private static final String LOAD_ONLINE_HTML = "SELECT * FROM characters WHERE accesslevel=0 ORDER BY online DESC LIMIT 0, 25";
  48.  
  49. private static final String[] COMMANDS =
  50. {
  51. "_bbspvp",
  52. "_bbsfame",
  53. "_bbsgetfav",
  54. "_bbspk",
  55. "_bbsonline"
  56. };
  57.  
  58. @Override
  59. public boolean parseCommunityBoardCommand(String command, Player player)
  60. {
  61.  
  62. _player = player;
  63.  
  64. if (command.startsWith("_bbspvp") || command.startsWith("_bbsgetfav"))
  65. {
  66.  
  67. String html = _pvpHTML.toString();
  68. html = html.replace("%PvP%", "PvP");
  69. html = html.replace("%Fame%", "<a action=\"bypass _bbsfame\">Fame</a>");
  70. html = html.replace("%PK%", "<a action=\"bypass _bbspk\">PK</a>");
  71. html = html.replace("%ONLINE%", "<a action=\"bypass _bbsonline\">Online</a>");
  72.  
  73. CommunityBoardHandler.separateAndSend(html, player);
  74. }
  75. else if (command.startsWith("_bbsfame"))
  76. {
  77.  
  78. String html = _fameHTML.toString();
  79. html = html.replace("%PvP%", "<a action=\"bypass _bbspvp\">PvP</a>");
  80. html = html.replace("%Fame%", "Fame");
  81. html = html.replace("%PK%", "<a action=\"bypass _bbspk\">PK</a>");
  82. html = html.replace("%ONLINE%", "<a action=\"bypass _bbsonline\">Online</a>");
  83.  
  84. CommunityBoardHandler.separateAndSend(html, player);
  85. }
  86. else if (command.startsWith("_bbspk"))
  87. {
  88.  
  89. String html = _pkHTML.toString();
  90. html = html.replace("%PvP%", "<a action=\"bypass _bbspvp\">PvP</a>");
  91. html = html.replace("%Fame%", "<a action=\"bypass _bbsfame\">Fame</a>");
  92. html = html.replace("%PK%", "PK");
  93. html = html.replace("%ONLINE%", "<a action=\"bypass _bbsonline\">Online</a>");
  94.  
  95. CommunityBoardHandler.separateAndSend(html, player);
  96. }
  97. else if (command.startsWith("_bbsonline"))
  98. {
  99.  
  100. String html = _onlineHTML.toString();
  101. html = html.replace("%PvP%", "<a action=\"bypass _bbspvp\">PvP</a>");
  102. html = html.replace("%Fame%", "<a action=\"bypass _bbsfame\">Fame</a>");
  103. html = html.replace("%PK%", "<a action=\"bypass _bbspk\">PK</a>");
  104. html = html.replace("%ONLINE%", "Online");
  105.  
  106. CommunityBoardHandler.separateAndSend(html, player);
  107. }
  108.  
  109. else
  110. {
  111. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + command + " is not implemented yet</center><br><br></body></html>", "101");
  112. player.sendPacket(sb);
  113.  
  114. }
  115. return false;
  116. }
  117.  
  118. @Override
  119. public String[] getCommunityBoardCommands()
  120. {
  121. return COMMANDS;
  122. }
  123.  
  124. @SuppressWarnings("null")
  125. public void loadHTML(int whichone)
  126. {
  127. final StringBuilder HTML = StringUtil.startAppend(1000, "");
  128.  
  129. String info = null;
  130. switch (whichone)
  131. {
  132. default:
  133. info = "Top PvPers of the server (updated every 5 minutes)";
  134. break;
  135. case 1:
  136. info = "Most famous people of the server (updated every 5 minutes)";
  137. break;
  138. case 2:
  139. info = "The most \"hardcore\" players (updated every 5 minutes)";
  140. break;
  141. case 3:
  142. info = "Online List (updated every 5 minutes)";
  143. break;
  144. }
  145.  
  146. HTML.append("<html><title>" + info + "</title><body><br><center><table width=\"100%\">");
  147.  
  148. HTML.append("<tr>");
  149.  
  150. HTML.append("<td><font color=\"LEVEL\">Player Name</font></td>");
  151. HTML.append("<td><font color=\"LEVEL\">Player Title</font></td>");
  152. HTML.append("<td><font color=\"LEVEL\">Base Class</font></td>");
  153. HTML.append("<td><font color=\"LEVEL\">%ONLINE%</font></td>");
  154. HTML.append("<td><font color=\"LEVEL\">Clan</font></td>");
  155.  
  156. HTML.append("<td><font color=\"LEVEL\">%Fame%</font></td>");
  157. HTML.append("<td><font color=\"LEVEL\">%PvP%</font></td>");
  158. HTML.append("<td><font color=\"LEVEL\">%PK%</font></td>");
  159.  
  160. HTML.append("</tr>");
  161.  
  162. PreparedStatement statement;
  163. ResultSet rs;
  164. Connection con = null;
  165. try
  166. {
  167. con = DatabaseFactory.getConnection();
  168.  
  169. switch (whichone)
  170. {
  171. default:
  172. statement = con.prepareStatement(LOAD_PVP_HTML);
  173. break;
  174. case 1:
  175. statement = con.prepareStatement(LOAD_FAME_HTML);
  176. break;
  177. case 2:
  178. statement = con.prepareStatement(LOAD_PK_HTML);
  179. break;
  180. case 3:
  181. statement = con.prepareStatement(LOAD_ONLINE_HTML);
  182. break;
  183. }
  184.  
  185. boolean lol = true;
  186. String color = "FFF8C6";
  187. String colorName = "bdccd4";
  188. String colorClass = "bdccd4";
  189. String colorOnline = "bdccd4";
  190. String colorPvPs = "bdccd4";
  191. String colorFame = "686868";
  192.  
  193. rs = statement.executeQuery();
  194.  
  195. while (rs.next())
  196. {
  197. String name = rs.getString("char_name");
  198. String title = rs.getString("title");
  199. if (title == null)
  200. {
  201. title = "";
  202. }
  203. title = title.replaceAll("<", "&lt;");
  204. title = title.replaceAll(">", "&gt;");
  205.  
  206. String fame = String.valueOf(rs.getInt("fame"));
  207. String pvps = String.valueOf(rs.getInt("pvpkills"));
  208. String pks = String.valueOf(rs.getInt("pkkills"));
  209.  
  210. ClassId baseclass = ClassId.getClassId(rs.getInt("base_class"));
  211. boolean online = Boolean.parseBoolean(String.valueOf(rs.getBoolean("online")));
  212.  
  213. if(rs.getBoolean("online"))
  214. {
  215. colorName = "379d2d";
  216. colorClass = "916e27";
  217. colorOnline = "379d2d";
  218. colorPvPs = "8c4848";
  219. colorFame = "744ccf";
  220. }
  221. else {
  222. colorName = "bdccd4";
  223. colorClass = "bdccd4";
  224. colorOnline = "bdccd4";
  225. colorPvPs = "bdccd4";
  226. colorFame = "686868";
  227. }
  228.  
  229. if(rs.getBoolean("online"))
  230. name = "<font color="+colorName+">"+name+"</font>";
  231.  
  232. Clan clan = ClanTable.getInstance().getClan(rs.getInt("clanid"));
  233. String clanname = "-";
  234. if (clan != null)
  235. {
  236. clanname = clan.getName() + " (Lvl " + clan.getLevel() + ")";
  237. }
  238.  
  239. HTML.append("<tr>");
  240. HTML.append("<td><font color=" + colorName + ">" + name + "</font></td>");
  241. HTML.append("<td><font color=" + color + ">" + title + "</font></td>");
  242. HTML.append("<td><font color=" + colorClass + ">" + baseclass + "</font></td>");
  243. HTML.append("<td><font color=" + colorOnline + ">" + online + "</font></td>");
  244. HTML.append("<td><font color=" + color + ">" + clanname + "</font></td>");
  245.  
  246. HTML.append("<td><font color=" + colorFame + ">" + fame + "</font></td>");
  247. HTML.append("<td><font color=" + colorPvPs + ">" + pvps + "</font></td>");
  248. HTML.append("<td><font color=" + color + ">" + pks + "</font></td>");
  249. HTML.append("</tr>");
  250.  
  251. if (lol)
  252. {
  253. lol = false;
  254. color = "817679";
  255. }
  256. else
  257. {
  258. lol = true;
  259. color = "FFF8C6";
  260. }
  261. }
  262.  
  263. rs.close();
  264. statement.close();
  265. }
  266. catch (Exception e)
  267. {
  268. e.printStackTrace();
  269. }
  270. finally
  271. {
  272. try
  273. {
  274. con.close();
  275. }
  276. catch (Exception e)
  277. {
  278. }
  279.  
  280. HTML.append("</table></center><br></body></html>");
  281. }
  282.  
  283. switch (whichone)
  284. {
  285. default:
  286. _pvpHTML = HTML;
  287. break;
  288. case 1:
  289. _fameHTML = HTML;
  290. break;
  291. case 2:
  292. _pkHTML = HTML;
  293. break;
  294. case 3:
  295. _onlineHTML = HTML;
  296. break;
  297.  
  298. }
  299. }
  300.  
  301. public PvpBoard() {
  302. ThreadPool.scheduleAtFixedRate(new Start(), 0 ,10000); //5 minutes
  303. }
  304.  
  305. class Start implements Runnable
  306. {
  307. @Override
  308. public void run()
  309. {
  310. loadHTML(0);
  311. loadHTML(1);
  312. loadHTML(2);
  313. loadHTML(3);
  314. }
  315. }
  316.  
  317. public static PvpBoard getInstance()
  318. {
  319. return PvpBoard.SingletonHolder.INSTANCE;
  320. }
  321.  
  322. private static class SingletonHolder
  323. {
  324. protected static final PvpBoard INSTANCE = new PvpBoard();
  325. }
  326. }
  327.  
  328.  
  329.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement