2
0

Time.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /** This program is free software: you can redistribute it and/or modify it under
  2. * the terms of the GNU General Public License as published by the Free Software
  3. * Foundation, either version 3 of the License, or (at your option) any later
  4. * version.
  5. *
  6. * This program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  9. * details.
  10. *
  11. * You should have received a copy of the GNU General Public License along with
  12. * this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. package net.sf.l2j.gameserver.handler.usercommandhandlers;
  15. import net.sf.l2j.gameserver.GameTimeController;
  16. import net.sf.l2j.gameserver.handler.IUserCommandHandler;
  17. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  18. import net.sf.l2j.gameserver.network.SystemMessageId;
  19. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  20. /**
  21. *
  22. *
  23. */
  24. public class Time implements IUserCommandHandler
  25. {
  26. private static final int[] COMMAND_IDS =
  27. {
  28. 77
  29. };
  30. /**
  31. *
  32. * @see net.sf.l2j.gameserver.handler.IUserCommandHandler#useUserCommand(int, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance)
  33. */
  34. public boolean useUserCommand(int id, L2PcInstance activeChar)
  35. {
  36. if (COMMAND_IDS[0] != id)
  37. return false;
  38. int t = GameTimeController.getInstance().getGameTime();
  39. String h = "" + (t / 60) % 24;
  40. String m;
  41. if (t % 60 < 10)
  42. m = "0" + t % 60;
  43. else
  44. m = "" + t % 60;
  45. SystemMessage sm;
  46. if (GameTimeController.getInstance().isNowNight())
  47. {
  48. sm = new SystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_NIGHT);
  49. sm.addString(h);
  50. sm.addString(m);
  51. }
  52. else
  53. {
  54. sm = new SystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_DAY);
  55. sm.addString(h);
  56. sm.addString(m);
  57. }
  58. activeChar.sendPacket(sm);
  59. return true;
  60. }
  61. /**
  62. *
  63. * @see net.sf.l2j.gameserver.handler.IUserCommandHandler#getUserCommandList()
  64. */
  65. public int[] getUserCommandList()
  66. {
  67. return COMMAND_IDS;
  68. }
  69. }