Guest User

Pvp/pk Item

a guest
Jun 17th, 2011
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.41 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2JServer
  3. Index: java/com/l2jserver/gameserver/network/clientpackets/RequestBypassToServer.java
  4. ===================================================================
  5. --- java/com/l2jserver/gameserver/network/clientpackets/RequestBypassToServer.java (revision 51)
  6. +++ java/com/l2jserver/gameserver/network/clientpackets/RequestBypassToServer.java (working copy)
  7. @@ -33,7 +34,11 @@
  8. import com.l2jserver.gameserver.model.actor.instance.L2MerchantSummonInstance;
  9. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  10. import com.l2jserver.gameserver.model.entity.Hero;
  11. import com.l2jserver.gameserver.model.entity.L2Event;
  12. +import com.l2jserver.gameserver.model.entity.PvpPkList;
  13. import com.l2jserver.gameserver.network.SystemMessageId;
  14. import com.l2jserver.gameserver.network.communityserver.CommunityServerThread;
  15. import com.l2jserver.gameserver.network.communityserver.writepackets.RequestShowCommunityBoard;
  16. @@ -169,6 +180,10 @@
  17. }
  18. catch (NumberFormatException nfe) {}
  19. }
  20. + else if (_command.startsWith("pvpItem")){
  21. + PvpPkList list = new PvpPkList();
  22. + list.convert(activeChar,_command.substring(8));
  23. + }
  24. // Navigate through Manor windows
  25. else if (_command.startsWith("manor_menu_select"))
  26. {
  27. Index: java/com/l2jserver/gameserver/model/entity/PvpPkList.java
  28. ===================================================================
  29. --- java/com/l2jserver/gameserver/model/entity/PvpPkList.java (revision 0)
  30. +++ java/com/l2jserver/gameserver/model/entity/PvpPkList.java (revision 0)
  31. @@ -0,0 +1,154 @@
  32. +/*
  33. + * This program is free software: you can redistribute it and/or modify it under
  34. + * the terms of the GNU General Public License as published by the Free Software
  35. + * Foundation, either version 3 of the License, or (at your option) any later
  36. + * version.
  37. + *
  38. + * This program is distributed in the hope that it will be useful, but WITHOUT
  39. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  40. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  41. + * details.
  42. + *
  43. + * You should have received a copy of the GNU General Public License along with
  44. + * this program. If not, see <http://www.gnu.org/licenses/>.
  45. + */
  46. +package com.l2jserver.gameserver.model.entity;
  47. +
  48. +import java.sql.Connection;
  49. +import java.sql.PreparedStatement;
  50. +import java.sql.ResultSet;
  51. +import java.util.StringTokenizer;
  52. +
  53. +import com.l2jserver.L2DatabaseFactory;
  54. +import com.l2jserver.gameserver.model.L2World;
  55. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  56. +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  57. +import com.l2jserver.util.StringUtil;
  58. +
  59. +/**
  60. + * @author FighterBoss
  61. + *
  62. + */
  63. +public class PvpPkList
  64. +{
  65. + private int allPages = 1;
  66. + private int howMayPerPage = 2;
  67. + public void showUsTheFuture(L2PcInstance activeChar, boolean pvp, int page, String name){
  68. + String bad = "Pk";
  69. + String good = "Pk";
  70. + if(!pvp)
  71. + bad = "Pvp";
  72. + else
  73. + good = "Pvp";
  74. + NpcHtmlMessage adminReply = new NpcHtmlMessage(10);
  75. + final StringBuilder replyMSG = StringUtil.startAppend(
  76. + 1000,
  77. + "<html><head><title>PvP/PK List</title></head><body>",
  78. + "<center>Top "+ good +" List<br>",
  79. + "<button value=\""+ bad +" List\" action=\"bypass -h pvpItem "+ bad.subSequence(0, 2) +" \" width=65 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">",
  80. + "</center><br><table width=300><tr><td>Nr.</td><td width=80>Name</td><td>"+ good +" Points</td><td>Online</td></tr>",
  81. + getList(pvp,page,name),
  82. + "</table>",
  83. + "<br><table><tr><td><edit var=\"name\" width=120 height=15></td><td>",
  84. + "<button value=\"Search\" action=\"bypass -h pvpItem "+ bad.subSequence(0, 2) +" 1 $name \" width=65 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">",
  85. + "</td></tr></table><br><center>",
  86. + getPages(page,pvp),
  87. + "</center></html></body>"
  88. + );
  89. +
  90. + adminReply.setHtml(replyMSG.toString());
  91. + activeChar.sendPacket(adminReply);
  92. + }
  93. +
  94. + public void convert(L2PcInstance activeChar, String text)
  95. + {
  96. + boolean pvp = true;
  97. + int page = 1;
  98. + String name = "";
  99. + StringTokenizer st = new StringTokenizer(text);
  100. + if(st.nextToken().equals("Pk"))
  101. + pvp = false;
  102. + if(st.hasMoreTokens())
  103. + page = Integer.parseInt(st.nextToken());
  104. + if(st.hasMoreTokens())
  105. + name = st.nextToken();;
  106. + showUsTheFuture(activeChar,pvp,page,name);
  107. + }
  108. +
  109. + private String getPages(int page, boolean pvp)
  110. + {
  111. + String text = "<table><tr>";
  112. + String pvpx = "Pv";
  113. + if(!pvp)
  114. + pvpx = "Pk";
  115. + if(page>1){
  116. + if(page>4)
  117. + text += "<td width=30><a action=\"bypass -h pvpItem "+ pvpx +" "+ 1 +"\">First</a></td>";
  118. + for(int i = page-3;i<=page-1;i++)
  119. + if(i>0)
  120. + text += "<td><a action=\"bypass -h pvpItem "+ pvpx +" "+ i +"\">"+ i +"</a> </td>";
  121. + }
  122. + text += "<td>"+ page + " </td>";
  123. + for(int i = page+1;i<=page+3;i++)
  124. + if(i<=allPages)
  125. + text += "<td><a action=\"bypass -h pvpItem "+ pvpx +" "+ i +"\">"+ i +"</a> </td>";
  126. + if(page<(allPages-3))
  127. + text += "<td width=30><a action=\"bypass -h pvpItem "+ pvpx +" "+ allPages +"\">Last</a></td>";
  128. + return text;
  129. + }
  130. + private String getList(boolean pvp, int page, String name){
  131. + String text = "";
  132. + int number = 0;
  133. + String orderBy = "pvpkills";
  134. + if(!pvp)
  135. + orderBy = "pkkills";
  136. + Connection con = null;
  137. + try
  138. + {
  139. + con = L2DatabaseFactory.getInstance().getConnection();
  140. + PreparedStatement statement = con.prepareStatement("SELECT char_name, pvpkills, pkkills FROM characters WHERE char_name like '%"+ name +"%' ORDER BY "+ orderBy +" DESC");
  141. + ResultSet rset = statement.executeQuery();
  142. + while(rset.next())
  143. + {
  144. + number ++;
  145. + if(number >= (page*howMayPerPage-(howMayPerPage-1)) && number <= (page*howMayPerPage)){
  146. + text += "<tr><td>"+number+"</td><td>"+rset.getString("char_name")+"</td><td>";
  147. + if(pvp)
  148. + text += rset.getString("pvpkills");
  149. + else
  150. + text += rset.getString("pkkills");
  151. + text += "</td><td>";
  152. + boolean online = false;
  153. + for(L2PcInstance player : L2World.getInstance().getAllPlayers().values())
  154. + if(player.getName().equals(rset.getString("char_name")))
  155. + online = true;
  156. + if(online)
  157. + text += "<font color=\"66FF00\">Online</font>";
  158. + else
  159. + text += "<font color=\"CC0000\">Offline</font>";
  160. + text += "</td></tr>";
  161. + }
  162. + if(number % howMayPerPage == 0)
  163. + allPages ++;
  164. + }
  165. + rset.close();
  166. + statement.close();
  167. + }
  168. + catch (Exception e)
  169. + {
  170. + System.out.println(e);
  171. + }
  172. + finally
  173. + {
  174. + L2DatabaseFactory.close(con);
  175. + }
  176. + return text;
  177. + }
  178. +}
  179. #P L2J_DataPack
  180. Index: data/scripts/handlers/itemhandlers/PvpPkItem.java
  181. ===================================================================
  182. --- data/scripts/handlers/itemhandlers/PvpPkItem.java (revision 0)
  183. +++ data/scripts/handlers/itemhandlers/PvpPkItem.java (revision 0)
  184. @@ -0,0 +1,35 @@
  185. +/*
  186. + * This program is free software: you can redistribute it and/or modify it under
  187. + * the terms of the GNU General Public License as published by the Free Software
  188. + * Foundation, either version 3 of the License, or (at your option) any later
  189. + * version.
  190. + *
  191. + * This program is distributed in the hope that it will be useful, but WITHOUT
  192. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  193. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  194. + * details.
  195. + *
  196. + * You should have received a copy of the GNU General Public License along with
  197. + * this program. If not, see <http://www.gnu.org/licenses/>.
  198. + */
  199. +package handlers.itemhandlers;
  200. +
  201. +import com.l2jserver.gameserver.handler.IItemHandler;
  202. +import com.l2jserver.gameserver.model.L2ItemInstance;
  203. +import com.l2jserver.gameserver.model.actor.L2Playable;
  204. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  205. +import com.l2jserver.gameserver.model.entity.PvpPkList;
  206. +
  207. +public class PvpPkItem implements IItemHandler
  208. +{
  209. + /**
  210. + *
  211. + * @see com.l2jserver.gameserver.handler.IItemHandler#useItem(com.l2jserver.gameserver.model.actor.L2Playable, com.l2jserver.gameserver.model.L2ItemInstance, boolean)
  212. + */
  213. + public void useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  214. + {
  215. + L2PcInstance activeChar = (L2PcInstance) playable;
  216. + PvpPkList x = new PvpPkList();
  217. + x.showUsTheFuture(activeChar, true, 1, "");
  218. + }
  219. +}
Advertisement
Add Comment
Please, Sign In to add comment