InstanceZone.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.usercommandhandlers;
  16. import java.util.Map;
  17. import com.l2jserver.gameserver.handler.IUserCommandHandler;
  18. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  23. /**
  24. * Instance Zone user command.
  25. * @author nille02
  26. */
  27. public class InstanceZone implements IUserCommandHandler
  28. {
  29. private static final int[] COMMAND_IDS =
  30. {
  31. 114
  32. };
  33. @Override
  34. public int[] getUserCommandList()
  35. {
  36. return COMMAND_IDS;
  37. }
  38. @Override
  39. public boolean useUserCommand(int id, L2PcInstance activeChar)
  40. {
  41. if (id != COMMAND_IDS[0])
  42. {
  43. return false;
  44. }
  45. final InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(activeChar);
  46. if ((world != null) && (world.getTemplateId() >= 0))
  47. {
  48. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.INSTANT_ZONE_CURRENTLY_INUSE_S1);
  49. sm.addInstanceName(world.getTemplateId());
  50. activeChar.sendPacket(sm);
  51. }
  52. final Map<Integer, Long> instanceTimes = InstanceManager.getInstance().getAllInstanceTimes(activeChar.getObjectId());
  53. boolean firstMessage = true;
  54. if (instanceTimes != null)
  55. {
  56. for (int instanceId : instanceTimes.keySet())
  57. {
  58. long remainingTime = (instanceTimes.get(instanceId) - System.currentTimeMillis()) / 1000;
  59. if (remainingTime > 60)
  60. {
  61. if (firstMessage)
  62. {
  63. firstMessage = false;
  64. activeChar.sendPacket(SystemMessageId.INSTANCE_ZONE_TIME_LIMIT);
  65. }
  66. int hours = (int) (remainingTime / 3600);
  67. int minutes = (int) ((remainingTime % 3600) / 60);
  68. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVAILABLE_AFTER_S1_S2_HOURS_S3_MINUTES);
  69. sm.addInstanceName(instanceId);
  70. sm.addNumber(hours);
  71. sm.addNumber(minutes);
  72. activeChar.sendPacket(sm);
  73. }
  74. else
  75. {
  76. InstanceManager.getInstance().deleteInstanceTime(activeChar.getObjectId(), instanceId);
  77. }
  78. }
  79. }
  80. if (firstMessage)
  81. {
  82. activeChar.sendPacket(SystemMessageId.NO_INSTANCEZONE_TIME_LIMIT);
  83. }
  84. return true;
  85. }
  86. }