Admin team add command was not adding players correctly.

Fixes https://github.com/BentoBoxWorld/BentoBox/issues/506

Also, admin unregister was blocking unregistration of team players, but
that is an artificial constraint, so I enabled it. Without it, it would
not be possible to correct weird team issues like this one after they
happen.
This commit is contained in:
tastybento 2019-01-30 17:27:53 -08:00
parent 804d0f9878
commit 8dbf7ec231
4 changed files with 15 additions and 24 deletions

View File

@ -36,14 +36,11 @@ public class AdminUnregisterCommand extends CompositeCommand {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
return false;
}
if (!getIslands().hasIsland(getWorld(), targetUUID)) {
if (!getIslands().hasIsland(getWorld(), targetUUID) && !getIslands().inTeam(getWorld(), targetUUID)) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
if (getIslands().inTeam(getWorld(), targetUUID)) {
user.sendMessage("commands.admin.unregister.cannot-unregister-team-player");
return false;
}
// Unregister island
user.sendMessage("commands.admin.unregister.unregistered-island", "[xyz]", Util.xyz(getIslands().getIsland(getWorld(), targetUUID).getCenter().toVector()));
getIslands().removePlayer(getWorld(), targetUUID);

View File

@ -6,6 +6,7 @@ import java.util.UUID;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
public class AdminTeamAddCommand extends CompositeCommand {
@ -60,9 +61,15 @@ public class AdminTeamAddCommand extends CompositeCommand {
User owner = User.getInstance(ownerUUID);
owner.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, getPlugin().getPlayers().getName(targetUUID));
target.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel());
getIslands().getIsland(getWorld(), ownerUUID).addMember(targetUUID);
user.sendMessage("general.success");
return true;
Island teamIsland = getIslands().getIsland(getWorld(), ownerUUID);
if (teamIsland != null) {
getIslands().setJoinTeam(teamIsland, targetUUID);
user.sendMessage("general.success");
return true;
} else {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
}

View File

@ -147,19 +147,6 @@ public class AdminUnregisterCommandTest {
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.player-has-no-island"));
}
/**
* Test method for .
*/
@Test
public void testExecuteInTeam() {
when(im.inTeam(Mockito.any(),Mockito.any())).thenReturn(true);
String[] name = {"tastybento"};
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
AdminUnregisterCommand itl = new AdminUnregisterCommand(ac);
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
Mockito.verify(user).sendMessage("commands.admin.unregister.cannot-unregister-team-player");
}
/**
* Test method for .
*/

View File

@ -294,7 +294,7 @@ public class AdminTeamAddCommandTest {
// Success
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
Mockito.verify(island).addMember(notUUID);
Mockito.verify(im).setJoinTeam(Mockito.eq(island), Mockito.eq(notUUID));
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
}