TvTEventTeam.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.entity;
  16. import java.util.Map;
  17. import javolution.util.FastMap;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. /**
  20. * @author FBIagent
  21. */
  22. public class TvTEventTeam
  23. {
  24. /** The name of the team<br> */
  25. private final String _name;
  26. /** The team spot coordinated<br> */
  27. private int[] _coordinates = new int[3];
  28. /** The points of the team<br> */
  29. private short _points;
  30. /** Name and instance of all participated players in FastMap<br> */
  31. private Map<Integer, L2PcInstance> _participatedPlayers = new FastMap<>();
  32. /**
  33. * C'tor initialize the team<br>
  34. * <br>
  35. * @param name as String<br>
  36. * @param coordinates as int[]<br>
  37. */
  38. public TvTEventTeam(String name, int[] coordinates)
  39. {
  40. _name = name;
  41. _coordinates = coordinates;
  42. _points = 0;
  43. }
  44. /**
  45. * Adds a player to the team<br>
  46. * <br>
  47. * @param playerInstance as L2PcInstance<br>
  48. * @return boolean: true if success, otherwise false<br>
  49. */
  50. public boolean addPlayer(L2PcInstance playerInstance)
  51. {
  52. if (playerInstance == null)
  53. {
  54. return false;
  55. }
  56. synchronized (_participatedPlayers)
  57. {
  58. _participatedPlayers.put(playerInstance.getObjectId(), playerInstance);
  59. }
  60. return true;
  61. }
  62. /**
  63. * Removes a player from the team
  64. * @param playerObjectId
  65. */
  66. public void removePlayer(int playerObjectId)
  67. {
  68. synchronized (_participatedPlayers)
  69. {
  70. _participatedPlayers.remove(playerObjectId);
  71. }
  72. }
  73. /**
  74. * Increases the points of the team<br>
  75. */
  76. public void increasePoints()
  77. {
  78. ++_points;
  79. }
  80. /**
  81. * Cleanup the team and make it ready for adding players again<br>
  82. */
  83. public void cleanMe()
  84. {
  85. _participatedPlayers.clear();
  86. _participatedPlayers = new FastMap<>();
  87. _points = 0;
  88. }
  89. /**
  90. * Is given player in this team?
  91. * @param playerObjectId
  92. * @return boolean: true if player is in this team, otherwise false
  93. */
  94. public boolean containsPlayer(int playerObjectId)
  95. {
  96. boolean containsPlayer;
  97. synchronized (_participatedPlayers)
  98. {
  99. containsPlayer = _participatedPlayers.containsKey(playerObjectId);
  100. }
  101. return containsPlayer;
  102. }
  103. /**
  104. * Returns the name of the team<br>
  105. * <br>
  106. * @return String: name of the team<br>
  107. */
  108. public String getName()
  109. {
  110. return _name;
  111. }
  112. /**
  113. * Returns the coordinates of the team spot<br>
  114. * <br>
  115. * @return int[]: team coordinates<br>
  116. */
  117. public int[] getCoordinates()
  118. {
  119. return _coordinates;
  120. }
  121. /**
  122. * Returns the points of the team<br>
  123. * <br>
  124. * @return short: team points<br>
  125. */
  126. public short getPoints()
  127. {
  128. return _points;
  129. }
  130. /**
  131. * Returns name and instance of all participated players in FastMap<br>
  132. * <br>
  133. * @return Map<String, L2PcInstance>: map of players in this team<br>
  134. */
  135. public Map<Integer, L2PcInstance> getParticipatedPlayers()
  136. {
  137. Map<Integer, L2PcInstance> participatedPlayers = null;
  138. synchronized (_participatedPlayers)
  139. {
  140. participatedPlayers = _participatedPlayers;
  141. }
  142. return participatedPlayers;
  143. }
  144. /**
  145. * Returns player count of this team<br>
  146. * <br>
  147. * @return int: number of players in team<br>
  148. */
  149. public int getParticipatedPlayerCount()
  150. {
  151. int participatedPlayerCount;
  152. synchronized (_participatedPlayers)
  153. {
  154. participatedPlayerCount = _participatedPlayers.size();
  155. }
  156. return participatedPlayerCount;
  157. }
  158. }