ChatTell.java 2.8 KB

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