AdminCursedWeapons.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 handlers.admincommandhandlers;
  16. import java.util.Collection;
  17. import java.util.StringTokenizer;
  18. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  19. import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;
  20. import com.l2jserver.gameserver.model.CursedWeapon;
  21. import com.l2jserver.gameserver.model.L2Object;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  25. import com.l2jserver.util.StringUtil;
  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. @Override
  48. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  49. {
  50. CursedWeaponsManager cwm = CursedWeaponsManager.getInstance();
  51. int id = 0;
  52. StringTokenizer st = new StringTokenizer(command);
  53. st.nextToken();
  54. if (command.startsWith("admin_cw_info"))
  55. {
  56. if (!command.contains("menu"))
  57. {
  58. activeChar.sendMessage("====== Cursed Weapons: ======");
  59. for (CursedWeapon cw : cwm.getCursedWeapons())
  60. {
  61. activeChar.sendMessage("> " + cw.getName() + " (" + cw.getItemId() + ")");
  62. if (cw.isActivated())
  63. {
  64. L2PcInstance pl = cw.getPlayer();
  65. activeChar.sendMessage(" Player holding: " + (pl == null ? "null" : pl.getName()));
  66. activeChar.sendMessage(" Player karma: " + cw.getPlayerKarma());
  67. activeChar.sendMessage(" Time Remaining: " + (cw.getTimeLeft() / 60000) + " min.");
  68. activeChar.sendMessage(" Kills : " + cw.getNbKills());
  69. }
  70. else if (cw.isDropped())
  71. {
  72. activeChar.sendMessage(" Lying on the ground.");
  73. activeChar.sendMessage(" Time Remaining: " + (cw.getTimeLeft() / 60000) + " min.");
  74. activeChar.sendMessage(" Kills : " + cw.getNbKills());
  75. }
  76. else
  77. {
  78. activeChar.sendMessage(" Don't exist in the world.");
  79. }
  80. activeChar.sendPacket(SystemMessageId.FRIEND_LIST_FOOTER);
  81. }
  82. }
  83. else
  84. {
  85. final Collection<CursedWeapon> cws = cwm.getCursedWeapons();
  86. final StringBuilder replyMSG =
  87. new StringBuilder(cws.size() * 300);
  88. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  89. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/cwinfo.htm");
  90. for (CursedWeapon cw : cwm.getCursedWeapons()) {
  91. itemId = cw.getItemId();
  92. StringUtil.append(replyMSG,
  93. "<table width=270><tr><td>Name:</td><td>",
  94. cw.getName(),
  95. "</td></tr>");
  96. if (cw.isActivated()) {
  97. L2PcInstance pl = cw.getPlayer();
  98. StringUtil.append(replyMSG,
  99. "<tr><td>Weilder:</td><td>",
  100. (pl == null ? "null" : pl.getName()),
  101. "</td></tr>" +
  102. "<tr><td>Karma:</td><td>",
  103. String.valueOf(cw.getPlayerKarma()),
  104. "</td></tr>" +
  105. "<tr><td>Kills:</td><td>",
  106. String.valueOf(cw.getPlayerPkKills()),
  107. "/",
  108. String.valueOf(cw.getNbKills()),
  109. "</td></tr>" +
  110. "<tr><td>Time remaining:</td><td>",
  111. String.valueOf(cw.getTimeLeft() / 60000),
  112. " min.</td></tr>" +
  113. "<tr><td><button value=\"Remove\" action=\"bypass -h admin_cw_remove ",
  114. String.valueOf(itemId),
  115. "\" width=73 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>" +
  116. "<td><button value=\"Go\" action=\"bypass -h admin_cw_goto ",
  117. String.valueOf(itemId),
  118. "\" width=73 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>"
  119. );
  120. }
  121. else if (cw.isDropped()) {
  122. StringUtil.append(replyMSG,
  123. "<tr><td>Position:</td><td>Lying on the ground</td></tr>" +
  124. "<tr><td>Time remaining:</td><td>",
  125. String.valueOf(cw.getTimeLeft() / 60000),
  126. " min.</td></tr>" +
  127. "<tr><td>Kills:</td><td>",
  128. String.valueOf(cw.getNbKills()),
  129. "</td></tr>" +
  130. "<tr><td><button value=\"Remove\" action=\"bypass -h admin_cw_remove ",
  131. String.valueOf(itemId),
  132. "\" width=73 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>" +
  133. "<td><button value=\"Go\" action=\"bypass -h admin_cw_goto ",
  134. String.valueOf(itemId),
  135. "\" width=73 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>"
  136. );
  137. } else {
  138. StringUtil.append(replyMSG,
  139. "<tr><td>Position:</td><td>Doesn't exist.</td></tr>" +
  140. "<tr><td><button value=\"Give to Target\" action=\"bypass -h admin_cw_add ",
  141. String.valueOf(itemId),
  142. "\" width=130 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td></td></tr>"
  143. );
  144. }
  145. replyMSG.append("</table><br>");
  146. }
  147. adminReply.replace("%cwinfo%", replyMSG.toString());
  148. activeChar.sendPacket(adminReply);
  149. }
  150. }
  151. else if (command.startsWith("admin_cw_reload"))
  152. {
  153. cwm.reload();
  154. }
  155. else
  156. {
  157. CursedWeapon cw = null;
  158. try
  159. {
  160. String parameter = st.nextToken();
  161. if (parameter.matches("[0-9]*"))
  162. id = Integer.parseInt(parameter);
  163. else
  164. {
  165. parameter = parameter.replace('_', ' ');
  166. for (CursedWeapon cwp : cwm.getCursedWeapons())
  167. {
  168. if (cwp.getName().toLowerCase().contains(parameter.toLowerCase()))
  169. {
  170. id = cwp.getItemId();
  171. break;
  172. }
  173. }
  174. }
  175. cw = cwm.getCursedWeapon(id);
  176. }
  177. catch (Exception e)
  178. {
  179. activeChar.sendMessage("Usage: //cw_remove|//cw_goto|//cw_add <itemid|name>");
  180. }
  181. if (cw == null)
  182. {
  183. activeChar.sendMessage("Unknown cursed weapon ID.");
  184. return false;
  185. }
  186. if (command.startsWith("admin_cw_remove "))
  187. {
  188. cw.endOfLife();
  189. }
  190. else if (command.startsWith("admin_cw_goto "))
  191. {
  192. cw.goTo(activeChar);
  193. }
  194. else if (command.startsWith("admin_cw_add"))
  195. {
  196. if (cw.isActive())
  197. activeChar.sendMessage("This cursed weapon is already active.");
  198. else
  199. {
  200. L2Object target = activeChar.getTarget();
  201. if (target instanceof L2PcInstance)
  202. ((L2PcInstance) target).addItem("AdminCursedWeaponAdd", id, 1, target, true);
  203. else
  204. activeChar.addItem("AdminCursedWeaponAdd", id, 1, activeChar, true);
  205. cw.setEndTime(System.currentTimeMillis() + cw.getDuration() * 60000L);
  206. cw.reActivate();
  207. }
  208. }
  209. else
  210. {
  211. activeChar.sendMessage("Unknown command.");
  212. }
  213. }
  214. return true;
  215. }
  216. @Override
  217. public String[] getAdminCommandList()
  218. {
  219. return ADMIN_COMMANDS;
  220. }
  221. }