Time.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.text.SimpleDateFormat;
  21. import java.util.Date;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.GameTimeController;
  24. import com.l2jserver.gameserver.handler.IUserCommandHandler;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  28. /**
  29. * Time user command.
  30. */
  31. public class Time implements IUserCommandHandler
  32. {
  33. private static final int[] COMMAND_IDS =
  34. {
  35. 77
  36. };
  37. private static final SimpleDateFormat fmt = new SimpleDateFormat("H:mm.");
  38. @Override
  39. public boolean useUserCommand(int id, L2PcInstance activeChar)
  40. {
  41. if (COMMAND_IDS[0] != id)
  42. {
  43. return false;
  44. }
  45. int t = GameTimeController.getInstance().getGameTime();
  46. String h = "" + ((t / 60) % 24);
  47. String m;
  48. if ((t % 60) < 10)
  49. {
  50. m = "0" + (t % 60);
  51. }
  52. else
  53. {
  54. m = "" + (t % 60);
  55. }
  56. SystemMessage sm;
  57. if (GameTimeController.getInstance().isNight())
  58. {
  59. sm = SystemMessage.getSystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_NIGHT);
  60. sm.addString(h);
  61. sm.addString(m);
  62. }
  63. else
  64. {
  65. sm = SystemMessage.getSystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_DAY);
  66. sm.addString(h);
  67. sm.addString(m);
  68. }
  69. activeChar.sendPacket(sm);
  70. if (Config.L2JMOD_DISPLAY_SERVER_TIME)
  71. {
  72. activeChar.sendMessage("Server time is " + fmt.format(new Date(System.currentTimeMillis())));
  73. }
  74. return true;
  75. }
  76. @Override
  77. public int[] getUserCommandList()
  78. {
  79. return COMMAND_IDS;
  80. }
  81. }