AdminCursedWeapons.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.util.Collection;
  21. import java.util.StringTokenizer;
  22. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  23. import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;
  24. import com.l2jserver.gameserver.model.CursedWeapon;
  25. import com.l2jserver.gameserver.model.L2Object;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  29. import com.l2jserver.util.StringUtil;
  30. /**
  31. * This class handles following admin commands: - cw_info = displays cursed weapon status - cw_remove = removes a cursed weapon from the world, item id or name must be provided - cw_add = adds a cursed weapon into the world, item id or name must be provided. Target will be the weilder - cw_goto =
  32. * teleports GM to the specified cursed weapon - 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 = new StringBuilder(cws.size() * 300);
  87. final NpcHtmlMessage adminReply = new NpcHtmlMessage();
  88. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/cwinfo.htm");
  89. for (CursedWeapon cw : cwm.getCursedWeapons())
  90. {
  91. itemId = cw.getItemId();
  92. StringUtil.append(replyMSG, "<table width=270><tr><td>Name:</td><td>", cw.getName(), "</td></tr>");
  93. if (cw.isActivated())
  94. {
  95. L2PcInstance pl = cw.getPlayer();
  96. StringUtil.append(replyMSG, "<tr><td>Weilder:</td><td>", (pl == null ? "null" : pl.getName()), "</td></tr>" + "<tr><td>Karma:</td><td>", String.valueOf(cw.getPlayerKarma()), "</td></tr>" + "<tr><td>Kills:</td><td>", String.valueOf(cw.getPlayerPkKills()), "/", String.valueOf(cw.getNbKills()), "</td></tr>" + "<tr><td>Time remaining:</td><td>", String.valueOf(cw.getTimeLeft() / 60000), " min.</td></tr>" + "<tr><td><button value=\"Remove\" action=\"bypass -h admin_cw_remove ", String.valueOf(itemId), "\" width=73 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>" + "<td><button value=\"Go\" action=\"bypass -h admin_cw_goto ", String.valueOf(itemId), "\" width=73 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  97. }
  98. else if (cw.isDropped())
  99. {
  100. StringUtil.append(replyMSG, "<tr><td>Position:</td><td>Lying on the ground</td></tr>" + "<tr><td>Time remaining:</td><td>", String.valueOf(cw.getTimeLeft() / 60000), " min.</td></tr>" + "<tr><td>Kills:</td><td>", String.valueOf(cw.getNbKills()), "</td></tr>" + "<tr><td><button value=\"Remove\" action=\"bypass -h admin_cw_remove ", String.valueOf(itemId), "\" width=73 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>" + "<td><button value=\"Go\" action=\"bypass -h admin_cw_goto ", String.valueOf(itemId), "\" width=73 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  101. }
  102. else
  103. {
  104. StringUtil.append(replyMSG, "<tr><td>Position:</td><td>Doesn't exist.</td></tr>" + "<tr><td><button value=\"Give to Target\" action=\"bypass -h admin_cw_add ", String.valueOf(itemId), "\" width=130 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td></td></tr>");
  105. }
  106. replyMSG.append("</table><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. {
  124. id = Integer.parseInt(parameter);
  125. }
  126. else
  127. {
  128. parameter = parameter.replace('_', ' ');
  129. for (CursedWeapon cwp : cwm.getCursedWeapons())
  130. {
  131. if (cwp.getName().toLowerCase().contains(parameter.toLowerCase()))
  132. {
  133. id = cwp.getItemId();
  134. break;
  135. }
  136. }
  137. }
  138. cw = cwm.getCursedWeapon(id);
  139. }
  140. catch (Exception e)
  141. {
  142. activeChar.sendMessage("Usage: //cw_remove|//cw_goto|//cw_add <itemid|name>");
  143. }
  144. if (cw == null)
  145. {
  146. activeChar.sendMessage("Unknown cursed weapon ID.");
  147. return false;
  148. }
  149. if (command.startsWith("admin_cw_remove "))
  150. {
  151. cw.endOfLife();
  152. }
  153. else if (command.startsWith("admin_cw_goto "))
  154. {
  155. cw.goTo(activeChar);
  156. }
  157. else if (command.startsWith("admin_cw_add"))
  158. {
  159. if (cw.isActive())
  160. {
  161. activeChar.sendMessage("This cursed weapon is already active.");
  162. }
  163. else
  164. {
  165. L2Object target = activeChar.getTarget();
  166. if (target instanceof L2PcInstance)
  167. {
  168. ((L2PcInstance) target).addItem("AdminCursedWeaponAdd", id, 1, target, true);
  169. }
  170. else
  171. {
  172. activeChar.addItem("AdminCursedWeaponAdd", id, 1, activeChar, true);
  173. }
  174. cw.setEndTime(System.currentTimeMillis() + (cw.getDuration() * 60000L));
  175. cw.reActivate();
  176. }
  177. }
  178. else
  179. {
  180. activeChar.sendMessage("Unknown command.");
  181. }
  182. }
  183. return true;
  184. }
  185. @Override
  186. public String[] getAdminCommandList()
  187. {
  188. return ADMIN_COMMANDS;
  189. }
  190. }