AdminMammon.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 com.l2jserver.gameserver.SevenSigns;
  17. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  18. import com.l2jserver.gameserver.model.AutoSpawnHandler;
  19. import com.l2jserver.gameserver.model.AutoSpawnHandler.AutoSpawnInstance;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. /**
  24. * Admin Command Handler for Mammon NPCs
  25. * @author Tempy, Zoey76
  26. */
  27. public class AdminMammon implements IAdminCommandHandler
  28. {
  29. private static final String[] ADMIN_COMMANDS = { "admin_mammon_find", "admin_mammon_respawn", };
  30. private boolean _isSealValidation = SevenSigns.getInstance().isSealValidationPeriod();
  31. @Override
  32. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  33. {
  34. int teleportIndex = -1;
  35. final AutoSpawnInstance blackSpawnInst = AutoSpawnHandler.getInstance().getAutoSpawnInstance(SevenSigns.MAMMON_BLACKSMITH_ID, false);
  36. final AutoSpawnInstance merchSpawnInst = AutoSpawnHandler.getInstance().getAutoSpawnInstance(SevenSigns.MAMMON_MERCHANT_ID, false);
  37. if (command.startsWith("admin_mammon_find"))
  38. {
  39. try
  40. {
  41. if (command.length() > 17)
  42. {
  43. teleportIndex = Integer.parseInt(command.substring(18));
  44. }
  45. }
  46. catch (Exception NumberFormatException)
  47. {
  48. activeChar.sendMessage("Usage: //mammon_find [teleportIndex] (where 1 = Blacksmith, 2 = Merchant)");
  49. return false;
  50. }
  51. if (!_isSealValidation)
  52. {
  53. activeChar.sendPacket(SystemMessageId.SSQ_COMPETITION_UNDERWAY);
  54. return false;
  55. }
  56. if (blackSpawnInst != null)
  57. {
  58. final L2Npc[] blackInst = blackSpawnInst.getNPCInstanceList();
  59. if (blackInst.length > 0)
  60. {
  61. final int x1 = blackInst[0].getX(), y1 = blackInst[0].getY(), z1 = blackInst[0].getZ();
  62. activeChar.sendMessage("Blacksmith of Mammon: " + x1 + " " + y1 + " " + z1);
  63. if (teleportIndex == 1)
  64. {
  65. activeChar.teleToLocation(x1, y1, z1, true);
  66. }
  67. }
  68. }
  69. else
  70. {
  71. activeChar.sendMessage("Blacksmith of Mammon isn't registered for spawn.");
  72. }
  73. if (merchSpawnInst != null)
  74. {
  75. final L2Npc[] merchInst = merchSpawnInst.getNPCInstanceList();
  76. if (merchInst.length > 0)
  77. {
  78. final int x2 = merchInst[0].getX(), y2 = merchInst[0].getY(), z2 = merchInst[0].getZ();
  79. activeChar.sendMessage("Merchant of Mammon: " + x2 + " " + y2 + " " + z2);
  80. if (teleportIndex == 2)
  81. {
  82. activeChar.teleToLocation(x2, y2, z2, true);
  83. }
  84. }
  85. }
  86. else
  87. {
  88. activeChar.sendMessage("Merchant of Mammon isn't registered for spawn.");
  89. }
  90. }
  91. else if (command.startsWith("admin_mammon_respawn"))
  92. {
  93. if (!_isSealValidation)
  94. {
  95. activeChar.sendPacket(SystemMessageId.SSQ_COMPETITION_UNDERWAY);
  96. return true;
  97. }
  98. if (merchSpawnInst != null)
  99. {
  100. long merchRespawn = AutoSpawnHandler.getInstance().getTimeToNextSpawn(merchSpawnInst);
  101. activeChar.sendMessage("The Merchant of Mammon will respawn in " + (merchRespawn / 60000) + " minute(s).");
  102. }
  103. else
  104. {
  105. activeChar.sendMessage("Merchant of Mammon isn't registered for spawn.");
  106. }
  107. if (blackSpawnInst != null)
  108. {
  109. long blackRespawn = AutoSpawnHandler.getInstance().getTimeToNextSpawn(blackSpawnInst);
  110. activeChar.sendMessage("The Blacksmith of Mammon will respawn in " + (blackRespawn / 60000) + " minute(s).");
  111. }
  112. else
  113. {
  114. activeChar.sendMessage("Blacksmith of Mammon isn't registered for spawn.");
  115. }
  116. }
  117. return true;
  118. }
  119. @Override
  120. public String[] getAdminCommandList()
  121. {
  122. return ADMIN_COMMANDS;
  123. }
  124. }