PartyMatchRoomList.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.model;
  16. import java.util.Map;
  17. import javolution.util.FastMap;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.network.SystemMessageId;
  20. import com.l2jserver.gameserver.network.serverpackets.ExClosePartyRoom;
  21. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  22. /**
  23. * @author Gnacik
  24. */
  25. public class PartyMatchRoomList
  26. {
  27. private int _maxid = 1;
  28. private Map<Integer, PartyMatchRoom> _rooms;
  29. private PartyMatchRoomList()
  30. {
  31. _rooms = new FastMap<Integer, PartyMatchRoom>();
  32. }
  33. public synchronized void addPartyMatchRoom(int id, PartyMatchRoom room)
  34. {
  35. _rooms.put(id, room);
  36. _maxid++;
  37. }
  38. public void deleteRoom(int id)
  39. {
  40. for(L2PcInstance _member : getRoom(id).getPartyMembers())
  41. {
  42. if(_member == null)
  43. continue;
  44. _member.sendPacket(new ExClosePartyRoom());
  45. _member.sendPacket(new SystemMessage(SystemMessageId.PARTY_ROOM_DISBANDED));
  46. _member.setPartyRoom(0);
  47. //_member.setPartyMatching(0);
  48. _member.broadcastUserInfo();
  49. }
  50. _rooms.remove(id);
  51. }
  52. public PartyMatchRoom getRoom(int id)
  53. {
  54. return _rooms.get(id);
  55. }
  56. public PartyMatchRoom[] getRooms()
  57. {
  58. return _rooms.values().toArray(new PartyMatchRoom[_rooms.size()]);
  59. }
  60. public int getPartyMatchRoomCount()
  61. {
  62. return _rooms.size();
  63. }
  64. public int getMaxId()
  65. {
  66. return _maxid;
  67. }
  68. public PartyMatchRoom getPlayerRoom(L2PcInstance player)
  69. {
  70. for(PartyMatchRoom _room : _rooms.values())
  71. for(L2PcInstance member : _room.getPartyMembers())
  72. if(member.equals(player))
  73. return _room;
  74. return null;
  75. }
  76. public int getPlayerRoomId(L2PcInstance player)
  77. {
  78. for(PartyMatchRoom _room : _rooms.values())
  79. for(L2PcInstance member : _room.getPartyMembers())
  80. if(member.equals(player))
  81. return _room.getId();
  82. return -1;
  83. }
  84. public static PartyMatchRoomList getInstance()
  85. {
  86. return SingletonHolder._instance;
  87. }
  88. @SuppressWarnings("synthetic-access")
  89. private static class SingletonHolder
  90. {
  91. protected static final PartyMatchRoomList _instance = new PartyMatchRoomList();
  92. }
  93. }