mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-26 04:35:43 +01:00
Remove players from the island and cache.
This commit is contained in:
parent
dc51bd87b1
commit
9f8a6bcded
@ -57,7 +57,7 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
|
||||
mUser.sendMessage("commands.admin.team.disband.disbanded");
|
||||
// The owner gets to keep the island
|
||||
if (!m.equals(targetUUID)) {
|
||||
island.removeMember(m);
|
||||
getIslands().removePlayer(island, m);
|
||||
TeamEvent.builder()
|
||||
.island(island)
|
||||
.reason(TeamEvent.Reason.KICK)
|
||||
|
@ -84,7 +84,7 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
||||
if (ownerUUID != null) {
|
||||
User.getInstance(ownerUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());
|
||||
}
|
||||
island.removeMember(user.getUniqueId());
|
||||
getIslands().removePlayer(island, user.getUniqueId());
|
||||
// Clean the player
|
||||
getPlayers().cleanLeavingPlayer(getWorld(), user, false, island);
|
||||
|
||||
|
@ -83,7 +83,7 @@ public class IslandTeamUncoopCommand extends CompositeCommand {
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island != null) {
|
||||
island.removeMember(targetUUID);
|
||||
getIslands().removePlayer(island, targetUUID);
|
||||
user.sendMessage("commands.island.team.uncoop.success", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName());
|
||||
target.sendMessage("commands.island.team.uncoop.you-are-no-longer-a-coop-member", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());
|
||||
// Set cooldown
|
||||
|
@ -83,7 +83,7 @@ public class IslandTeamUntrustCommand extends CompositeCommand {
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island != null) {
|
||||
island.removeMember(targetUUID);
|
||||
getIslands().removePlayer(island, targetUUID);
|
||||
user.sendMessage("commands.island.team.untrust.success", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName());
|
||||
target.sendMessage("commands.island.team.untrust.you-are-no-longer-trusted", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());
|
||||
// Set cooldown
|
||||
|
@ -1378,6 +1378,15 @@ public class IslandsManager {
|
||||
islandCache.removePlayer(world, uuid).forEach(handler::saveObjectAsync);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this player from this island
|
||||
* @param island island
|
||||
* @param uuid uuid of member
|
||||
*/
|
||||
public void removePlayer(Island island, UUID uuid) {
|
||||
islandCache.removePlayer(island, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* This teleports players away from an island - used when reseting or deleting an island
|
||||
* @param island to remove players from
|
||||
@ -1512,7 +1521,7 @@ public class IslandsManager {
|
||||
public void setOwner(User user, UUID targetUUID, Island island) {
|
||||
islandCache.setOwner(island, targetUUID);
|
||||
// Remove the old owner from the island
|
||||
island.removeMember(user.getUniqueId());
|
||||
plugin.getIslands().removePlayer(island, user.getUniqueId());
|
||||
|
||||
user.sendMessage("commands.island.team.setowner.name-is-the-owner", "[name]", plugin.getPlayers().getName(targetUUID));
|
||||
plugin.getIWM().getAddon(island.getWorld()).ifPresent(addon -> {
|
||||
|
@ -303,6 +303,19 @@ public class IslandCache {
|
||||
return islandSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes player from island and removes the cache reference
|
||||
* @param island member's island
|
||||
* @param uuid uuid of member to remove
|
||||
*/
|
||||
public void removePlayer(@NonNull Island island, @NonNull UUID uuid) {
|
||||
Set<Island> islandSet = islandsByUUID.get(uuid);
|
||||
if (islandSet != null) {
|
||||
islandSet.remove(island);
|
||||
}
|
||||
island.removeMember(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of islands in the cache
|
||||
* @return the number of islands
|
||||
|
@ -18,6 +18,7 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -27,6 +28,7 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
@ -58,11 +60,17 @@ import world.bentobox.bentobox.util.Util;
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class AdminUnregisterCommandTest {
|
||||
|
||||
@Mock
|
||||
private CompositeCommand ac;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
@Mock
|
||||
private World world;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -84,8 +92,6 @@ public class AdminUnregisterCommandTest {
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
@ -98,8 +104,8 @@ public class AdminUnregisterCommandTest {
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
ac = mock(CompositeCommand.class);
|
||||
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
when(ac.getWorld()).thenReturn(world);
|
||||
|
||||
// Island World Manager
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
@ -107,7 +113,6 @@ public class AdminUnregisterCommandTest {
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||
when(im.isOwner(any(),any())).thenReturn(true);
|
||||
@ -115,7 +120,6 @@ public class AdminUnregisterCommandTest {
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
@ -227,9 +231,9 @@ public class AdminUnregisterCommandTest {
|
||||
itl.unregisterPlayer(user, "name", targetUUID);
|
||||
verify(user).sendMessage("commands.admin.unregister.unregistered-island", TextVariables.XYZ, "1,2,3", TextVariables.NAME, "name");
|
||||
assertTrue(map.isEmpty());
|
||||
verify(im).removePlayer(any(), eq(uuid1));
|
||||
verify(im).removePlayer(any(), eq(uuid2));
|
||||
verify(im).removePlayer(any(), eq(uuid3));
|
||||
verify(im, never()).removePlayer(any(), eq(uuid4));
|
||||
verify(im).removePlayer(any(World.class), eq(uuid1));
|
||||
verify(im).removePlayer(any(World.class), eq(uuid2));
|
||||
verify(im).removePlayer(any(World.class), eq(uuid3));
|
||||
verify(im, never()).removePlayer(any(World.class), eq(uuid4));
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,11 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -72,6 +74,8 @@ public class AdminTeamDisbandCommandTest {
|
||||
@Mock
|
||||
private PluginManager pim;
|
||||
private UUID notUUID;
|
||||
@Mock
|
||||
private @Nullable Island island;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -119,6 +123,7 @@ public class AdminTeamDisbandCommandTest {
|
||||
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||
when(im.isOwner(any(),any())).thenReturn(true);
|
||||
when(im.getOwner(any(),any())).thenReturn(uuid);
|
||||
when(im.getIsland(any(World.class), any(UUID.class))).thenReturn(island);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
@ -214,8 +219,7 @@ public class AdminTeamDisbandCommandTest {
|
||||
@Test
|
||||
public void testExecuteSuccess() {
|
||||
when(im.inTeam(any(), any())).thenReturn(true);
|
||||
Island is = mock(Island.class);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(is);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
when(pm.getName(any())).thenReturn(name[0]);
|
||||
@ -229,8 +233,8 @@ public class AdminTeamDisbandCommandTest {
|
||||
|
||||
AdminTeamDisbandCommand itl = new AdminTeamDisbandCommand(ac);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
verify(is, never()).removeMember(notUUID);
|
||||
verify(is).removeMember(uuid);
|
||||
verify(im, never()).removePlayer(island, notUUID);
|
||||
verify(im).removePlayer(island, uuid);
|
||||
verify(user).sendMessage("commands.admin.team.disband.success", TextVariables.NAME, name[0]);
|
||||
verify(p).sendMessage("commands.admin.team.disband.disbanded");
|
||||
verify(p2).sendMessage("commands.admin.team.disband.disbanded");
|
||||
|
@ -21,6 +21,7 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -86,6 +87,8 @@ public class IslandTeamKickCommandTest {
|
||||
private Island island;
|
||||
@Mock
|
||||
private Addon addon;
|
||||
@Mock
|
||||
private World world;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -132,6 +135,7 @@ public class IslandTeamKickCommandTest {
|
||||
when(ic.getAddon()).thenReturn(addon);
|
||||
AddonDescription desc = new AddonDescription.Builder("main", "name", "version").build();
|
||||
when(addon.getDescription()).thenReturn(desc);
|
||||
when(ic.getWorld()).thenReturn(world);
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
@ -264,7 +268,7 @@ public class IslandTeamKickCommandTest {
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(im).removePlayer(any(), eq(notUUID));
|
||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||
}
|
||||
|
||||
@ -354,7 +358,7 @@ public class IslandTeamKickCommandTest {
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(im).removePlayer(any(), eq(notUUID));
|
||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||
}
|
||||
|
||||
@ -376,7 +380,7 @@ public class IslandTeamKickCommandTest {
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(im).removePlayer(any(), eq(notUUID));
|
||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||
verify(target, Mockito.never()).getInventory();
|
||||
|
||||
@ -404,7 +408,7 @@ public class IslandTeamKickCommandTest {
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(im).removePlayer(any(), eq(notUUID));
|
||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||
verify(target, Mockito.never()).getInventory();
|
||||
verify(pm).cleanLeavingPlayer(any(), any(User.class), eq(true), eq(island));
|
||||
|
@ -162,7 +162,7 @@ public class IslandTeamLeaveCommandTest {
|
||||
|
||||
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
verify(island).removeMember(uuid);
|
||||
verify(im).removePlayer(island,uuid);
|
||||
verify(user).sendMessage(eq("commands.island.team.leave.success"));
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ public class IslandTeamLeaveCommandTest {
|
||||
|
||||
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
verify(island).removeMember(uuid);
|
||||
verify(im).removePlayer(island, uuid);
|
||||
verify(user).sendMessage("commands.island.team.leave.success");
|
||||
verify(pm).addReset(eq(world), eq(uuid));
|
||||
verify(user).sendMessage("commands.island.reset.resets-left", TextVariables.NUMBER, "100");
|
||||
|
Loading…
Reference in New Issue
Block a user