ChatAdmin.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 handlers.voicedcommandhandlers;
  20. import java.util.StringTokenizer;
  21. import com.l2jserver.gameserver.data.sql.impl.CharNameTable;
  22. import com.l2jserver.gameserver.data.xml.impl.AdminData;
  23. import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
  24. import com.l2jserver.gameserver.instancemanager.PunishmentManager;
  25. import com.l2jserver.gameserver.model.L2World;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.punishment.PunishmentAffect;
  28. import com.l2jserver.gameserver.model.punishment.PunishmentTask;
  29. import com.l2jserver.gameserver.model.punishment.PunishmentType;
  30. import com.l2jserver.gameserver.util.Util;
  31. public class ChatAdmin implements IVoicedCommandHandler
  32. {
  33. private static final String[] VOICED_COMMANDS =
  34. {
  35. "banchat",
  36. "unbanchat"
  37. };
  38. @Override
  39. public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
  40. {
  41. if (!AdminData.getInstance().hasAccess(command, activeChar.getAccessLevel()))
  42. {
  43. return false;
  44. }
  45. if (command.equals(VOICED_COMMANDS[0])) // banchat
  46. {
  47. if (params == null)
  48. {
  49. activeChar.sendMessage("Usage: .banchat name [minutes]");
  50. return true;
  51. }
  52. StringTokenizer st = new StringTokenizer(params);
  53. if (st.hasMoreTokens())
  54. {
  55. String name = st.nextToken();
  56. long expirationTime = 0;
  57. if (st.hasMoreTokens())
  58. {
  59. String token = st.nextToken();
  60. if (Util.isDigit(token))
  61. {
  62. expirationTime = System.currentTimeMillis() + (Integer.parseInt(st.nextToken()) * 60 * 1000);
  63. }
  64. }
  65. int objId = CharNameTable.getInstance().getIdByName(name);
  66. if (objId > 0)
  67. {
  68. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  69. if ((player == null) || !player.isOnline())
  70. {
  71. activeChar.sendMessage("Player not online !");
  72. return false;
  73. }
  74. if (player.isChatBanned())
  75. {
  76. activeChar.sendMessage("Player is already punished !");
  77. return false;
  78. }
  79. if (player == activeChar)
  80. {
  81. activeChar.sendMessage("You can't ban yourself !");
  82. return false;
  83. }
  84. if (player.isGM())
  85. {
  86. activeChar.sendMessage("You can't ban GM !");
  87. return false;
  88. }
  89. if (AdminData.getInstance().hasAccess(command, player.getAccessLevel()))
  90. {
  91. activeChar.sendMessage("You can't ban moderator !");
  92. return false;
  93. }
  94. PunishmentManager.getInstance().startPunishment(new PunishmentTask(objId, PunishmentAffect.CHARACTER, PunishmentType.CHAT_BAN, expirationTime, "Chat banned by moderator", activeChar.getName()));
  95. player.sendMessage("Chat banned by moderator " + activeChar.getName());
  96. if (expirationTime > 0)
  97. {
  98. activeChar.sendMessage("Player " + player.getName() + " chat banned for " + expirationTime + " minutes.");
  99. }
  100. else
  101. {
  102. activeChar.sendMessage("Player " + player.getName() + " chat banned forever.");
  103. }
  104. }
  105. else
  106. {
  107. activeChar.sendMessage("Player not found !");
  108. return false;
  109. }
  110. }
  111. }
  112. else if (command.equals(VOICED_COMMANDS[1])) // unbanchat
  113. {
  114. if (params == null)
  115. {
  116. activeChar.sendMessage("Usage: .unbanchat name");
  117. return true;
  118. }
  119. StringTokenizer st = new StringTokenizer(params);
  120. if (st.hasMoreTokens())
  121. {
  122. String name = st.nextToken();
  123. int objId = CharNameTable.getInstance().getIdByName(name);
  124. if (objId > 0)
  125. {
  126. L2PcInstance player = L2World.getInstance().getPlayer(objId);
  127. if ((player == null) || !player.isOnline())
  128. {
  129. activeChar.sendMessage("Player not online !");
  130. return false;
  131. }
  132. if (!player.isChatBanned())
  133. {
  134. activeChar.sendMessage("Player is not chat banned !");
  135. return false;
  136. }
  137. PunishmentManager.getInstance().stopPunishment(objId, PunishmentAffect.CHARACTER, PunishmentType.CHAT_BAN);
  138. activeChar.sendMessage("Player " + player.getName() + " chat unbanned.");
  139. player.sendMessage("Chat unbanned by moderator " + activeChar.getName());
  140. }
  141. else
  142. {
  143. activeChar.sendMessage("Player not found !");
  144. return false;
  145. }
  146. }
  147. }
  148. return true;
  149. }
  150. @Override
  151. public String[] getVoicedCommandList()
  152. {
  153. return VOICED_COMMANDS;
  154. }
  155. }