GmListTable.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 com.l2jserver.gameserver;
  16. import java.util.logging.Logger;
  17. import javolution.util.FastList;
  18. import javolution.util.FastMap;
  19. import com.l2jserver.Config;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
  23. import com.l2jserver.gameserver.network.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. /** Set(L2PcInstance>) containing all the GM in game */
  33. private FastMap<L2PcInstance, Boolean> _gmList;
  34. public static GmListTable getInstance()
  35. {
  36. return SingletonHolder._instance;
  37. }
  38. public FastList<L2PcInstance> getAllGms(boolean includeHidden)
  39. {
  40. FastList<L2PcInstance> tmpGmList = new FastList<L2PcInstance>();
  41. for (FastMap.Entry<L2PcInstance, Boolean> n = _gmList.head(), end = _gmList.tail(); (n = n.getNext()) != end;)
  42. if (includeHidden || !n.getValue())
  43. tmpGmList.add(n.getKey());
  44. return tmpGmList;
  45. }
  46. public FastList<String> getAllGmNames(boolean includeHidden)
  47. {
  48. FastList<String> tmpGmList = new FastList<String>();
  49. for (FastMap.Entry<L2PcInstance, Boolean> n = _gmList.head(), end = _gmList.tail(); (n = n.getNext()) != end;)
  50. if (!n.getValue())
  51. tmpGmList.add(n.getKey().getName());
  52. else if (includeHidden)
  53. tmpGmList.add(n.getKey().getName() + " (invis)");
  54. return tmpGmList;
  55. }
  56. private GmListTable()
  57. {
  58. _gmList = new FastMap<L2PcInstance, Boolean>().shared();
  59. }
  60. /**
  61. * Add a L2PcInstance player to the Set _gmList
  62. */
  63. public void addGm(L2PcInstance player, boolean hidden)
  64. {
  65. if (Config.DEBUG)
  66. _log.fine("added gm: " + player.getName());
  67. _gmList.put(player, hidden);
  68. }
  69. public void deleteGm(L2PcInstance player)
  70. {
  71. if (Config.DEBUG)
  72. _log.fine("deleted gm: " + player.getName());
  73. _gmList.remove(player);
  74. }
  75. /**
  76. * GM will be displayed on clients gmlist
  77. * @param player
  78. */
  79. public void showGm(L2PcInstance player)
  80. {
  81. FastMap.Entry<L2PcInstance, Boolean> gm = _gmList.getEntry(player);
  82. if (gm != null)
  83. gm.setValue(false);
  84. }
  85. /**
  86. * GM will no longer be displayed on clients gmlist
  87. * @param player
  88. */
  89. public void hideGm(L2PcInstance player)
  90. {
  91. FastMap.Entry<L2PcInstance, Boolean> gm = _gmList.getEntry(player);
  92. if (gm != null)
  93. gm.setValue(true);
  94. }
  95. public boolean isGmOnline(boolean includeHidden)
  96. {
  97. for (FastMap.Entry<L2PcInstance, Boolean> n = _gmList.head(), end = _gmList.tail(); (n = n.getNext()) != end;)
  98. {
  99. if (includeHidden || !n.getValue())
  100. return true;
  101. }
  102. return false;
  103. }
  104. public void sendListToPlayer(L2PcInstance player)
  105. {
  106. if (isGmOnline(player.isGM()))
  107. {
  108. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.GM_LIST));
  109. for (String name : getAllGmNames(player.isGM()))
  110. {
  111. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.GM_C1);
  112. sm.addString(name);
  113. player.sendPacket(sm);
  114. }
  115. }
  116. else
  117. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_GM_PROVIDING_SERVICE_NOW));
  118. }
  119. public static void broadcastToGMs(L2GameServerPacket packet)
  120. {
  121. for (L2PcInstance gm : getInstance().getAllGms(true))
  122. gm.sendPacket(packet);
  123. }
  124. public static void broadcastMessageToGMs(String message)
  125. {
  126. for (L2PcInstance gm : getInstance().getAllGms(true))
  127. gm.sendMessage(message);
  128. }
  129. @SuppressWarnings("synthetic-access")
  130. private static class SingletonHolder
  131. {
  132. protected static final GmListTable _instance = new GmListTable();
  133. }
  134. }