AdminMammon.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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.regex.Matcher;
  17. import java.util.regex.Pattern;
  18. import net.sf.l2j.gameserver.SevenSigns;
  19. import net.sf.l2j.gameserver.datatables.NpcTable;
  20. import net.sf.l2j.gameserver.datatables.SpawnTable;
  21. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  22. import net.sf.l2j.gameserver.model.AutoSpawnHandler;
  23. import net.sf.l2j.gameserver.model.AutoSpawnHandler.AutoSpawnInstance;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  26. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  27. /**
  28. * Admin Command Handler for Mammon NPCs
  29. *
  30. * @author Tempy
  31. */
  32. public class AdminMammon implements IAdminCommandHandler
  33. {
  34. private static final String[] ADMIN_COMMANDS =
  35. {
  36. "admin_mammon_find",
  37. "admin_mammon_respawn",
  38. "admin_list_spawns",
  39. "admin_msg"
  40. };
  41. private boolean _isSealValidation = SevenSigns.getInstance().isSealValidationPeriod();
  42. @SuppressWarnings("deprecation")
  43. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  44. {
  45. int npcId = 0;
  46. int teleportIndex = -1;
  47. AutoSpawnInstance blackSpawnInst = AutoSpawnHandler.getInstance().getAutoSpawnInstance(SevenSigns.MAMMON_BLACKSMITH_ID, false);
  48. AutoSpawnInstance merchSpawnInst = AutoSpawnHandler.getInstance().getAutoSpawnInstance(SevenSigns.MAMMON_MERCHANT_ID, false);
  49. if (command.startsWith("admin_mammon_find"))
  50. {
  51. try
  52. {
  53. if (command.length() > 17)
  54. teleportIndex = Integer.parseInt(command.substring(18));
  55. }
  56. catch (Exception NumberFormatException)
  57. {
  58. activeChar.sendMessage("Usage: //mammon_find [teleportIndex] (where 1 = Blacksmith, 2 = Merchant)");
  59. }
  60. if (!_isSealValidation)
  61. {
  62. activeChar.sendMessage("The competition period is currently in effect.");
  63. return true;
  64. }
  65. if (blackSpawnInst != null)
  66. {
  67. L2NpcInstance[] blackInst = blackSpawnInst.getNPCInstanceList();
  68. if (blackInst.length > 0)
  69. {
  70. int x1 = blackInst[0].getX(), y1 = blackInst[0].getY(), z1 = blackInst[0].getZ();
  71. activeChar.sendMessage("Blacksmith of Mammon: " + x1 + " " + y1 + " " + z1);
  72. if (teleportIndex == 1)
  73. activeChar.teleToLocation(x1, y1, z1, true);
  74. }
  75. }
  76. else
  77. activeChar.sendMessage("Blacksmith of Mammon isn't registered for spawn.");
  78. if (merchSpawnInst != null)
  79. {
  80. L2NpcInstance[] merchInst = merchSpawnInst.getNPCInstanceList();
  81. if (merchInst.length > 0)
  82. {
  83. int x2 = merchInst[0].getX(), y2 = merchInst[0].getY(), z2 = merchInst[0].getZ();
  84. activeChar.sendMessage("Merchant of Mammon: " + x2 + " " + y2 + " " + z2);
  85. if (teleportIndex == 2)
  86. activeChar.teleToLocation(x2, y2, z2, true);
  87. }
  88. }
  89. else
  90. activeChar.sendMessage("Merchant of Mammon isn't registered for spawn.");
  91. }
  92. else if (command.startsWith("admin_mammon_respawn"))
  93. {
  94. if (!_isSealValidation)
  95. {
  96. activeChar.sendMessage("The competition period is currently in effect.");
  97. return true;
  98. }
  99. if (merchSpawnInst != null)
  100. {
  101. long merchRespawn = AutoSpawnHandler.getInstance().getTimeToNextSpawn(merchSpawnInst);
  102. activeChar.sendMessage("The Merchant of Mammon will respawn in " + (merchRespawn / 60000) + " minute(s).");
  103. }
  104. else
  105. activeChar.sendMessage("Merchant of Mammon isn't registered for spawn.");
  106. if (blackSpawnInst != null)
  107. {
  108. long blackRespawn = AutoSpawnHandler.getInstance().getTimeToNextSpawn(blackSpawnInst);
  109. activeChar.sendMessage("The Blacksmith of Mammon will respawn in " + (blackRespawn / 60000) + " minute(s).");
  110. }
  111. else
  112. activeChar.sendMessage("Blacksmith of Mammon isn't registered for spawn.");
  113. }
  114. else if (command.startsWith("admin_list_spawns"))
  115. {
  116. try
  117. { // admin_list_spawns x[xxxx] x[xx]
  118. String[] params = command.split(" ");
  119. Pattern pattern = Pattern.compile("[0-9]*");
  120. Matcher regexp = pattern.matcher(params[1]);
  121. if (regexp.matches())
  122. npcId = Integer.parseInt(params[1]);
  123. else
  124. {
  125. params[1] = params[1].replace('_', ' ');
  126. npcId = NpcTable.getInstance().getTemplateByName(params[1]).npcId;
  127. }
  128. if (params.length > 2)
  129. teleportIndex = Integer.parseInt(params[2]);
  130. }
  131. catch (Exception e)
  132. {
  133. activeChar.sendMessage("Command format is //list_spawns <npcId|npc_name> [tele_index]");
  134. }
  135. SpawnTable.getInstance().findNPCInstances(activeChar, npcId, teleportIndex);
  136. }
  137. // Used for testing SystemMessage IDs - Use //msg <ID>
  138. else if (command.startsWith("admin_msg"))
  139. {
  140. int msgId = -1;
  141. try
  142. {
  143. msgId = Integer.parseInt(command.substring(10).trim());
  144. }
  145. catch (Exception e)
  146. {
  147. activeChar.sendMessage("Command format: //msg <SYSTEM_MSG_ID>");
  148. return true;
  149. }
  150. activeChar.sendPacket(new SystemMessage(msgId));
  151. }
  152. return true;
  153. }
  154. public String[] getAdminCommandList()
  155. {
  156. return ADMIN_COMMANDS;
  157. }
  158. }