PartyMatchRoomList.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model;
  20. import java.util.Map;
  21. import java.util.concurrent.ConcurrentHashMap;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. import com.l2jserver.gameserver.network.serverpackets.ExClosePartyRoom;
  25. /**
  26. * @author Gnacik
  27. */
  28. public class PartyMatchRoomList
  29. {
  30. private int _maxid = 1;
  31. private final Map<Integer, PartyMatchRoom> _rooms;
  32. protected PartyMatchRoomList()
  33. {
  34. _rooms = new ConcurrentHashMap<>();
  35. }
  36. public synchronized void addPartyMatchRoom(int id, PartyMatchRoom room)
  37. {
  38. _rooms.put(id, room);
  39. _maxid++;
  40. }
  41. public void deleteRoom(int id)
  42. {
  43. for (L2PcInstance _member : getRoom(id).getPartyMembers())
  44. {
  45. if (_member == null)
  46. {
  47. continue;
  48. }
  49. _member.sendPacket(new ExClosePartyRoom());
  50. _member.sendPacket(SystemMessageId.PARTY_ROOM_DISBANDED);
  51. _member.setPartyRoom(0);
  52. // _member.setPartyMatching(0);
  53. _member.broadcastUserInfo();
  54. }
  55. _rooms.remove(id);
  56. }
  57. public PartyMatchRoom getRoom(int id)
  58. {
  59. return _rooms.get(id);
  60. }
  61. public PartyMatchRoom[] getRooms()
  62. {
  63. return _rooms.values().toArray(new PartyMatchRoom[_rooms.size()]);
  64. }
  65. public int getPartyMatchRoomCount()
  66. {
  67. return _rooms.size();
  68. }
  69. public int getMaxId()
  70. {
  71. return _maxid;
  72. }
  73. public PartyMatchRoom getPlayerRoom(L2PcInstance player)
  74. {
  75. for (PartyMatchRoom _room : _rooms.values())
  76. {
  77. for (L2PcInstance member : _room.getPartyMembers())
  78. {
  79. if (member.equals(player))
  80. {
  81. return _room;
  82. }
  83. }
  84. }
  85. return null;
  86. }
  87. public int getPlayerRoomId(L2PcInstance player)
  88. {
  89. for (PartyMatchRoom _room : _rooms.values())
  90. {
  91. for (L2PcInstance member : _room.getPartyMembers())
  92. {
  93. if (member.equals(player))
  94. {
  95. return _room.getId();
  96. }
  97. }
  98. }
  99. return -1;
  100. }
  101. public static PartyMatchRoomList getInstance()
  102. {
  103. return SingletonHolder._instance;
  104. }
  105. private static class SingletonHolder
  106. {
  107. protected static final PartyMatchRoomList _instance = new PartyMatchRoomList();
  108. }
  109. }