AdminAnnouncements.java 3.7 KB

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