ChatTell.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.chathandlers;
  16. import net.sf.l2j.Config;
  17. import net.sf.l2j.gameserver.handler.IChatHandler;
  18. import net.sf.l2j.gameserver.model.BlockList;
  19. import net.sf.l2j.gameserver.model.L2World;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  21. import net.sf.l2j.gameserver.network.SystemMessageId;
  22. import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  23. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  24. /**
  25. * A chat handler
  26. *
  27. * @author durgus
  28. */
  29. public class ChatTell implements IChatHandler
  30. {
  31. private static final int[] COMMAND_IDS =
  32. {
  33. 2
  34. };
  35. /**
  36. * Handle chat type 'tell'
  37. * @see net.sf.l2j.gameserver.handler.IChatHandler#handleChat(int, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
  38. */
  39. public void handleChat(int type, L2PcInstance activeChar, String target, String text)
  40. {
  41. // Return if no target is set
  42. if (target == null)
  43. return;
  44. CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
  45. L2PcInstance receiver = null;
  46. receiver = L2World.getInstance().getPlayer(target);
  47. if (receiver != null && !BlockList.isBlocked(receiver, activeChar))
  48. {
  49. if (Config.JAIL_DISABLE_CHAT && receiver.isInJail())
  50. {
  51. activeChar.sendMessage("Player is in jail.");
  52. return;
  53. }
  54. if (receiver.isChatBanned())
  55. {
  56. activeChar.sendMessage("Player is chat banned.");
  57. return;
  58. }
  59. if (!receiver.getMessageRefusal())
  60. {
  61. receiver.sendPacket(cs);
  62. activeChar.sendPacket(new CreatureSay(activeChar.getObjectId(), type, "->" + receiver.getName(), text));
  63. }
  64. else
  65. {
  66. activeChar.sendPacket(new SystemMessage(SystemMessageId.THE_PERSON_IS_IN_MESSAGE_REFUSAL_MODE));
  67. }
  68. }
  69. else
  70. {
  71. SystemMessage sm = new SystemMessage(SystemMessageId.S1_IS_NOT_ONLINE);
  72. sm.addString(target);
  73. activeChar.sendPacket(sm);
  74. sm = null;
  75. }
  76. }
  77. /**
  78. * Returns the chat types registered to this handler
  79. * @see net.sf.l2j.gameserver.handler.IChatHandler#getChatTypeList()
  80. */
  81. public int[] getChatTypeList()
  82. {
  83. return COMMAND_IDS;
  84. }
  85. }