AdminMammon.java 5.5 KB

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