AdminCursedWeapons.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 net.sf.l2j.gameserver.handler.admincommandhandlers;
  16. import java.util.StringTokenizer;
  17. import javolution.text.TextBuilder;
  18. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  19. import net.sf.l2j.gameserver.instancemanager.CursedWeaponsManager;
  20. import net.sf.l2j.gameserver.model.CursedWeapon;
  21. import net.sf.l2j.gameserver.model.L2Object;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  23. import net.sf.l2j.gameserver.network.SystemMessageId;
  24. import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
  25. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  26. /**
  27. * This class handles following admin commands:
  28. * - cw_info = displays cursed weapon status
  29. * - cw_remove = removes a cursed weapon from the world, item id or name must be provided
  30. * - cw_add = adds a cursed weapon into the world, item id or name must be provided. Target will be the weilder
  31. * - cw_goto = teleports GM to the specified cursed weapon
  32. * - cw_reload = reloads instance manager
  33. * @version $Revision: 1.1.6.3 $ $Date: 2007/07/31 10:06:06 $
  34. */
  35. public class AdminCursedWeapons implements IAdminCommandHandler {
  36. private static final String[] ADMIN_COMMANDS = {"admin_cw_info", "admin_cw_remove", "admin_cw_goto", "admin_cw_reload", "admin_cw_add", "admin_cw_info_menu"};
  37. private int itemId;
  38. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  39. {
  40. CursedWeaponsManager cwm = CursedWeaponsManager.getInstance();
  41. int id=0;
  42. StringTokenizer st = new StringTokenizer(command);
  43. st.nextToken();
  44. if (command.startsWith("admin_cw_info"))
  45. {
  46. if (!command.contains("menu"))
  47. {
  48. activeChar.sendMessage("====== Cursed Weapons: ======");
  49. for (CursedWeapon cw : cwm.getCursedWeapons())
  50. {
  51. activeChar.sendMessage("> "+cw.getName()+" ("+cw.getItemId()+")");
  52. if (cw.isActivated())
  53. {
  54. L2PcInstance pl = cw.getPlayer();
  55. activeChar.sendMessage(" Player holding: "+ pl==null ? "null" : pl.getName());
  56. activeChar.sendMessage(" Player karma: "+cw.getPlayerKarma());
  57. activeChar.sendMessage(" Time Remaining: "+(cw.getTimeLeft()/60000)+" min.");
  58. activeChar.sendMessage(" Kills : "+cw.getNbKills());
  59. }
  60. else if (cw.isDropped())
  61. {
  62. activeChar.sendMessage(" Lying on the ground.");
  63. activeChar.sendMessage(" Time Remaining: "+(cw.getTimeLeft()/60000)+" min.");
  64. activeChar.sendMessage(" Kills : "+cw.getNbKills());
  65. }
  66. else
  67. {
  68. activeChar.sendMessage(" Don't exist in the world.");
  69. }
  70. activeChar.sendPacket(new SystemMessage(SystemMessageId.FRIEND_LIST_FOOTER));
  71. }
  72. }
  73. else
  74. {
  75. TextBuilder replyMSG = new TextBuilder();
  76. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  77. adminReply.setFile("data/html/admin/cwinfo.htm");
  78. for (CursedWeapon cw : cwm.getCursedWeapons())
  79. {
  80. itemId=cw.getItemId();
  81. replyMSG.append("<table width=270><tr><td>Name:</td><td>"+cw.getName()+"</td></tr>");
  82. if (cw.isActivated())
  83. {
  84. L2PcInstance pl = cw.getPlayer();
  85. replyMSG.append("<tr><td>Weilder:</td><td>"+ (pl==null?"null" : pl.getName())+"</td></tr>");
  86. replyMSG.append("<tr><td>Karma:</td><td>"+String.valueOf(cw.getPlayerKarma())+"</td></tr>");
  87. replyMSG.append("<tr><td>Kills:</td><td>"+String.valueOf(cw.getPlayerPkKills())+"/"+String.valueOf(cw.getNbKills())+"</td></tr>");
  88. replyMSG.append("<tr><td>Time remaining:</td><td>"+String.valueOf(cw.getTimeLeft()/60000)+" min.</td></tr>");
  89. replyMSG.append("<tr><td><button value=\"Remove\" action=\"bypass -h admin_cw_remove "+String.valueOf(itemId)+"\" width=73 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  90. replyMSG.append("<td><button value=\"Go\" action=\"bypass -h admin_cw_goto "+String.valueOf(itemId)+"\" width=73 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  91. }
  92. else if (cw.isDropped())
  93. {
  94. replyMSG.append("<tr><td>Position:</td><td>Lying on the ground</td></tr>");
  95. replyMSG.append("<tr><td>Time remaining:</td><td>"+String.valueOf(cw.getTimeLeft()/60000)+" min.</td></tr>");
  96. replyMSG.append("<tr><td>Kills:</td><td>"+String.valueOf(cw.getNbKills())+"</td></tr>");
  97. replyMSG.append("<tr><td><button value=\"Remove\" action=\"bypass -h admin_cw_remove "+String.valueOf(itemId)+"\" width=73 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  98. replyMSG.append("<td><button value=\"Go\" action=\"bypass -h admin_cw_goto "+String.valueOf(itemId)+"\" width=73 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  99. }
  100. else
  101. {
  102. replyMSG.append("<tr><td>Position:</td><td>Doesn't exist.</td></tr>");
  103. replyMSG.append("<tr><td><button value=\"Give to Target\" action=\"bypass -h admin_cw_add "+String.valueOf(itemId)+"\" width=99 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df></td><td></td></tr>");
  104. }
  105. replyMSG.append("</table>");
  106. replyMSG.append("<br>");
  107. }
  108. adminReply.replace("%cwinfo%", replyMSG.toString());
  109. activeChar.sendPacket(adminReply);
  110. }
  111. }
  112. else if (command.startsWith("admin_cw_reload"))
  113. {
  114. cwm.reload();
  115. }
  116. else
  117. {
  118. CursedWeapon cw=null;
  119. try
  120. {
  121. String parameter = st.nextToken();
  122. if (parameter.matches("[0-9]*"))
  123. id = Integer.parseInt(parameter);
  124. else
  125. {
  126. parameter = parameter.replace('_', ' ');
  127. for (CursedWeapon cwp : cwm.getCursedWeapons())
  128. {
  129. if (cwp.getName().toLowerCase().contains(parameter.toLowerCase()))
  130. {
  131. id=cwp.getItemId();
  132. break;
  133. }
  134. }
  135. }
  136. cw = cwm.getCursedWeapon(id);
  137. if (cw==null)
  138. {
  139. activeChar.sendMessage("Unknown cursed weapon ID.");
  140. return false;
  141. }
  142. }
  143. catch (Exception e)
  144. {
  145. activeChar.sendMessage("Usage: //cw_remove|//cw_goto|//cw_add <itemid|name>");
  146. }
  147. if (command.startsWith("admin_cw_remove "))
  148. {
  149. cw.endOfLife();
  150. }
  151. else if (command.startsWith("admin_cw_goto "))
  152. {
  153. cw.goTo(activeChar);
  154. }
  155. else if (command.startsWith("admin_cw_add"))
  156. {
  157. if (cw==null)
  158. {
  159. activeChar.sendMessage("Usage: //cw_add <itemid|name>");
  160. return false;
  161. }
  162. else if (cw.isActive())
  163. activeChar.sendMessage("This cursed weapon is already active.");
  164. else
  165. {
  166. L2Object target = activeChar.getTarget();
  167. if (target instanceof L2PcInstance)
  168. ((L2PcInstance)target).addItem("AdminCursedWeaponAdd", id, 1, target, true);
  169. else
  170. activeChar.addItem("AdminCursedWeaponAdd", id, 1, activeChar, true);
  171. }
  172. }
  173. else
  174. {
  175. activeChar.sendMessage("Unknown command.");
  176. }
  177. }
  178. return true;
  179. }
  180. public String[] getAdminCommandList() {
  181. return ADMIN_COMMANDS;
  182. }
  183. }