AdminCursedWeapons.java 7.6 KB

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