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 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. * @param player
  63. * @param hidden
  64. */
  65. public void addGm(L2PcInstance player, boolean hidden)
  66. {
  67. if (Config.DEBUG)
  68. _log.fine("added gm: " + player.getName());
  69. _gmList.put(player, hidden);
  70. }
  71. public void deleteGm(L2PcInstance player)
  72. {
  73. if (Config.DEBUG)
  74. _log.fine("deleted gm: " + player.getName());
  75. _gmList.remove(player);
  76. }
  77. /**
  78. * GM will be displayed on clients gmlist
  79. * @param player
  80. */
  81. public void showGm(L2PcInstance player)
  82. {
  83. FastMap.Entry<L2PcInstance, Boolean> gm = _gmList.getEntry(player);
  84. if (gm != null)
  85. 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)
  95. gm.setValue(true);
  96. }
  97. public boolean isGmOnline(boolean includeHidden)
  98. {
  99. for (FastMap.Entry<L2PcInstance, Boolean> n = _gmList.head(), end = _gmList.tail(); (n = n.getNext()) != end;)
  100. {
  101. if (includeHidden || !n.getValue())
  102. return true;
  103. }
  104. return false;
  105. }
  106. public void sendListToPlayer(L2PcInstance player)
  107. {
  108. if (isGmOnline(player.isGM()))
  109. {
  110. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.GM_LIST));
  111. for (String name : getAllGmNames(player.isGM()))
  112. {
  113. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.GM_C1);
  114. sm.addString(name);
  115. player.sendPacket(sm);
  116. }
  117. }
  118. else
  119. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_GM_PROVIDING_SERVICE_NOW));
  120. }
  121. public static void broadcastToGMs(L2GameServerPacket packet)
  122. {
  123. for (L2PcInstance gm : getInstance().getAllGms(true))
  124. gm.sendPacket(packet);
  125. }
  126. public static void broadcastMessageToGMs(String message)
  127. {
  128. for (L2PcInstance gm : getInstance().getAllGms(true))
  129. gm.sendMessage(message);
  130. }
  131. @SuppressWarnings("synthetic-access")
  132. private static class SingletonHolder
  133. {
  134. protected static final GmListTable _instance = new GmListTable();
  135. }
  136. }