TvTEventTeam.java 4.1 KB

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