ChatTrade.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 java.util.Collection;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.datatables.MapRegionTable;
  19. import net.sf.l2j.gameserver.handler.IChatHandler;
  20. import net.sf.l2j.gameserver.model.L2World;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  22. import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  23. import net.sf.l2j.gameserver.util.Broadcast;
  24. /**
  25. * A chat handler
  26. *
  27. * @author durgus
  28. */
  29. public class ChatTrade implements IChatHandler
  30. {
  31. private static final int[] COMMAND_IDS =
  32. {
  33. 8
  34. };
  35. /**
  36. * Handle chat type 'trade'
  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. CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
  42. if (Config.DEFAULT_TRADE_CHAT.equalsIgnoreCase("on") || (Config.DEFAULT_TRADE_CHAT.equalsIgnoreCase("gm") && activeChar.isGM()))
  43. Broadcast.toAllOnlinePlayers(cs);
  44. else if (Config.DEFAULT_TRADE_CHAT.equalsIgnoreCase("limited"))
  45. {
  46. int region = MapRegionTable.getInstance().getMapRegion(activeChar.getX(), activeChar.getY());
  47. Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
  48. //synchronized (L2World.getInstance().getAllPlayers())
  49. {
  50. for (L2PcInstance player : pls)
  51. if (region == MapRegionTable.getInstance().getMapRegion(player.getX(), player.getY()))
  52. player.sendPacket(cs);
  53. }
  54. }
  55. }
  56. /**
  57. * Returns the chat types registered to this handler
  58. * @see net.sf.l2j.gameserver.handler.IChatHandler#getChatTypeList()
  59. */
  60. public int[] getChatTypeList()
  61. {
  62. return COMMAND_IDS;
  63. }
  64. }