Time.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 net.sf.l2j.gameserver.handler.usercommandhandlers;
  15. import net.sf.l2j.gameserver.GameTimeController;
  16. import net.sf.l2j.gameserver.handler.IUserCommandHandler;
  17. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  18. import net.sf.l2j.gameserver.network.SystemMessageId;
  19. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  20. /**
  21. *
  22. *
  23. */
  24. public class Time implements IUserCommandHandler
  25. {
  26. private static final int[] COMMAND_IDS = { 77 };
  27. /* (non-Javadoc)
  28. *
  29. */
  30. public boolean useUserCommand(int id, L2PcInstance activeChar)
  31. {
  32. if (COMMAND_IDS[0] != id) return false;
  33. int t = GameTimeController.getInstance().getGameTime();
  34. String h = "" + (t/60)%24;
  35. String m;
  36. if (t%60 < 10)
  37. m = "0" + t%60;
  38. else
  39. m = "" + t%60;
  40. SystemMessage sm;
  41. if (GameTimeController.getInstance().isNowNight()) {
  42. sm = new SystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_NIGHT);
  43. sm.addString(h);
  44. sm.addString(m);
  45. }
  46. else {
  47. sm = new SystemMessage(SystemMessageId.TIME_S1_S2_IN_THE_DAY);
  48. sm.addString(h);
  49. sm.addString(m);
  50. }
  51. activeChar.sendPacket(sm);
  52. return true;
  53. }
  54. public int[] getUserCommandList()
  55. {
  56. return COMMAND_IDS;
  57. }
  58. }