Added IslandsManager and IslandCache#getIslands(World)

This commit is contained in:
Florian CUNY 2019-08-28 14:21:08 +02:00
parent 4e86441f6f
commit edb6d11fc2
2 changed files with 32 additions and 1 deletions

View File

@ -356,7 +356,7 @@ public class IslandsManager {
}
/**
* Returns an <strong>unmodifiable collection</strong> of all the islands (even those who may be unowned).
* Returns an <strong>unmodifiable collection</strong> of all existing islands (even those who may be unowned).
* @return unmodifiable collection containing every island.
* @since 1.1
*/
@ -365,6 +365,17 @@ public class IslandsManager {
return islandCache.getIslands();
}
/**
* Returns an <strong>unmodifiable collection</strong> of all the islands (even those who may be unowned) in the specified world.
* @param world World of the gamemode.
* @return unmodifiable collection containing all the islands in the specified world.
* @since 1.7.0
*/
@NonNull
public Collection<Island> getIslands(@NonNull World world) {
return islandCache.getIslands(world);
}
/**
* Returns the IslandCache instance.
* @return the islandCache

View File

@ -1,12 +1,15 @@
package world.bentobox.bentobox.managers.island;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.Location;
import org.bukkit.World;
@ -158,6 +161,23 @@ public class IslandCache {
return Collections.unmodifiableCollection(islandsByLocation.values());
}
/**
* Returns an <strong>unmodifiable collection</strong> of all the islands (even those who may be unowned) in the specified world.
* @param world World of the gamemode.
* @return unmodifiable collection containing all the islands in the specified world.
* @since 1.7.0
*/
@NonNull
public Collection<Island> getIslands(@NonNull World world) {
World overworld = Util.getWorld(world);
List<Island> islandsInWorld = islandsByLocation.entrySet().stream()
.filter(entry -> overworld.equals(Util.getWorld(entry.getKey().getWorld()))) // shouldn't make NPEs
.map(Map.Entry::getValue)
.collect(Collectors.toCollection(ArrayList::new));
return Collections.unmodifiableCollection(islandsInWorld);
}
/**
* @param world world to check
* @param uuid uuid of player to check