mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-29 12:37:37 +01:00
Added reset for inventory and enderchests.
Money is to do because it required Vault integration.
This commit is contained in:
parent
638712566a
commit
11d257c64a
@ -211,12 +211,10 @@ commands:
|
||||
leave:
|
||||
cannot-leave: "&cTeamleaders cannot leave! Become a member first, or kick all members."
|
||||
description: "leave your island"
|
||||
type-again: "&cEnter the leave command again to confirm"
|
||||
left-your-island: "&c[name] left your island"
|
||||
kick:
|
||||
description: "remove a member from your island"
|
||||
parameters: "<player>"
|
||||
type-again: "&cEnter the kick command again to confirm"
|
||||
leader-kicked: "&cThe leader kicked you from the island!"
|
||||
cannot-kick: "&cYou cannot kick yourself!"
|
||||
demote:
|
||||
|
@ -78,6 +78,16 @@ public class IslandResetCommand extends CompositeCommand {
|
||||
Island oldIsland = getIslands().getIsland(getWorld(), player.getUniqueId());
|
||||
// Remove them from this island (it still exists and will be deleted later)
|
||||
getIslands().removePlayer(getWorld(), player.getUniqueId());
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld())) {
|
||||
user.getPlayer().getInventory().clear();
|
||||
}
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
// TODO: needs Vault
|
||||
}
|
||||
// Create new island and then delete the old one
|
||||
try {
|
||||
NewIsland.builder()
|
||||
|
@ -77,6 +77,16 @@ public class IslandTeamInviteAcceptCommand extends CompositeCommand {
|
||||
user.teleport(newHome);
|
||||
// Remove player as owner of the old island
|
||||
getIslands().removePlayer(getWorld(), playerUUID);
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld())) {
|
||||
user.getPlayer().getInventory().clear();
|
||||
}
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
// TODO: needs Vault
|
||||
}
|
||||
// Add the player as a team member of the new island
|
||||
getIslands().setJoinTeam(teamIsland, playerUUID);
|
||||
// Set the player's home
|
||||
|
@ -60,6 +60,16 @@ public class IslandTeamKickCommand extends CompositeCommand {
|
||||
kickSet.remove(targetUUID);
|
||||
User.getInstance(targetUUID).sendMessage("commands.island.team.kick.leader-kicked");
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld())) {
|
||||
user.getPlayer().getInventory().clear();
|
||||
}
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
// TODO: needs Vault
|
||||
}
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
} else {
|
||||
|
@ -31,11 +31,12 @@ public class IslandTeamLeaveCommand extends CompositeCommand {
|
||||
return false;
|
||||
}
|
||||
if (!getSettings().isLeaveConfirmation()) {
|
||||
leave(user);
|
||||
leave(user);
|
||||
return true;
|
||||
} else {
|
||||
this.askConfirmation(user, () -> leave(user));
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void leave(User user) {
|
||||
@ -43,7 +44,17 @@ public class IslandTeamLeaveCommand extends CompositeCommand {
|
||||
if (leaderUUID != null) {
|
||||
User.getInstance(leaderUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName());
|
||||
}
|
||||
getIslands().removePlayer(getWorld(), user.getUniqueId());
|
||||
getIslands().setLeaveTeam(getWorld(), user.getUniqueId());
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld())) {
|
||||
user.getPlayer().getInventory().clear();
|
||||
}
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
// TODO: needs Vault
|
||||
}
|
||||
user.sendMessage("general.success");
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -52,6 +54,8 @@ public class IslandTeamKickCommandTest {
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private IslandWorldManager iwm;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@ -73,7 +77,7 @@ public class IslandTeamKickCommandTest {
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
player = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
@ -83,7 +87,7 @@ public class IslandTeamKickCommandTest {
|
||||
notUUID = UUID.randomUUID();
|
||||
}
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getPlayer()).thenReturn(player);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
User.setPlugin(plugin);
|
||||
|
||||
@ -115,7 +119,7 @@ public class IslandTeamKickCommandTest {
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// IWM friendly name
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
}
|
||||
@ -230,4 +234,35 @@ public class IslandTeamKickCommandTest {
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.kick.type-again"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamKickCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteTestResets() {
|
||||
when(s.isKickConfirmation()).thenReturn(false);
|
||||
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
|
||||
Set<UUID> members = new HashSet<>();
|
||||
members.add(notUUID);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members);
|
||||
|
||||
// Require resets
|
||||
when(iwm.isOnLeaveResetEnderChest(Mockito.any())).thenReturn(true);
|
||||
Inventory enderChest = mock(Inventory.class);
|
||||
when(player.getEnderChest()).thenReturn(enderChest);
|
||||
when(iwm.isOnLeaveResetInventory(Mockito.any())).thenReturn(true);
|
||||
PlayerInventory inv = mock(PlayerInventory.class);
|
||||
when(player.getInventory()).thenReturn(inv);
|
||||
when(iwm.isOnLeaveResetMoney(Mockito.any())).thenReturn(true);
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertTrue(itl.execute(user, Arrays.asList(name)));
|
||||
Mockito.verify(im).removePlayer(Mockito.any(), Mockito.eq(notUUID));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
||||
|
||||
Mockito.verify(enderChest).clear();
|
||||
Mockito.verify(inv).clear();
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -29,6 +31,7 @@ import us.tastybento.bskyblock.Settings;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
import us.tastybento.bskyblock.commands.IslandCommand;
|
||||
import us.tastybento.bskyblock.managers.CommandsManager;
|
||||
import us.tastybento.bskyblock.managers.IslandWorldManager;
|
||||
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||
import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
|
||||
@ -45,6 +48,8 @@ public class IslandTeamLeaveCommandTest {
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private IslandWorldManager iwm;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@ -66,13 +71,13 @@ public class IslandTeamLeaveCommandTest {
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
player = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getPlayer()).thenReturn(player);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
|
||||
// Parent command has no aliases
|
||||
@ -95,6 +100,9 @@ public class IslandTeamLeaveCommandTest {
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
|
||||
// Island World Manager
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,7 +139,7 @@ public class IslandTeamLeaveCommandTest {
|
||||
|
||||
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
|
||||
assertTrue(itl.execute(user, new ArrayList<>()));
|
||||
Mockito.verify(im).removePlayer(Mockito.any(), Mockito.eq(uuid));
|
||||
Mockito.verify(im).setLeaveTeam(Mockito.any(), Mockito.eq(uuid));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
||||
}
|
||||
|
||||
@ -151,7 +159,35 @@ public class IslandTeamLeaveCommandTest {
|
||||
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
|
||||
assertFalse(itl.execute(user, new ArrayList<>()));
|
||||
// Confirmation required
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.leave.type-again"));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.confirm"), Mockito.eq("[seconds]"), Mockito.eq("0"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamLeaveCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteTestResets() {
|
||||
when(s.isLeaveConfirmation()).thenReturn(false);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
// Add a team leader - null
|
||||
when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(null);
|
||||
|
||||
// Require resets
|
||||
when(iwm.isOnLeaveResetEnderChest(Mockito.any())).thenReturn(true);
|
||||
Inventory enderChest = mock(Inventory.class);
|
||||
when(player.getEnderChest()).thenReturn(enderChest);
|
||||
when(iwm.isOnLeaveResetInventory(Mockito.any())).thenReturn(true);
|
||||
PlayerInventory inv = mock(PlayerInventory.class);
|
||||
when(player.getInventory()).thenReturn(inv);
|
||||
when(iwm.isOnLeaveResetMoney(Mockito.any())).thenReturn(true);
|
||||
|
||||
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
|
||||
assertTrue(itl.execute(user, new ArrayList<>()));
|
||||
Mockito.verify(im).setLeaveTeam(Mockito.any(), Mockito.eq(uuid));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
||||
|
||||
Mockito.verify(enderChest).clear();
|
||||
Mockito.verify(inv).clear();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user