Time.java 2.3 KB

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