Fixes bug where coop or trusted could sethomes on other islands

https://github.com/BentoBoxWorld/BentoBox/issues/588
This commit is contained in:
tastybento 2019-03-13 00:01:23 -07:00
parent 8ad546df6f
commit 60b075c668
3 changed files with 17 additions and 16 deletions

View File

@ -28,7 +28,7 @@ public class IslandSethomeCommand extends ConfirmableCommand {
user.sendMessage("general.errors.no-island");
return false;
}
if (!getPlugin().getIslands().userIsOnIsland(user.getWorld(), user)) {
if (!getPlugin().getIslands().locationIsOnIsland(user.getPlayer(), user.getLocation())) {
user.sendMessage("commands.island.sethome.must-be-on-your-island");
return false;
}

View File

@ -797,7 +797,7 @@ public class IslandsManager {
}
/**
* Checks if an online player is in the protected area of an island he owns or he is part of.
* Checks if an online player is in the protected area of an island he owns or he is part of. i.e. rank is > VISITOR_RANK
*
* @param world the World to check. Typically this is the user's world. Does not check nether or end worlds. If null the method will always return {@code false}.
* @param user the User to check, if null or if this is not a Player the method will always return {@code false}.

View File

@ -118,7 +118,7 @@ public class IslandSethomeCommandTest {
// Number of homes default
when(iwm.getMaxHomes(Mockito.any())).thenReturn(3);
when(plugin.getIWM()).thenReturn(iwm);
// Number of homes
PowerMockito.mockStatic(Util.class);
// 1 home for now
@ -156,26 +156,27 @@ public class IslandSethomeCommandTest {
assertFalse(isc.canExecute(user, "island", Collections.emptyList()));
Mockito.verify(user).sendMessage("general.errors.no-island");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteNotOnIsland() {
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
when(im.locationIsOnIsland(Mockito.any(), Mockito.any())).thenReturn(false);
IslandSethomeCommand isc = new IslandSethomeCommand(ic);
assertFalse(isc.canExecute(user, "island", Collections.emptyList()));
Mockito.verify(user, Mockito.never()).sendMessage("general.errors.no-island");
Mockito.verify(user).sendMessage("commands.island.sethome.must-be-on-your-island");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecute() {
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
when(im.userIsOnIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
when(im.locationIsOnIsland(Mockito.any(), Mockito.any())).thenReturn(true);
IslandSethomeCommand isc = new IslandSethomeCommand(ic);
assertTrue(isc.canExecute(user, "island", Collections.emptyList()));
Mockito.verify(user, Mockito.never()).sendMessage("general.errors.no-island");
@ -191,8 +192,8 @@ public class IslandSethomeCommandTest {
assertTrue(isc.execute(user, "island", Collections.emptyList()));
Mockito.verify(user).sendMessage("commands.island.sethome.home-set");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@ -202,7 +203,7 @@ public class IslandSethomeCommandTest {
assertFalse(isc.execute(user, "island", Collections.singletonList("3")));
Mockito.verify(user).sendMessage("general.errors.no-permission");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@ -213,7 +214,7 @@ public class IslandSethomeCommandTest {
assertTrue(isc.execute(user, "island", Collections.singletonList("3")));
Mockito.verify(user).sendMessage("commands.island.sethome.home-set");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@ -235,7 +236,7 @@ public class IslandSethomeCommandTest {
assertFalse(isc.execute(user, "island", Collections.singletonList("-3")));
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.sethome.num-homes"), Mockito.eq("[number]"), Mockito.eq("5"));
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@ -261,7 +262,7 @@ public class IslandSethomeCommandTest {
assertTrue(isc.execute(user, "island", Collections.emptyList()));
Mockito.verify(user).sendMessage("commands.island.sethome.home-set");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@ -276,7 +277,7 @@ public class IslandSethomeCommandTest {
assertFalse(isc.execute(user, "island", Collections.emptyList()));
Mockito.verify(user).sendMessage("commands.island.sethome.nether.not-allowed");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@ -292,7 +293,7 @@ public class IslandSethomeCommandTest {
Mockito.verify(user).sendRawMessage(Mockito.eq("commands.island.sethome.nether.confirmation"));
Mockito.verify(user).sendMessage(Mockito.eq("commands.confirmation.confirm"), Mockito.eq("[seconds]"), Mockito.eq("0"));
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@ -307,7 +308,7 @@ public class IslandSethomeCommandTest {
assertTrue(isc.execute(user, "island", Collections.emptyList()));
Mockito.verify(user).sendMessage("commands.island.sethome.home-set");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@ -322,7 +323,7 @@ public class IslandSethomeCommandTest {
assertFalse(isc.execute(user, "island", Collections.emptyList()));
Mockito.verify(user).sendMessage("commands.island.sethome.the-end.not-allowed");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandSethomeCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/