SystemMessage.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.serverpackets;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. /**
  22. * @author Forsaiken, UnAfraid
  23. */
  24. public final class SystemMessage extends AbstractMessagePacket<SystemMessage>
  25. {
  26. private SystemMessage(final SystemMessageId smId)
  27. {
  28. super(smId);
  29. }
  30. public static final SystemMessage sendString(final String text)
  31. {
  32. if (text == null)
  33. {
  34. throw new NullPointerException();
  35. }
  36. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1);
  37. sm.addString(text);
  38. return sm;
  39. }
  40. public static final SystemMessage getSystemMessage(final SystemMessageId smId)
  41. {
  42. SystemMessage sm = smId.getStaticSystemMessage();
  43. if (sm != null)
  44. {
  45. return sm;
  46. }
  47. sm = new SystemMessage(smId);
  48. if (smId.getParamCount() == 0)
  49. {
  50. smId.setStaticSystemMessage(sm);
  51. }
  52. return sm;
  53. }
  54. /**
  55. * Use {@link #getSystemMessage(SystemMessageId)} where possible instead
  56. * @param id
  57. * @return the system message associated to the given Id.
  58. */
  59. public static SystemMessage getSystemMessage(int id)
  60. {
  61. return getSystemMessage(SystemMessageId.getSystemMessageId(id));
  62. }
  63. /**
  64. * Use SystemMessage.getSystemMessage(SystemMessageId smId) where possible instead
  65. * @param id
  66. * @deprecated
  67. */
  68. @Deprecated
  69. private SystemMessage(final int id)
  70. {
  71. this(SystemMessageId.getSystemMessageId(id));
  72. }
  73. @Override
  74. protected final void writeImpl()
  75. {
  76. writeC(0x62);
  77. writeMe();
  78. }
  79. }