GmListTable.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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;
  16. import java.util.logging.Logger;
  17. import javolution.util.FastList;
  18. import javolution.util.FastMap;
  19. import net.sf.l2j.Config;
  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.L2GameServerPacket;
  23. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  24. /**
  25. * This class stores references to all online game masters. (access level > 100)
  26. *
  27. * @version $Revision: 1.2.2.1.2.7 $ $Date: 2005/04/05 19:41:24 $
  28. */
  29. public class GmListTable
  30. {
  31. private static Logger _log = Logger.getLogger(GmListTable.class.getName());
  32. private static GmListTable _instance;
  33. /** Set(L2PcInstance>) containing all the GM in game */
  34. private FastMap<L2PcInstance, Boolean> _gmList;
  35. public static GmListTable getInstance()
  36. {
  37. if (_instance == null)
  38. {
  39. _instance = new GmListTable();
  40. }
  41. return _instance;
  42. }
  43. public FastList<L2PcInstance> getAllGms(boolean includeHidden)
  44. {
  45. FastList<L2PcInstance> tmpGmList = new FastList<L2PcInstance>();
  46. for (FastMap.Entry<L2PcInstance, Boolean> n = _gmList.head(), end = _gmList.tail(); (n = n.getNext())!=end;)
  47. if (includeHidden || !n.getValue())
  48. tmpGmList.add(n.getKey());
  49. return tmpGmList;
  50. }
  51. public FastList<String> getAllGmNames(boolean includeHidden)
  52. {
  53. FastList<String> tmpGmList = new FastList<String>();
  54. for (FastMap.Entry<L2PcInstance, Boolean> n = _gmList.head(), end = _gmList.tail(); (n = n.getNext())!=end;)
  55. if (!n.getValue())
  56. tmpGmList.add(n.getKey().getName());
  57. else if (includeHidden)
  58. tmpGmList.add(n.getKey().getName()+" (invis)");
  59. return tmpGmList;
  60. }
  61. private GmListTable()
  62. {
  63. _gmList = new FastMap<L2PcInstance,Boolean>().setShared(true);
  64. }
  65. /**
  66. * Add a L2PcInstance player to the Set _gmList
  67. */
  68. public void addGm(L2PcInstance player, boolean hidden)
  69. {
  70. if (Config.DEBUG) _log.fine("added gm: "+player.getName());
  71. _gmList.put(player,hidden);
  72. }
  73. public void deleteGm(L2PcInstance player)
  74. {
  75. if (Config.DEBUG) _log.fine("deleted gm: "+player.getName());
  76. _gmList.remove(player);
  77. }
  78. /**
  79. * GM will be displayed on clients gmlist
  80. * @param player
  81. */
  82. public void showGm(L2PcInstance player)
  83. {
  84. FastMap.Entry<L2PcInstance, Boolean> gm = _gmList.getEntry(player);
  85. if (gm != null) gm.setValue(false);
  86. }
  87. /**
  88. * GM will no longer be displayed on clients gmlist
  89. * @param player
  90. */
  91. public void hideGm(L2PcInstance player)
  92. {
  93. FastMap.Entry<L2PcInstance, Boolean> gm = _gmList.getEntry(player);
  94. if (gm != null) gm.setValue(true);
  95. }
  96. public boolean isGmOnline(boolean includeHidden)
  97. {
  98. for (FastMap.Entry<L2PcInstance, Boolean> n = _gmList.head(), end = _gmList.tail(); (n = n.getNext())!=end;)
  99. {
  100. if (includeHidden || !n.getValue())
  101. return true;
  102. }
  103. return false;
  104. }
  105. public void sendListToPlayer (L2PcInstance player)
  106. {
  107. if (!isGmOnline(player.isGM()))
  108. {
  109. SystemMessage sm = new SystemMessage(SystemMessageId.NO_GM_PROVIDING_SERVICE_NOW); //There are not any GMs that are providing customer service currently.
  110. player.sendPacket(sm);
  111. } else
  112. {
  113. SystemMessage sm = new SystemMessage(SystemMessageId.GM_LIST);
  114. player.sendPacket(sm);
  115. for (String name : getAllGmNames(player.isGM()))
  116. {
  117. sm = new SystemMessage(SystemMessageId.GM_S1);
  118. sm.addString(name);
  119. player.sendPacket(sm);
  120. }
  121. }
  122. }
  123. public static void broadcastToGMs(L2GameServerPacket packet)
  124. {
  125. for (L2PcInstance gm : getInstance().getAllGms(true))
  126. {
  127. gm.sendPacket(packet);
  128. }
  129. }
  130. public static void broadcastMessageToGMs(String message)
  131. {
  132. for (L2PcInstance gm : getInstance().getAllGms(true))
  133. {
  134. gm.sendPacket(SystemMessage.sendString(message));
  135. }
  136. }
  137. }