Time.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. public class Time implements IUserCommandHandler
  25. {
  26. private static final int[] COMMAND_IDS =
  27. {
  28. 77
  29. };
  30. private static final SimpleDateFormat fmt = new SimpleDateFormat("H:mm.");
  31. @Override
  32. public boolean useUserCommand(int id, L2PcInstance activeChar)
  33. {
  34. if (COMMAND_IDS[0] != id)
  35. return false;
  36. int t = GameTimeController.getInstance().getGameTime();
  37. String h = "" + (t / 60) % 24;
  38. String m;
  39. if (t % 60 < 10)
  40. m = "0" + t % 60;
  41. else
  42. m = "" + t % 60;
  43. SystemMessage sm;
  44. if (GameTimeController.getInstance().isNowNight())
  45. {
  46. sm = SystemMessage.getSystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_NIGHT);
  47. sm.addString(h);
  48. sm.addString(m);
  49. }
  50. else
  51. {
  52. sm = SystemMessage.getSystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_DAY);
  53. sm.addString(h);
  54. sm.addString(m);
  55. }
  56. activeChar.sendPacket(sm);
  57. if (Config.L2JMOD_DISPLAY_SERVER_TIME)
  58. activeChar.sendMessage("Server time is " + fmt.format(new Date(System.currentTimeMillis())));
  59. return true;
  60. }
  61. @Override
  62. public int[] getUserCommandList()
  63. {
  64. return COMMAND_IDS;
  65. }
  66. }