AdminAnnouncements.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 net.sf.l2j.gameserver.handler.admincommandhandlers;
  16. import java.util.Collection;
  17. import net.sf.l2j.gameserver.Announcements;
  18. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  19. import net.sf.l2j.gameserver.model.L2World;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  21. /**
  22. * This class handles following admin commands:
  23. * - announce text = announces text to all players
  24. * - list_announcements = show menu
  25. * - reload_announcements = reloads announcements from txt file
  26. * - announce_announcements = announce all stored announcements to all players
  27. * - add_announcement text = adds text to startup announcements
  28. * - del_announcement id = deletes announcement with respective id
  29. *
  30. * @version $Revision: 1.4.4.5 $ $Date: 2005/04/11 10:06:06 $
  31. */
  32. public class AdminAnnouncements implements IAdminCommandHandler
  33. {
  34. private static final String[] ADMIN_COMMANDS =
  35. {
  36. "admin_list_announcements",
  37. "admin_reload_announcements",
  38. "admin_announce_announcements",
  39. "admin_add_announcement",
  40. "admin_del_announcement",
  41. "admin_announce",
  42. "admin_announce_menu"
  43. };
  44. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  45. {
  46. if (command.equals("admin_list_announcements"))
  47. {
  48. Announcements.getInstance().listAnnouncements(activeChar);
  49. }
  50. else if (command.equals("admin_reload_announcements"))
  51. {
  52. Announcements.getInstance().loadAnnouncements();
  53. Announcements.getInstance().listAnnouncements(activeChar);
  54. }
  55. else if (command.startsWith("admin_announce_menu"))
  56. {
  57. Announcements sys = new Announcements();
  58. sys.handleAnnounce(command, 20);
  59. Announcements.getInstance().listAnnouncements(activeChar);
  60. }
  61. else if (command.equals("admin_announce_announcements"))
  62. {
  63. Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
  64. // synchronized (L2World.getInstance().getAllPlayers())
  65. {
  66. for (L2PcInstance player : pls)
  67. Announcements.getInstance().showAnnouncements(player);
  68. }
  69. Announcements.getInstance().listAnnouncements(activeChar);
  70. }
  71. else if (command.startsWith("admin_add_announcement"))
  72. {
  73. // FIXME the player can send only 16 chars (if you try to send more
  74. // it sends null), remove this function or not?
  75. if (!command.equals("admin_add_announcement"))
  76. {
  77. try
  78. {
  79. String val = command.substring(23);
  80. Announcements.getInstance().addAnnouncement(val);
  81. Announcements.getInstance().listAnnouncements(activeChar);
  82. }
  83. catch (StringIndexOutOfBoundsException e)
  84. {
  85. }// ignore errors
  86. }
  87. }
  88. else if (command.startsWith("admin_del_announcement"))
  89. {
  90. try
  91. {
  92. int val = new Integer(command.substring(23)).intValue();
  93. Announcements.getInstance().delAnnouncement(val);
  94. Announcements.getInstance().listAnnouncements(activeChar);
  95. }
  96. catch (StringIndexOutOfBoundsException e)
  97. {
  98. }
  99. }
  100. // Command is admin announce
  101. else if (command.startsWith("admin_announce"))
  102. {
  103. // Call method from another class
  104. Announcements sys = new Announcements();
  105. sys.handleAnnounce(command, 15);
  106. }
  107. return true;
  108. }
  109. public String[] getAdminCommandList()
  110. {
  111. return ADMIN_COMMANDS;
  112. }
  113. }