Time.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. @Override
  35. public boolean useUserCommand(int id, L2PcInstance activeChar)
  36. {
  37. if (COMMAND_IDS[0] != id)
  38. return false;
  39. int t = GameTimeController.getInstance().getGameTime();
  40. String h = "" + (t / 60) % 24;
  41. String m;
  42. if (t % 60 < 10)
  43. m = "0" + t % 60;
  44. else
  45. m = "" + t % 60;
  46. SystemMessage sm;
  47. if (GameTimeController.getInstance().isNowNight())
  48. {
  49. sm = SystemMessage.getSystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_NIGHT);
  50. sm.addString(h);
  51. sm.addString(m);
  52. }
  53. else
  54. {
  55. sm = SystemMessage.getSystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_DAY);
  56. sm.addString(h);
  57. sm.addString(m);
  58. }
  59. activeChar.sendPacket(sm);
  60. if (Config.L2JMOD_DISPLAY_SERVER_TIME)
  61. activeChar.sendMessage("Server time is " + fmt.format(new Date(System.currentTimeMillis())));
  62. return true;
  63. }
  64. /**
  65. *
  66. * @see com.l2jserver.gameserver.handler.IUserCommandHandler#getUserCommandList()
  67. */
  68. @Override
  69. public int[] getUserCommandList()
  70. {
  71. return COMMAND_IDS;
  72. }
  73. }