GmListTable.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2, or (at your option)
  5. * any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. * 02111-1307, USA.
  16. *
  17. * http://www.gnu.org/copyleft/gpl.html
  18. */
  19. package net.sf.l2j.gameserver;
  20. import javolution.util.FastList;
  21. import javolution.util.FastMap;
  22. import java.util.logging.Logger;
  23. import net.sf.l2j.Config;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25. import net.sf.l2j.gameserver.network.SystemMessageId;
  26. import net.sf.l2j.gameserver.serverpackets.L2GameServerPacket;
  27. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  28. /**
  29. * This class stores references to all online game masters. (access level > 100)
  30. *
  31. * @version $Revision: 1.2.2.1.2.7 $ $Date: 2005/04/05 19:41:24 $
  32. */
  33. public class GmListTable
  34. {
  35. private static Logger _log = Logger.getLogger(GmListTable.class.getName());
  36. private static GmListTable _instance;
  37. /** Set(L2PcInstance>) containing all the GM in game */
  38. private FastMap<L2PcInstance, Boolean> _gmList;
  39. public static GmListTable getInstance()
  40. {
  41. if (_instance == null)
  42. {
  43. _instance = new GmListTable();
  44. }
  45. return _instance;
  46. }
  47. public FastList<L2PcInstance> getAllGms(boolean includeHidden)
  48. {
  49. FastList<L2PcInstance> tmpGmList = new FastList<L2PcInstance>();
  50. for (FastMap.Entry<L2PcInstance, Boolean> n = _gmList.head(), end = _gmList.tail(); (n = n.getNext())!=end;)
  51. if (includeHidden || !n.getValue())
  52. tmpGmList.add(n.getKey());
  53. return tmpGmList;
  54. }
  55. public FastList<String> getAllGmNames(boolean includeHidden)
  56. {
  57. FastList<String> tmpGmList = new FastList<String>();
  58. for (FastMap.Entry<L2PcInstance, Boolean> n = _gmList.head(), end = _gmList.tail(); (n = n.getNext())!=end;)
  59. if (!n.getValue())
  60. tmpGmList.add(n.getKey().getName());
  61. else if (includeHidden)
  62. tmpGmList.add(n.getKey().getName()+" (invis)");
  63. return tmpGmList;
  64. }
  65. private GmListTable()
  66. {
  67. _gmList = new FastMap<L2PcInstance,Boolean>().setShared(true);
  68. }
  69. /**
  70. * Add a L2PcInstance player to the Set _gmList
  71. */
  72. public void addGm(L2PcInstance player, boolean hidden)
  73. {
  74. if (Config.DEBUG) _log.fine("added gm: "+player.getName());
  75. _gmList.put(player,hidden);
  76. }
  77. public void deleteGm(L2PcInstance player)
  78. {
  79. if (Config.DEBUG) _log.fine("deleted gm: "+player.getName());
  80. _gmList.remove(player);
  81. }
  82. /**
  83. * GM will be displayed on clients gmlist
  84. * @param player
  85. */
  86. public void showGm(L2PcInstance player)
  87. {
  88. FastMap.Entry<L2PcInstance, Boolean> gm = _gmList.getEntry(player);
  89. if (gm != null) gm.setValue(false);
  90. }
  91. /**
  92. * GM will no longer be displayed on clients gmlist
  93. * @param player
  94. */
  95. public void hideGm(L2PcInstance player)
  96. {
  97. FastMap.Entry<L2PcInstance, Boolean> gm = _gmList.getEntry(player);
  98. if (gm != null) gm.setValue(true);
  99. }
  100. public boolean isGmOnline(boolean includeHidden)
  101. {
  102. for (FastMap.Entry<L2PcInstance, Boolean> n = _gmList.head(), end = _gmList.tail(); (n = n.getNext())!=end;)
  103. {
  104. if (includeHidden || !n.getValue())
  105. return true;
  106. }
  107. return false;
  108. }
  109. public void sendListToPlayer (L2PcInstance player)
  110. {
  111. if (!isGmOnline(player.isGM()))
  112. {
  113. SystemMessage sm = new SystemMessage(SystemMessageId.NO_GM_PROVIDING_SERVICE_NOW); //There are not any GMs that are providing customer service currently.
  114. player.sendPacket(sm);
  115. } else
  116. {
  117. SystemMessage sm = new SystemMessage(SystemMessageId.GM_LIST);
  118. player.sendPacket(sm);
  119. for (String name : getAllGmNames(player.isGM()))
  120. {
  121. sm = new SystemMessage(SystemMessageId.GM_S1);
  122. sm.addString(name);
  123. player.sendPacket(sm);
  124. }
  125. }
  126. }
  127. public static void broadcastToGMs(L2GameServerPacket packet)
  128. {
  129. for (L2PcInstance gm : getInstance().getAllGms(true))
  130. {
  131. gm.sendPacket(packet);
  132. }
  133. }
  134. public static void broadcastMessageToGMs(String message)
  135. {
  136. for (L2PcInstance gm : getInstance().getAllGms(true))
  137. {
  138. gm.sendPacket(SystemMessage.sendString(message));
  139. }
  140. }
  141. }