mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-09-29 07:07:30 +02:00
Added a lot of tests to IslandManagerTest class.
This commit is contained in:
parent
0a17639529
commit
c7d9fed400
@ -30,7 +30,7 @@ public class IslandSethomeCommand extends CompositeCommand {
|
|||||||
user.sendMessage("general.errors.no-island");
|
user.sendMessage("general.errors.no-island");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!getPlugin().getIslands().playerIsOnIsland(user)) {
|
if (!getPlugin().getIslands().userIsOnIsland(user)) {
|
||||||
user.sendMessage("commands.island.sethome.must-be-on-your-island");
|
user.sendMessage("commands.island.sethome.must-be-on-your-island");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ public class ObsidianToLava implements Listener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
User user = User.getInstance(e.getPlayer());
|
User user = User.getInstance(e.getPlayer());
|
||||||
if (plugin.getIslands().playerIsOnIsland(user)) {
|
if (plugin.getIslands().userIsOnIsland(user)) {
|
||||||
// Look around to see if this is a lone obsidian block
|
// Look around to see if this is a lone obsidian block
|
||||||
Block b = e.getClickedBlock();
|
Block b = e.getClickedBlock();
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -49,13 +50,13 @@ public class IslandsManager {
|
|||||||
* - Location to be checked
|
* - Location to be checked
|
||||||
* @return true if safe, otherwise false
|
* @return true if safe, otherwise false
|
||||||
*/
|
*/
|
||||||
public boolean isSafeLocation(final Location l) {
|
public boolean isSafeLocation(Location l) {
|
||||||
if (l == null) {
|
if (l == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Block ground = l.getBlock().getRelative(BlockFace.DOWN);
|
Block ground = l.getBlock().getRelative(BlockFace.DOWN);
|
||||||
final Block space1 = l.getBlock();
|
Block space1 = l.getBlock();
|
||||||
final Block space2 = l.getBlock().getRelative(BlockFace.UP);
|
Block space2 = l.getBlock().getRelative(BlockFace.UP);
|
||||||
|
|
||||||
// Ground must be solid
|
// Ground must be solid
|
||||||
if (!ground.getType().isSolid()) {
|
if (!ground.getType().isSolid()) {
|
||||||
@ -93,8 +94,8 @@ public class IslandsManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ground.getType().equals(Material.CACTUS) || ground.getType().equals(Material.BOAT) || ground.getType().equals(Material.FENCE)
|
if (ground.getType().equals(Material.CACTUS) || ground.getType().equals(Material.BOAT) || ground.getType().toString().contains("FENCE")
|
||||||
|| ground.getType().equals(Material.NETHER_FENCE) || ground.getType().equals(Material.SIGN_POST) || ground.getType().equals(Material.WALL_SIGN)) {
|
|| ground.getType().equals(Material.SIGN_POST) || ground.getType().equals(Material.WALL_SIGN)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check that the space is not solid
|
// Check that the space is not solid
|
||||||
@ -128,6 +129,10 @@ public class IslandsManager {
|
|||||||
// Island Cache
|
// Island Cache
|
||||||
private IslandCache islandCache;
|
private IslandCache islandCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Islands Manager
|
||||||
|
* @param plugin
|
||||||
|
*/
|
||||||
public IslandsManager(BSkyBlock plugin){
|
public IslandsManager(BSkyBlock plugin){
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
// Set up the database handler to store and retrieve Island classes
|
// Set up the database handler to store and retrieve Island classes
|
||||||
@ -385,8 +390,7 @@ public class IslandsManager {
|
|||||||
if (spawn != null && spawn.onIsland(location)) {
|
if (spawn != null && spawn.onIsland(location)) {
|
||||||
return Optional.of(spawn);
|
return Optional.of(spawn);
|
||||||
}
|
}
|
||||||
Optional<Island> island = getIslandAt(location);
|
return getIslandAt(location).filter(i -> i.onIsland(location));
|
||||||
return island.map(x->x.onIsland(location) ? island.get() : null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -397,7 +401,7 @@ public class IslandsManager {
|
|||||||
* @param number - a number - starting home location e.g., 1
|
* @param number - a number - starting home location e.g., 1
|
||||||
* @return Location of a safe teleport spot or null if one cannot be found
|
* @return Location of a safe teleport spot or null if one cannot be found
|
||||||
*/
|
*/
|
||||||
public Location getSafeHomeLocation(final UUID playerUUID, int number) {
|
public Location getSafeHomeLocation(UUID playerUUID, int number) {
|
||||||
// Try the numbered home location first
|
// Try the numbered home location first
|
||||||
Location l = plugin.getPlayers().getHomeLocation(playerUUID, number);
|
Location l = plugin.getPlayers().getHomeLocation(playerUUID, number);
|
||||||
if (l == null) {
|
if (l == null) {
|
||||||
@ -568,6 +572,13 @@ public class IslandsManager {
|
|||||||
return spawn.onIsland(playerLoc);
|
return spawn.onIsland(playerLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param spawn the spawn to set
|
||||||
|
*/
|
||||||
|
public void setSpawn(Island spawn) {
|
||||||
|
this.spawn = spawn;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if there is an island or blocks at this location
|
* Checks if there is an island or blocks at this location
|
||||||
* @param location - the location
|
* @param location - the location
|
||||||
@ -575,7 +586,7 @@ public class IslandsManager {
|
|||||||
*/
|
*/
|
||||||
public boolean isIsland(Location location){
|
public boolean isIsland(Location location){
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
location = getClosestIsland(location);
|
location = getClosestIsland(location);
|
||||||
if (islandCache.getIslandAt(location) != null) {
|
if (islandCache.getIslandAt(location) != null) {
|
||||||
@ -589,7 +600,6 @@ public class IslandsManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Look around
|
// Look around
|
||||||
|
|
||||||
for (int x = -5; x <= 5; x++) {
|
for (int x = -5; x <= 5; x++) {
|
||||||
for (int y = 10; y <= 255; y++) {
|
for (int y = 10; y <= 255; y++) {
|
||||||
for (int z = -5; z <= 5; z++) {
|
for (int z = -5; z <= 5; z++) {
|
||||||
@ -617,6 +627,9 @@ public class IslandsManager {
|
|||||||
long z = Math.round((double) location.getBlockZ() / plugin.getSettings().getIslandDistance())
|
long z = Math.round((double) location.getBlockZ() / plugin.getSettings().getIslandDistance())
|
||||||
* plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandZOffset();
|
* plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandZOffset();
|
||||||
long y = plugin.getSettings().getIslandHeight();
|
long y = plugin.getSettings().getIslandHeight();
|
||||||
|
if (location.getBlockX() == x && location.getBlockZ() == z) {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
return new Location(location.getWorld(), x, y, z);
|
return new Location(location.getWorld(), x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,29 +668,9 @@ public class IslandsManager {
|
|||||||
if (player == null) {
|
if (player == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Get the player's island from the grid if it exists
|
// Get the player's island
|
||||||
Optional<Island> island = getIslandAt(loc);
|
Optional<Island> ii = getIslandAt(loc);
|
||||||
if (island.isPresent()) {
|
return getIslandAt(loc).filter(i -> i.onIsland(loc)).map(i -> i.getMemberSet().contains(player.getUniqueId())).orElse(false);
|
||||||
// Return whether the location is within the protected zone and the player is on the list of acceptable players
|
|
||||||
return island.get().onIsland(loc) && island.get().getMemberSet().contains(player.getUniqueId());
|
|
||||||
}
|
|
||||||
// Not in the grid, so do it the old way
|
|
||||||
// Make a list of test locations and test them
|
|
||||||
Set<Location> islandTestLocations = new HashSet<>();
|
|
||||||
if (plugin.getPlayers().hasIsland(player.getUniqueId()) || plugin.getPlayers().inTeam(player.getUniqueId())) {
|
|
||||||
islandTestLocations.add(getIslandLocation(player.getUniqueId()));
|
|
||||||
}
|
|
||||||
// TODO: Check any coop locations
|
|
||||||
// Run through all the locations
|
|
||||||
for (Location islandTestLocation : islandTestLocations) {
|
|
||||||
if (loc.getWorld().equals(islandTestLocation.getWorld())) {
|
|
||||||
return loc.getX() >= islandTestLocation.getX() - plugin.getSettings().getIslandProtectionRange()
|
|
||||||
&& loc.getX() < islandTestLocation.getX() + plugin.getSettings().getIslandProtectionRange()
|
|
||||||
&& loc.getZ() >= islandTestLocation.getZ() - plugin.getSettings().getIslandProtectionRange()
|
|
||||||
&& loc.getZ() < islandTestLocation.getZ() + plugin.getSettings().getIslandProtectionRange();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int metrics_getCreatedCount(){
|
public int metrics_getCreatedCount(){
|
||||||
@ -695,7 +688,10 @@ public class IslandsManager {
|
|||||||
* @param user - the User
|
* @param user - the User
|
||||||
* @return true if on valid island, false if not
|
* @return true if on valid island, false if not
|
||||||
*/
|
*/
|
||||||
public boolean playerIsOnIsland(User user) {
|
public boolean userIsOnIsland(User user) {
|
||||||
|
if (user == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return Optional.ofNullable(getIsland(user.getUniqueId())).map(i -> i.onIsland(user.getLocation())).orElse(false);
|
return Optional.ofNullable(getIsland(user.getUniqueId())).map(i -> i.onIsland(user.getLocation())).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -723,7 +719,7 @@ public class IslandsManager {
|
|||||||
*/
|
*/
|
||||||
public void removePlayersFromIsland(final Island island) {
|
public void removePlayersFromIsland(final Island island) {
|
||||||
// Teleport players away
|
// Teleport players away
|
||||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (island.inIslandSpace(player.getLocation().getBlockX(), player.getLocation().getBlockZ())) {
|
if (island.inIslandSpace(player.getLocation().getBlockX(), player.getLocation().getBlockZ())) {
|
||||||
// Teleport island players to their island home
|
// Teleport island players to their island home
|
||||||
if (plugin.getPlayers().hasIsland(player.getUniqueId()) || plugin.getPlayers().inTeam(player.getUniqueId())) {
|
if (plugin.getPlayers().hasIsland(player.getUniqueId()) || plugin.getPlayers().inTeam(player.getUniqueId())) {
|
||||||
|
@ -124,7 +124,7 @@ public class ObsidianToLavaTest {
|
|||||||
// Put player in world
|
// Put player in world
|
||||||
when(iwm.inWorld(Mockito.any())).thenReturn(true);
|
when(iwm.inWorld(Mockito.any())).thenReturn(true);
|
||||||
// Put player on island
|
// Put player on island
|
||||||
when(im.playerIsOnIsland(Mockito.any())).thenReturn(true);
|
when(im.userIsOnIsland(Mockito.any())).thenReturn(true);
|
||||||
// Set as survival
|
// Set as survival
|
||||||
when(who.getGameMode()).thenReturn(GameMode.SURVIVAL);
|
when(who.getGameMode()).thenReturn(GameMode.SURVIVAL);
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ public class ObsidianToLavaTest {
|
|||||||
when(who.getGameMode()).thenReturn(GameMode.SURVIVAL);
|
when(who.getGameMode()).thenReturn(GameMode.SURVIVAL);
|
||||||
|
|
||||||
// Test when player is not on island
|
// Test when player is not on island
|
||||||
when(im.playerIsOnIsland(Mockito.any())).thenReturn(false);
|
when(im.userIsOnIsland(Mockito.any())).thenReturn(false);
|
||||||
assertFalse(listener.onPlayerInteract(event));
|
assertFalse(listener.onPlayerInteract(event));
|
||||||
|
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user