InstanceZone.java 3.0 KB

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