AdminBanChat.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.ThreadPoolManager;
  17. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  18. import net.sf.l2j.gameserver.model.L2Object;
  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. * - admin_banchat = Imposes a chat ban on the specified player/target.
  24. * - admin_unbanchat = Removes any chat ban on the specified player/target.
  25. *
  26. * Uses:
  27. * admin_banchat [<player_name>] [<ban_duration>]
  28. * admin_unbanchat [<player_name>]
  29. *
  30. * If <player_name> is not specified, the current target player is used.
  31. *
  32. * @version $Revision: 1.1.6.3 $ $Date: 2005/04/11 10:06:06 $
  33. */
  34. public class AdminBanChat implements IAdminCommandHandler {
  35. private static final String[] ADMIN_COMMANDS = {"admin_banchat", "admin_unbanchat"};
  36. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  37. {
  38. String[] cmdParams = command.split(" ");
  39. long banLength = -1;
  40. L2Object targetObject = null;
  41. L2PcInstance targetPlayer = null;
  42. if (cmdParams.length > 1)
  43. {
  44. targetPlayer = L2World.getInstance().getPlayer(cmdParams[1]);
  45. if (cmdParams.length > 2)
  46. {
  47. try
  48. {
  49. banLength = Integer.parseInt(cmdParams[2]) * 60000L;
  50. } catch (NumberFormatException nfe) {}
  51. }
  52. } else
  53. {
  54. if (activeChar.getTarget() != null)
  55. {
  56. targetObject = activeChar.getTarget();
  57. if (targetObject instanceof L2PcInstance)
  58. targetPlayer = (L2PcInstance)targetObject;
  59. }
  60. }
  61. if (targetPlayer == null)
  62. {
  63. activeChar.sendMessage("Incorrect parameter or target.");
  64. return false;
  65. }
  66. if (command.startsWith("admin_banchat"))
  67. {
  68. String banLengthStr = "";
  69. if (banLength > -1)
  70. {
  71. targetPlayer.setChatUnbanTask(ThreadPoolManager.getInstance().scheduleGeneral(new SchedChatUnban(targetPlayer, activeChar), banLength));
  72. banLengthStr = " for " + banLength + " seconds.";
  73. }
  74. activeChar.sendMessage(targetPlayer.getName() + " is now chat banned" + banLengthStr + ".");
  75. targetPlayer.setChatBanned(true);
  76. }
  77. else if (command.startsWith("admin_unbanchat"))
  78. {
  79. activeChar.sendMessage(targetPlayer.getName() + "'s chat ban has now been lifted.");
  80. targetPlayer.setChatBanned(false);
  81. }
  82. return true;
  83. }
  84. public String[] getAdminCommandList() {
  85. return ADMIN_COMMANDS;
  86. }
  87. private class SchedChatUnban implements Runnable
  88. {
  89. L2PcInstance _player;
  90. L2PcInstance _banner;
  91. protected SchedChatUnban(L2PcInstance player, L2PcInstance banner)
  92. {
  93. _player = player;
  94. _banner = banner;
  95. }
  96. public void run()
  97. {
  98. _player.setChatBanned(false);
  99. }
  100. }
  101. }