AdminBanChat.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. {
  36. private static final String[] ADMIN_COMMANDS =
  37. {
  38. "admin_banchat",
  39. "admin_unbanchat"
  40. };
  41. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. String[] cmdParams = command.split(" ");
  44. long banLength = -1;
  45. L2Object targetObject = null;
  46. L2PcInstance targetPlayer = null;
  47. if (cmdParams.length > 1)
  48. {
  49. targetPlayer = L2World.getInstance().getPlayer(cmdParams[1]);
  50. if (cmdParams.length > 2)
  51. {
  52. try
  53. {
  54. banLength = Integer.parseInt(cmdParams[2]) * 60000L;
  55. }
  56. catch (NumberFormatException nfe)
  57. {
  58. }
  59. }
  60. }
  61. else
  62. {
  63. if (activeChar.getTarget() != null)
  64. {
  65. targetObject = activeChar.getTarget();
  66. if (targetObject instanceof L2PcInstance)
  67. targetPlayer = (L2PcInstance) targetObject;
  68. }
  69. }
  70. if (targetPlayer == null)
  71. {
  72. activeChar.sendMessage("Incorrect parameter or target.");
  73. return false;
  74. }
  75. if (command.startsWith("admin_banchat"))
  76. {
  77. String banLengthStr = "";
  78. if (banLength > -1)
  79. {
  80. targetPlayer.setChatUnbanTask(ThreadPoolManager.getInstance().scheduleGeneral(new SchedChatUnban(targetPlayer, activeChar), banLength));
  81. banLengthStr = " for " + banLength + " seconds.";
  82. }
  83. activeChar.sendMessage(targetPlayer.getName() + " is now chat banned" + banLengthStr + ".");
  84. targetPlayer.setChatBanned(true);
  85. }
  86. else if (command.startsWith("admin_unbanchat"))
  87. {
  88. activeChar.sendMessage(targetPlayer.getName() + "'s chat ban has now been lifted.");
  89. targetPlayer.setChatBanned(false);
  90. }
  91. return true;
  92. }
  93. public String[] getAdminCommandList()
  94. {
  95. return ADMIN_COMMANDS;
  96. }
  97. private class SchedChatUnban implements Runnable
  98. {
  99. L2PcInstance _player;
  100. L2PcInstance _banner;
  101. protected SchedChatUnban(L2PcInstance player, L2PcInstance banner)
  102. {
  103. _player = player;
  104. _banner = banner;
  105. }
  106. public void run()
  107. {
  108. _player.setChatBanned(false);
  109. }
  110. }
  111. }