ChatTell.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2004-2014 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.chathandlers;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.handler.IChatHandler;
  22. import com.l2jserver.gameserver.model.BlockList;
  23. import com.l2jserver.gameserver.model.L2World;
  24. import com.l2jserver.gameserver.model.PcCondOverride;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  28. import com.l2jserver.gameserver.util.Util;
  29. /**
  30. * Tell chat handler.
  31. * @author durgus
  32. */
  33. public class ChatTell implements IChatHandler
  34. {
  35. private static final int[] COMMAND_IDS =
  36. {
  37. 2
  38. };
  39. /**
  40. * Handle chat type 'tell'
  41. */
  42. @Override
  43. public void handleChat(int type, L2PcInstance activeChar, String target, String text)
  44. {
  45. if (activeChar.isChatBanned() && Util.contains(Config.BAN_CHAT_CHANNELS, type))
  46. {
  47. activeChar.sendPacket(SystemMessageId.CHATTING_IS_CURRENTLY_PROHIBITED);
  48. return;
  49. }
  50. if (Config.JAIL_DISABLE_CHAT && activeChar.isJailed() && !activeChar.canOverrideCond(PcCondOverride.CHAT_CONDITIONS))
  51. {
  52. activeChar.sendPacket(SystemMessageId.CHATTING_PROHIBITED);
  53. return;
  54. }
  55. // Return if no target is set
  56. if (target == null)
  57. {
  58. return;
  59. }
  60. CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
  61. L2PcInstance receiver = null;
  62. receiver = L2World.getInstance().getPlayer(target);
  63. if ((receiver != null) && !receiver.isSilenceMode(activeChar.getObjectId()))
  64. {
  65. if (Config.JAIL_DISABLE_CHAT && receiver.isJailed() && !activeChar.canOverrideCond(PcCondOverride.CHAT_CONDITIONS))
  66. {
  67. activeChar.sendMessage("Player is in jail.");
  68. return;
  69. }
  70. if (receiver.isChatBanned())
  71. {
  72. activeChar.sendPacket(SystemMessageId.THE_PERSON_IS_IN_MESSAGE_REFUSAL_MODE);
  73. return;
  74. }
  75. if ((receiver.getClient() == null) || receiver.getClient().isDetached())
  76. {
  77. activeChar.sendMessage("Player is in offline mode.");
  78. return;
  79. }
  80. if (!BlockList.isBlocked(receiver, activeChar))
  81. {
  82. // Allow reciever to send PMs to this char, which is in silence mode.
  83. if (Config.SILENCE_MODE_EXCLUDE && activeChar.isSilenceMode())
  84. {
  85. activeChar.addSilenceModeExcluded(receiver.getObjectId());
  86. }
  87. receiver.sendPacket(cs);
  88. activeChar.sendPacket(new CreatureSay(activeChar.getObjectId(), type, "->" + receiver.getName(), text));
  89. }
  90. else
  91. {
  92. activeChar.sendPacket(SystemMessageId.THE_PERSON_IS_IN_MESSAGE_REFUSAL_MODE);
  93. }
  94. }
  95. else
  96. {
  97. activeChar.sendPacket(SystemMessageId.TARGET_IS_NOT_FOUND_IN_THE_GAME);
  98. }
  99. }
  100. /**
  101. * Returns the chat types registered to this handler.
  102. */
  103. @Override
  104. public int[] getChatTypeList()
  105. {
  106. return COMMAND_IDS;
  107. }
  108. }