InstanceZone.java 2.8 KB

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