Time.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 handlers.usercommandhandlers;
  15. import java.text.SimpleDateFormat;
  16. import java.util.Date;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.GameTimeController;
  19. import com.l2jserver.gameserver.handler.IUserCommandHandler;
  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. public class Time implements IUserCommandHandler
  24. {
  25. private static final int[] COMMAND_IDS =
  26. {
  27. 77
  28. };
  29. private static final SimpleDateFormat fmt = new SimpleDateFormat("H:mm.");
  30. /**
  31. *
  32. * @see com.l2jserver.gameserver.handler.IUserCommandHandler#useUserCommand(int, com.l2jserver.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 = SystemMessage.getSystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_NIGHT);
  49. sm.addString(h);
  50. sm.addString(m);
  51. }
  52. else
  53. {
  54. sm = SystemMessage.getSystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_DAY);
  55. sm.addString(h);
  56. sm.addString(m);
  57. }
  58. activeChar.sendPacket(sm);
  59. if (Config.L2JMOD_DISPLAY_SERVER_TIME)
  60. activeChar.sendMessage("Server time is " + fmt.format(new Date(System.currentTimeMillis())));
  61. return true;
  62. }
  63. /**
  64. *
  65. * @see com.l2jserver.gameserver.handler.IUserCommandHandler#getUserCommandList()
  66. */
  67. public int[] getUserCommandList()
  68. {
  69. return COMMAND_IDS;
  70. }
  71. }