mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-26 02:57:59 +01:00
Improves API and JavaDocs for getMembers (#628)
* Improves API and JavaDocs for getMembers https://github.com/BentoBoxWorld/BentoBox/issues/627 * Fixed indentation in Island
This commit is contained in:
parent
aeb0e7d4fa
commit
f5ad5aa2c9
@ -246,9 +246,9 @@ public class Island implements DataObject {
|
||||
|
||||
/**
|
||||
* Returns the members of this island.
|
||||
* It contains any player which has one of the following rank on this island: {@link RanksManager#COOP_RANK COOP},
|
||||
* It contains all players that have any rank on this island, including {@link RanksManager#BANNED},
|
||||
* {@link RanksManager#TRUSTED_RANK TRUSTED}, {@link RanksManager#MEMBER_RANK MEMBER}, {@link RanksManager#SUB_OWNER_RANK SUB_OWNER},
|
||||
* {@link RanksManager#OWNER_RANK OWNER}.
|
||||
* {@link RanksManager#OWNER_RANK OWNER}, etc.
|
||||
*
|
||||
* @return the members - key is the UUID, value is the RanksManager enum, e.g. {@link RanksManager#MEMBER_RANK}.
|
||||
* @see #getMemberSet()
|
||||
@ -265,13 +265,19 @@ public class Island implements DataObject {
|
||||
* @see #getMembers()
|
||||
*/
|
||||
public ImmutableSet<UUID> getMemberSet(){
|
||||
Builder<UUID> result = new ImmutableSet.Builder<>();
|
||||
return (getMemberSet(RanksManager.MEMBER_RANK));
|
||||
}
|
||||
|
||||
for (Entry<UUID, Integer> member: members.entrySet()) {
|
||||
if (member.getValue() >= RanksManager.MEMBER_RANK) {
|
||||
result.add(member.getKey());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns an immutable set containing the UUIDs of players with rank above that requested rank inclusive
|
||||
* @param minimumRank - minimum rank (inclusive) of members
|
||||
* @return immutable set of UUIDs
|
||||
* @see #getMembers()
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public @NonNull ImmutableSet<UUID> getMemberSet(@NonNull int minimumRank) {
|
||||
Builder<UUID> result = new ImmutableSet.Builder<>();
|
||||
members.entrySet().stream().filter(e -> e.getValue() >= minimumRank).map(Map.Entry::getKey).forEach(result::add);
|
||||
return result.build();
|
||||
}
|
||||
|
||||
|
@ -391,7 +391,22 @@ public class IslandsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of island member UUID's for the island of playerUUID
|
||||
* Returns a set of island member UUID's for the island of playerUUID of rank <tt>minimumRank</tt>
|
||||
* and above.
|
||||
* This includes the owner of the island. If there is no island, this set will be empty.
|
||||
*
|
||||
* @param world - world to check
|
||||
* @param playerUUID - the player's UUID
|
||||
* @param minimumRank - the minimum rank to be included in the set.
|
||||
* @return Set of team UUIDs
|
||||
*/
|
||||
public Set<UUID> getMembers(World world, UUID playerUUID, int minimumRank) {
|
||||
return islandCache.getMembers(world, playerUUID, minimumRank);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of island member UUID's for the island of playerUUID.
|
||||
* Only includes players of rank {@link RanksManager.MEMBER_RANK} and above.
|
||||
* This includes the owner of the island. If there is no island, this set will be empty.
|
||||
*
|
||||
* @param world - world to check
|
||||
@ -399,7 +414,7 @@ public class IslandsManager {
|
||||
* @return Set of team UUIDs
|
||||
*/
|
||||
public Set<UUID> getMembers(World world, UUID playerUUID) {
|
||||
return islandCache.getMembers(world, playerUUID);
|
||||
return islandCache.getMembers(world, playerUUID, RanksManager.MEMBER_RANK);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,14 +161,15 @@ public class IslandCache {
|
||||
/**
|
||||
* @param world world to check
|
||||
* @param uuid uuid of player to check
|
||||
* @param minimumRank minimum rank requested
|
||||
* @return set of UUID's of island members. If there is no island, this set will be empty
|
||||
*/
|
||||
@NonNull
|
||||
public Set<UUID> getMembers(@NonNull World world, @NonNull UUID uuid) {
|
||||
public Set<UUID> getMembers(@NonNull World world, @NonNull UUID uuid, @NonNull int minimumRank) {
|
||||
islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
|
||||
Island island = islandsByUUID.get(Util.getWorld(world)).get(uuid);
|
||||
if (island != null) {
|
||||
return island.getMemberSet();
|
||||
return island.getMemberSet(minimumRank);
|
||||
}
|
||||
return new HashSet<>(0);
|
||||
}
|
||||
|
@ -623,7 +623,7 @@ public class IslandsManagerTest {
|
||||
members.add(UUID.randomUUID());
|
||||
members.add(UUID.randomUUID());
|
||||
members.add(UUID.randomUUID());
|
||||
when(islandCache.getMembers(Mockito.any(), Mockito.any())).thenReturn(members);
|
||||
when(islandCache.getMembers(Mockito.any(), Mockito.any(), Mockito.anyInt())).thenReturn(members);
|
||||
IslandsManager im = new IslandsManager(plugin);
|
||||
im.setIslandCache(islandCache);
|
||||
assertEquals(members, im.getMembers(world, UUID.randomUUID()));
|
||||
|
@ -29,6 +29,7 @@ import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@ -76,6 +77,7 @@ public class IslandCacheTest {
|
||||
members.add(UUID.randomUUID());
|
||||
members.add(UUID.randomUUID());
|
||||
members.add(UUID.randomUUID());
|
||||
when(island.getMemberSet(Mockito.anyInt())).thenReturn(members.build());
|
||||
when(island.getMemberSet()).thenReturn(members.build());
|
||||
when(island.getMinX()).thenReturn(-200);
|
||||
when(island.getMinZ()).thenReturn(-200);
|
||||
@ -209,10 +211,10 @@ public class IslandCacheTest {
|
||||
IslandCache ic = new IslandCache();
|
||||
ic.addIsland(island);
|
||||
|
||||
assertTrue(ic.getMembers(world, null).isEmpty());
|
||||
assertTrue(ic.getMembers(world, UUID.randomUUID()).isEmpty());
|
||||
assertFalse(ic.getMembers(world, island.getOwner()).isEmpty());
|
||||
assertEquals(3, ic.getMembers(world, island.getOwner()).size());
|
||||
assertTrue(ic.getMembers(world, null, RanksManager.MEMBER_RANK).isEmpty());
|
||||
assertTrue(ic.getMembers(world, UUID.randomUUID(), RanksManager.MEMBER_RANK).isEmpty());
|
||||
assertFalse(ic.getMembers(world, island.getOwner(), RanksManager.MEMBER_RANK).isEmpty());
|
||||
assertEquals(3, ic.getMembers(world, island.getOwner(), RanksManager.MEMBER_RANK).size());
|
||||
|
||||
}
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user