criss28282

Untitled

Jun 12th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2004-2013 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.  
  21. import java.util.Collection;
  22.  
  23. import l2r.Config;
  24. import l2r.gameserver.enums.PcCondOverride;
  25. import l2r.gameserver.handler.IChatHandler;
  26. import l2r.gameserver.instancemanager.MapRegionManager;
  27. import l2r.gameserver.model.BlockList;
  28. import l2r.gameserver.model.L2World;
  29. import l2r.gameserver.model.actor.instance.L2PcInstance;
  30. import l2r.gameserver.network.SystemMessageId;
  31. import l2r.gameserver.network.serverpackets.CreatureSay;
  32. import l2r.gameserver.util.Util;
  33.  
  34. /**
  35. * Shout chat handler.
  36. * @author durgus
  37. */
  38. public class ChatShout implements IChatHandler
  39. {
  40. private static final int[] COMMAND_IDS =
  41. {
  42. 1
  43. };
  44.  
  45. /**
  46. * Handle chat type 'shout'
  47. */
  48. @Override
  49. public void handleChat(int type, L2PcInstance activeChar, String target, String text)
  50. {
  51. if (activeChar.isInOlympiadMode() && !activeChar.isGM() && Config.ENABLE_OLY_ANTIFEED)
  52. {
  53. return;
  54. }
  55.  
  56. if (activeChar.isChatBanned() && Util.contains(Config.BAN_CHAT_CHANNELS, type))
  57. {
  58. activeChar.sendPacket(SystemMessageId.CHATTING_IS_CURRENTLY_PROHIBITED);
  59. return;
  60. }
  61.  
  62. if (!activeChar.canOverrideCond(PcCondOverride.CHAT_CONDITIONS) && !activeChar.getFloodProtectors().getGlobalChat().tryPerformAction("global chat"))
  63. {
  64. activeChar.sendMessage("Do not spam shout channel.");
  65. return;
  66. }
  67.  
  68. CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
  69. CreatureSay cs2 = new CreatureSay(activeChar.getObjectId(), type, activeChar.getVar("namePrefix", "") + activeChar.getName(), text);
  70.  
  71. Collection<L2PcInstance> pls = L2World.getInstance().getPlayers();
  72.  
  73. if (Config.DEFAULT_GLOBAL_CHAT.equalsIgnoreCase("on") || (Config.DEFAULT_GLOBAL_CHAT.equalsIgnoreCase("gm") && activeChar.canOverrideCond(PcCondOverride.CHAT_CONDITIONS)))
  74. {
  75. int region = MapRegionManager.getInstance().getMapRegionLocId(activeChar);
  76. for (L2PcInstance player : pls)
  77. {
  78. if ((region == MapRegionManager.getInstance().getMapRegionLocId(player)) && !BlockList.isBlocked(player, activeChar) && (player.getInstanceId() == activeChar.getInstanceId()))
  79. {
  80. player.sendPacket(cs);
  81. }
  82. }
  83. }
  84. else if (Config.DEFAULT_GLOBAL_CHAT.equalsIgnoreCase("custom"))
  85. {
  86. if (activeChar.isGM())
  87. {
  88. for (L2PcInstance player : pls)
  89. {
  90. player.sendPacket(cs2);
  91. }
  92. }
  93.  
  94. else if (!activeChar.isGM())
  95. {
  96. int region = MapRegionManager.getInstance().getMapRegionLocId(activeChar);
  97. for (L2PcInstance player : pls)
  98. {
  99. if (player.isGM())
  100. {
  101. player.sendPacket(cs);
  102. }
  103. else if (!player.isGM())
  104. {
  105. if ((region == MapRegionManager.getInstance().getMapRegionLocId(player)) && !BlockList.isBlocked(player, activeChar) && (player.getInstanceId() == activeChar.getInstanceId()))
  106. {
  107. player.sendPacket(cs);
  108. }
  109. }
  110. }
  111. }
  112. }
  113. else if (Config.DEFAULT_GLOBAL_CHAT.equalsIgnoreCase("global"))
  114. {
  115. for (L2PcInstance player : pls)
  116. {
  117. if (!BlockList.isBlocked(player, activeChar))
  118. {
  119. player.sendPacket(cs);
  120. }
  121. }
  122. }
  123. }
  124.  
  125. /**
  126. * Returns the chat types registered to this handler.
  127. */
  128. @Override
  129. public int[] getChatTypeList()
  130. {
  131. return COMMAND_IDS;
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment