mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 19:25:12 +01:00
Extracted island info from the Island object.
This is in preparation to have a different info for players than admins. https://github.com/BentoBoxWorld/BentoBox/issues/1501
This commit is contained in:
parent
5bb12d53bd
commit
547c266975
@ -9,6 +9,7 @@ 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;
|
||||
import world.bentobox.bentobox.util.IslandInfo;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class AdminInfoCommand extends CompositeCommand {
|
||||
@ -34,7 +35,7 @@ public class AdminInfoCommand extends CompositeCommand {
|
||||
}
|
||||
// If there are no args, then the player wants info on the island at this location
|
||||
if (args.isEmpty()) {
|
||||
if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.showInfo(user)).orElse(false)) {
|
||||
if (!getIslands().getIslandAt(user.getLocation()).map(i -> new IslandInfo(i).showInfo(user)).orElse(false)) {
|
||||
user.sendMessage("commands.admin.info.no-island");
|
||||
return false;
|
||||
}
|
||||
@ -49,7 +50,7 @@ public class AdminInfoCommand extends CompositeCommand {
|
||||
// Show info for this player
|
||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||
if (island != null) {
|
||||
island.showInfo(user);
|
||||
new IslandInfo(island).showInfo(user);
|
||||
if (!getIslands().getQuarantinedIslandByUser(getWorld(), targetUUID).isEmpty()) {
|
||||
user.sendMessage("commands.admin.info.islands-in-trash");
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ 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;
|
||||
import world.bentobox.bentobox.util.IslandInfo;
|
||||
|
||||
public class AdminTrashCommand extends CompositeCommand {
|
||||
|
||||
@ -63,7 +64,7 @@ public class AdminTrashCommand extends CompositeCommand {
|
||||
user.sendMessage("commands.admin.trash.title");
|
||||
for (int i = 0; i < islands.size(); i++) {
|
||||
user.sendMessage("commands.admin.trash.count", TextVariables.NUMBER, String.valueOf(i+1));
|
||||
islands.get(i).showInfo(user);
|
||||
new IslandInfo(islands.get(i)).showInfo(user);
|
||||
}
|
||||
user.sendMessage("commands.admin.trash.use-switch", TextVariables.LABEL, getTopLabel());
|
||||
user.sendMessage("commands.admin.trash.use-emptytrash", TextVariables.LABEL, getTopLabel());
|
||||
|
@ -10,6 +10,7 @@ import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.IslandInfo;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class AdminTeamAddCommand extends CompositeCommand {
|
||||
@ -49,7 +50,10 @@ public class AdminTeamAddCommand extends CompositeCommand {
|
||||
}
|
||||
if (getIslands().inTeam(getWorld(), ownerUUID) && !getIslands().getOwner(getWorld(), ownerUUID).equals(ownerUUID)) {
|
||||
user.sendMessage("commands.admin.team.add.name-not-owner", TextVariables.NAME, args.get(0));
|
||||
getIslands().getIsland(getWorld(), ownerUUID).showMembers(user);
|
||||
Island island = getIslands().getIsland(getWorld(), ownerUUID);
|
||||
if (island != null) {
|
||||
new IslandInfo(island).showMembers(user);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (getIslands().inTeam(getWorld(), targetUUID)) {
|
||||
|
@ -13,6 +13,7 @@ import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.IslandInfo;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
@ -59,10 +60,12 @@ public class AdminTeamKickCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||
|
||||
if (island == null) {
|
||||
return false;
|
||||
}
|
||||
if (targetUUID.equals(island.getOwner())) {
|
||||
user.sendMessage("commands.admin.team.kick.cannot-kick-owner");
|
||||
island.showMembers(user);
|
||||
new IslandInfo(island).showMembers(user);
|
||||
return false;
|
||||
}
|
||||
User target = User.getInstance(targetUUID);
|
||||
|
@ -9,6 +9,7 @@ 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;
|
||||
import world.bentobox.bentobox.util.IslandInfo;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
@ -37,7 +38,7 @@ public class IslandInfoCommand extends CompositeCommand {
|
||||
}
|
||||
// If there are no args, then the player wants info on the island at this location
|
||||
if (args.isEmpty()) {
|
||||
if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.showInfo(user)).orElse(false)) {
|
||||
if (!getIslands().getIslandAt(user.getLocation()).map(i -> new IslandInfo(i).showInfo(user)).orElse(false)) {
|
||||
user.sendMessage("commands.admin.info.no-island");
|
||||
return false;
|
||||
}
|
||||
@ -56,10 +57,10 @@ public class IslandInfoCommand extends CompositeCommand {
|
||||
return false;
|
||||
}
|
||||
// Show info for this player
|
||||
island.showInfo(user);
|
||||
new IslandInfo(island).showInfo(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
|
@ -1,8 +1,6 @@
|
||||
package world.bentobox.bentobox.database.objects;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -23,7 +21,6 @@ import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -37,7 +34,6 @@ import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.logs.LogEntry;
|
||||
import world.bentobox.bentobox.api.metadata.MetaDataAble;
|
||||
import world.bentobox.bentobox.api.metadata.MetaDataValue;
|
||||
@ -49,6 +45,7 @@ import world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.IslandInfo;
|
||||
import world.bentobox.bentobox.util.Pair;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@ -1080,71 +1077,21 @@ public class Island implements DataObject, MetaDataAble {
|
||||
* Shows info of this island to this user.
|
||||
* @param user the User who is requesting it
|
||||
* @return always true
|
||||
* @deprecated Use {@link IslandInfo#showInfo(User) instead}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean showInfo(User user) {
|
||||
BentoBox plugin = BentoBox.getInstance();
|
||||
user.sendMessage("commands.admin.info.title");
|
||||
user.sendMessage("commands.admin.info.island-uuid", "[uuid]", this.getUniqueId());
|
||||
if (getOwner() == null) {
|
||||
user.sendMessage("commands.admin.info.unowned");
|
||||
} else {
|
||||
user.sendMessage("commands.admin.info.owner", "[owner]", plugin.getPlayers().getName(getOwner()), "[uuid]", getOwner().toString());
|
||||
|
||||
// Fixes #getLastPlayed() returning 0 when it is the owner's first connection.
|
||||
long lastPlayed = (Bukkit.getServer().getOfflinePlayer(getOwner()).getLastPlayed() != 0) ?
|
||||
Bukkit.getServer().getOfflinePlayer(getOwner()).getLastPlayed() : Bukkit.getServer().getOfflinePlayer(getOwner()).getFirstPlayed();
|
||||
String formattedDate;
|
||||
try {
|
||||
String dateTimeFormat = plugin.getLocalesManager().get("commands.admin.info.last-login-date-time-format");
|
||||
formattedDate = new SimpleDateFormat(dateTimeFormat).format(new Date(lastPlayed));
|
||||
} catch (NullPointerException | IllegalArgumentException ignored) {
|
||||
formattedDate = new Date(lastPlayed).toString();
|
||||
}
|
||||
user.sendMessage("commands.admin.info.last-login","[date]", formattedDate);
|
||||
|
||||
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(getWorld(), getOwner())));
|
||||
String resets = String.valueOf(plugin.getPlayers().getResets(getWorld(), getOwner()));
|
||||
String total = plugin.getIWM().getResetLimit(getWorld()) < 0 ? "Unlimited" : String.valueOf(plugin.getIWM().getResetLimit(getWorld()));
|
||||
user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total);
|
||||
// Show team members
|
||||
showMembers(user);
|
||||
}
|
||||
Vector location = getProtectionCenter().toVector();
|
||||
user.sendMessage("commands.admin.info.island-protection-center", TextVariables.XYZ, Util.xyz(location));
|
||||
user.sendMessage("commands.admin.info.island-center", TextVariables.XYZ, Util.xyz(getCenter().toVector()));
|
||||
user.sendMessage("commands.admin.info.island-coords", "[xz1]", Util.xyz(new Vector(this.getMinX(), 0, getMinZ())), "[xz2]", Util.xyz(new Vector(this.getMaxX(), 0, getMaxZ())));
|
||||
user.sendMessage("commands.admin.info.protection-range", "[range]", String.valueOf(getProtectionRange()));
|
||||
user.sendMessage("commands.admin.info.max-protection-range", "[range]", String.valueOf(getMaxEverProtectionRange()));
|
||||
user.sendMessage("commands.admin.info.protection-coords", "[xz1]", Util.xyz(new Vector(this.getMinProtectedX(), 0, getMinProtectedZ())), "[xz2]", Util.xyz(new Vector(this.getMaxProtectedX(), 0, getMaxProtectedZ())));
|
||||
if (spawn) {
|
||||
user.sendMessage("commands.admin.info.is-spawn");
|
||||
}
|
||||
if (!getBanned().isEmpty()) {
|
||||
user.sendMessage("commands.admin.info.banned-players");
|
||||
getBanned().forEach(u -> user.sendMessage("commands.admin.info.banned-format", TextVariables.NAME, plugin.getPlayers().getName(u)));
|
||||
}
|
||||
if (getPurgeProtected()) {
|
||||
user.sendMessage("commands.admin.info.purge-protected");
|
||||
}
|
||||
return true;
|
||||
return new IslandInfo(this).showInfo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the members of this island to this user.
|
||||
* @param user the User who is requesting it
|
||||
* @deprecated Use {@link IslandInfo#showMembers(User) instead}
|
||||
*/
|
||||
@Deprecated
|
||||
public void showMembers(User user) {
|
||||
BentoBox plugin = BentoBox.getInstance();
|
||||
user.sendMessage("commands.admin.info.team-members-title");
|
||||
members.forEach((u, i) -> {
|
||||
if (owner.equals(u)) {
|
||||
user.sendMessage("commands.admin.info.team-owner-format", TextVariables.NAME, plugin.getPlayers().getName(u)
|
||||
, "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i)));
|
||||
} else if (i > RanksManager.VISITOR_RANK){
|
||||
user.sendMessage("commands.admin.info.team-member-format", TextVariables.NAME, plugin.getPlayers().getName(u)
|
||||
, "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i)));
|
||||
}
|
||||
});
|
||||
new IslandInfo(this).showMembers(user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
109
src/main/java/world/bentobox/bentobox/util/IslandInfo.java
Normal file
109
src/main/java/world/bentobox/bentobox/util/IslandInfo.java
Normal file
@ -0,0 +1,109 @@
|
||||
package world.bentobox.bentobox.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
* @since 1.17.3
|
||||
*/
|
||||
public class IslandInfo {
|
||||
|
||||
private final BentoBox plugin;
|
||||
private final Island island;
|
||||
private final @Nullable UUID owner;
|
||||
private final World world;
|
||||
|
||||
|
||||
/**
|
||||
* @param plugin
|
||||
* @param island
|
||||
*/
|
||||
public IslandInfo(Island island) {
|
||||
this.plugin = BentoBox.getInstance();
|
||||
this.island = island;
|
||||
this.owner = island.getOwner();
|
||||
this.world = island.getWorld();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows info of this island to this user.
|
||||
* @param user the User who is requesting it
|
||||
* @return always true
|
||||
*/
|
||||
public boolean showInfo(User user) {
|
||||
user.sendMessage("commands.admin.info.title");
|
||||
user.sendMessage("commands.admin.info.island-uuid", "[uuid]", island.getUniqueId());
|
||||
if (owner == null) {
|
||||
user.sendMessage("commands.admin.info.unowned");
|
||||
} else {
|
||||
user.sendMessage("commands.admin.info.owner", "[owner]", plugin.getPlayers().getName(owner), "[uuid]", owner.toString());
|
||||
|
||||
// Fixes #getLastPlayed() returning 0 when it is the owner's first connection.
|
||||
long lastPlayed = (Bukkit.getOfflinePlayer(owner).getLastPlayed() != 0) ?
|
||||
Bukkit.getOfflinePlayer(owner).getLastPlayed() : Bukkit.getOfflinePlayer(owner).getFirstPlayed();
|
||||
String formattedDate;
|
||||
try {
|
||||
String dateTimeFormat = plugin.getLocalesManager().get("commands.admin.info.last-login-date-time-format");
|
||||
formattedDate = new SimpleDateFormat(dateTimeFormat).format(new Date(lastPlayed));
|
||||
} catch (NullPointerException | IllegalArgumentException ignored) {
|
||||
formattedDate = new Date(lastPlayed).toString();
|
||||
}
|
||||
user.sendMessage("commands.admin.info.last-login","[date]", formattedDate);
|
||||
|
||||
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(world, owner)));
|
||||
String resets = String.valueOf(plugin.getPlayers().getResets(world, owner));
|
||||
String total = plugin.getIWM().getResetLimit(world) < 0 ? "Unlimited" : String.valueOf(plugin.getIWM().getResetLimit(world));
|
||||
user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total);
|
||||
// Show team members
|
||||
showMembers(user);
|
||||
}
|
||||
Vector location = island.getProtectionCenter().toVector();
|
||||
user.sendMessage("commands.admin.info.island-protection-center", TextVariables.XYZ, Util.xyz(location));
|
||||
user.sendMessage("commands.admin.info.island-center", TextVariables.XYZ, Util.xyz(island.getCenter().toVector()));
|
||||
user.sendMessage("commands.admin.info.island-coords", "[xz1]", Util.xyz(new Vector(island.getMinX(), 0, island.getMinZ())), "[xz2]", Util.xyz(new Vector(island.getMaxX(), 0, island.getMaxZ())));
|
||||
user.sendMessage("commands.admin.info.protection-range", "[range]", String.valueOf(island.getProtectionRange()));
|
||||
user.sendMessage("commands.admin.info.max-protection-range", "[range]", String.valueOf(island.getMaxEverProtectionRange()));
|
||||
user.sendMessage("commands.admin.info.protection-coords", "[xz1]", Util.xyz(new Vector(island.getMinProtectedX(), 0, island.getMinProtectedZ())), "[xz2]", Util.xyz(new Vector(island.getMaxProtectedX(), 0, island.getMaxProtectedZ())));
|
||||
if (island.isSpawn()) {
|
||||
user.sendMessage("commands.admin.info.is-spawn");
|
||||
}
|
||||
if (!island.getBanned().isEmpty()) {
|
||||
user.sendMessage("commands.admin.info.banned-players");
|
||||
island.getBanned().forEach(u -> user.sendMessage("commands.admin.info.banned-format", TextVariables.NAME, plugin.getPlayers().getName(u)));
|
||||
}
|
||||
if (island.getPurgeProtected()) {
|
||||
user.sendMessage("commands.admin.info.purge-protected");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the members of this island to this user.
|
||||
* @param user the User who is requesting it
|
||||
*/
|
||||
public void showMembers(User user) {
|
||||
user.sendMessage("commands.admin.info.team-members-title");
|
||||
island.getMembers().forEach((u, i) -> {
|
||||
if (owner.equals(u)) {
|
||||
user.sendMessage("commands.admin.info.team-owner-format", TextVariables.NAME, plugin.getPlayers().getName(u)
|
||||
, "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i)));
|
||||
} else if (i > RanksManager.VISITOR_RANK){
|
||||
user.sendMessage("commands.admin.info.team-member-format", TextVariables.NAME, plugin.getPlayers().getName(u)
|
||||
, "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i)));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,27 +1,35 @@
|
||||
package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
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.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
@ -35,7 +43,9 @@ import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
@ -43,16 +53,32 @@ import world.bentobox.bentobox.util.Util;
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, Util.class})
|
||||
public class AdminInfoCommandTest {
|
||||
|
||||
private BentoBox plugin;
|
||||
private CompositeCommand ac;
|
||||
private UUID uuid;
|
||||
@Mock
|
||||
private CompositeCommand ic;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
|
||||
private Island island;
|
||||
|
||||
private AdminInfoCommand iic;
|
||||
|
||||
@Mock
|
||||
private Player player;
|
||||
@Mock
|
||||
private World world;
|
||||
@Mock
|
||||
private PlaceholdersManager phm;
|
||||
@Mock
|
||||
private @NonNull Location location;
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@ -60,69 +86,62 @@ public class AdminInfoCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BentoBox.class);
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
Util.setPlugin(plugin);
|
||||
// IWM
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(plugin.getRanksManager()).thenReturn(new RanksManager());
|
||||
|
||||
// Bukkit
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
// Command manager
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
while(notUUID.equals(uuid)) {
|
||||
notUUID = UUID.randomUUID();
|
||||
}
|
||||
when(player.isOp()).thenReturn(false);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getWorld()).thenReturn(world);
|
||||
when(user.getPlayer()).thenReturn(player);
|
||||
when(user.isPlayer()).thenReturn(true);
|
||||
//user = User.getInstance(player);
|
||||
// Set the User class plugin as this one
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
ac = mock(CompositeCommand.class);
|
||||
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// Island World Manager
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
|
||||
when(im.getOwner(Mockito.any(),Mockito.any())).thenReturn(uuid);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
when(lm.get(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
// Return the same string
|
||||
when(phm.replacePlaceholders(any(), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(phm);
|
||||
// Translate
|
||||
when(user.getTranslation(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
when(user.getTranslation(anyString(), anyString(), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Addon
|
||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||
// Island manager
|
||||
island = new Island(location, uuid, 100);
|
||||
when(location.toVector()).thenReturn(new Vector(1,2,3));
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
Optional<Island> optionalIsland = Optional.of(island);
|
||||
when(im.getIslandAt(any())).thenReturn(optionalIsland);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||
|
||||
// Players manager
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
when(pm.getUUID(any())).thenReturn(uuid);
|
||||
|
||||
|
||||
// Command
|
||||
iic = new AdminInfoCommand(ic);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
@ -130,93 +149,111 @@ public class AdminInfoCommandTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link AdminInfoCommand#execute(User, String, List)}.
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.AdminInfoCommand#setup()}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTargetConsole() {
|
||||
AdminInfoCommand itl = new AdminInfoCommand(ac);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
User console = User.getInstance(sender);
|
||||
assertFalse(itl.execute(console, itl.getLabel(), new ArrayList<>()));
|
||||
// Show help
|
||||
public void testSetup() {
|
||||
assertEquals("mod.info", iic.getPermission());
|
||||
assertFalse(iic.isOnlyPlayer());
|
||||
assertEquals("commands.admin.info.parameters", iic.getParameters());
|
||||
assertEquals("commands.admin.info.description", iic.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminInfoCommand#execute(User, String, List)} .
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.AdminInfoCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
AdminInfoCommand itl = new AdminInfoCommand(ac);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", name[0]);
|
||||
public void testExecuteUserStringListOfStringTooManyArgs() {
|
||||
assertFalse(iic.execute(user, "", Arrays.asList("hdhh", "hdhdhd")));
|
||||
verify(user).sendMessage("commands.help.header", "[label]", "commands.help.console");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for .
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.AdminInfoCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecutePlayerHasNoIsland() {
|
||||
AdminInfoCommand itl = new AdminInfoCommand(ac);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.player-has-no-island"));
|
||||
public void testExecuteUserStringListOfStringNoArgsConsole() {
|
||||
CommandSender console = mock(CommandSender.class);
|
||||
User sender = User.getInstance(console);
|
||||
assertFalse(iic.execute(sender, "", Collections.emptyList()));
|
||||
verify(user, never()).sendMessage("commands.help.header", "[label]", "commands.help.console");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminInfoCommand#execute(User, String, List)}.
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.AdminInfoCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSuccess() {
|
||||
AdminInfoCommand itl = new AdminInfoCommand(ac);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
Island is = mock(Island.class);
|
||||
when(im.getIsland(Mockito.any(), Mockito.eq(notUUID))).thenReturn(is);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(is).showInfo(Mockito.eq(user));
|
||||
public void testExecuteUserStringListOfStringNoArgsNoIsland() {
|
||||
when(im.getIslandAt(any())).thenReturn(Optional.empty());
|
||||
assertFalse(iic.execute(user, "", Collections.emptyList()));
|
||||
verify(user).sendMessage("commands.admin.info.no-island");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminInfoCommand#execute(User, String, List)}.
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.AdminInfoCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserNotOnIsland() {
|
||||
when(user.isPlayer()).thenReturn(true);
|
||||
AdminInfoCommand itl = new AdminInfoCommand(ac);
|
||||
// No island here
|
||||
when(im.getIslandAt(Mockito.any())).thenReturn(Optional.empty());
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Confirm other verifications
|
||||
Mockito.verify(user).sendMessage("commands.admin.info.no-island");
|
||||
public void testExecuteUserStringListOfStringNoArgsSuccess() {
|
||||
assertTrue(iic.execute(user, "", Collections.emptyList()));
|
||||
verify(user).sendMessage("commands.admin.info.title");
|
||||
verify(user).sendMessage(eq("commands.admin.info.island-uuid"), eq("[uuid]"), any());
|
||||
verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null), eq("[uuid]"), any());
|
||||
verify(user).sendMessage(eq("commands.admin.info.last-login"), eq("[date]"), any());
|
||||
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
|
||||
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
|
||||
verify(user).sendMessage("commands.admin.info.team-members-title");
|
||||
verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "ranks.owner");
|
||||
verify(user).sendMessage("commands.admin.info.island-protection-center", "[xyz]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.island-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.protection-range", "[range]", "100");
|
||||
verify(user).sendMessage("commands.admin.info.max-protection-range", "[range]", "100");
|
||||
verify(user).sendMessage("commands.admin.info.protection-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminInfoCommand#execute(User, String, List)}.
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.AdminInfoCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSuccessUserOnIsland() {
|
||||
when(user.isPlayer()).thenReturn(true);
|
||||
AdminInfoCommand itl = new AdminInfoCommand(ac);
|
||||
Location loc = mock(Location.class);
|
||||
public void testExecuteUserStringListOfStringArgsSuccess() {
|
||||
assertTrue(iic.execute(user, "", Collections.singletonList("tastybento")));
|
||||
verify(user).sendMessage("commands.admin.info.title");
|
||||
verify(user).sendMessage(eq("commands.admin.info.island-uuid"), eq("[uuid]"), any());
|
||||
verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null), eq("[uuid]"), any());
|
||||
verify(user).sendMessage(eq("commands.admin.info.last-login"), eq("[date]"), any());
|
||||
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
|
||||
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
|
||||
verify(user).sendMessage("commands.admin.info.team-members-title");
|
||||
verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "ranks.owner");
|
||||
verify(user).sendMessage("commands.admin.info.island-protection-center", "[xyz]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.island-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.protection-range", "[range]", "100");
|
||||
verify(user).sendMessage("commands.admin.info.max-protection-range", "[range]", "100");
|
||||
verify(user).sendMessage("commands.admin.info.protection-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0");
|
||||
|
||||
// Island has owner
|
||||
Island is = mock(Island.class);
|
||||
when(is.getOwner()).thenReturn(uuid);
|
||||
when(is.showInfo(Mockito.any())).thenReturn(true);
|
||||
Optional<Island> opi = Optional.of(is);
|
||||
when(im.getIslandAt(Mockito.any())).thenReturn(opi);
|
||||
when(user.getLocation()).thenReturn(loc);
|
||||
|
||||
|
||||
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Confirm other verifications
|
||||
Mockito.verify(is).showInfo(Mockito.eq(user));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.AdminInfoCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringArgsNoIsland() {
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
|
||||
assertFalse(iic.execute(user, "", Collections.singletonList("tastybento")));
|
||||
verify(user).sendMessage("general.errors.player-has-no-island");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.AdminInfoCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringArgsUnknownPlayer() {
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getUUID(any())).thenReturn(null);
|
||||
assertFalse(iic.execute(user, "", Collections.singletonList("tastybento")));
|
||||
verify(user).sendMessage("general.errors.unknown-player", "[name]", "tastybento");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,10 @@ package world.bentobox.bentobox.api.commands.admin.team;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -90,15 +93,15 @@ public class AdminTeamAddCommandTest {
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getOwner(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
||||
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
when(im.isOwner(any(), any())).thenReturn(true);
|
||||
when(im.getOwner(any(), any())).thenReturn(uuid);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
@ -112,16 +115,16 @@ public class AdminTeamAddCommandTest {
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// Island World Manager
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
// Addon
|
||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||
when(iwm.getAddon(any())).thenReturn(Optional.empty());
|
||||
|
||||
}
|
||||
|
||||
@ -158,16 +161,16 @@ public class AdminTeamAddCommandTest {
|
||||
String[] name = {"tastybento", "poslovich"};
|
||||
|
||||
// Unknown owner
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(null);
|
||||
when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(null);
|
||||
when(pm.getUUID(eq("poslovich"))).thenReturn(notUUID);
|
||||
assertFalse(itl.execute(user, ac.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", "tastybento");
|
||||
verify(user).sendMessage("general.errors.unknown-player", "[name]", "tastybento");
|
||||
|
||||
// Unknown target
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(null);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(eq("poslovich"))).thenReturn(null);
|
||||
assertFalse(itl.execute(user, ac.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", "poslovich");
|
||||
verify(user).sendMessage("general.errors.unknown-player", "[name]", "poslovich");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,13 +181,13 @@ public class AdminTeamAddCommandTest {
|
||||
AdminTeamAddCommand itl = new AdminTeamAddCommand(ac);
|
||||
String[] name = {"tastybento", "poslovich"};
|
||||
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(eq("poslovich"))).thenReturn(notUUID);
|
||||
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(notUUID))).thenReturn(true);
|
||||
when(im.inTeam(any(), eq(notUUID))).thenReturn(true);
|
||||
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.invite.errors.already-on-team"));
|
||||
verify(user).sendMessage(eq("commands.island.team.invite.errors.already-on-team"));
|
||||
}
|
||||
|
||||
|
||||
@ -196,14 +199,14 @@ public class AdminTeamAddCommandTest {
|
||||
AdminTeamAddCommand itl = new AdminTeamAddCommand(ac);
|
||||
String[] name = {"tastybento", "poslovich"};
|
||||
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(eq("poslovich"))).thenReturn(notUUID);
|
||||
|
||||
// No island,
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.hasIsland(any(), eq(uuid))).thenReturn(false);
|
||||
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("general.errors.player-has-no-island");
|
||||
verify(user).sendMessage("general.errors.player-has-no-island");
|
||||
|
||||
}
|
||||
|
||||
@ -215,21 +218,21 @@ public class AdminTeamAddCommandTest {
|
||||
AdminTeamAddCommand itl = new AdminTeamAddCommand(ac);
|
||||
String[] name = {"tastybento", "poslovich"};
|
||||
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(eq("poslovich"))).thenReturn(notUUID);
|
||||
|
||||
// Has island, has team, but not an owner
|
||||
when(im.hasIsland(Mockito.any(),Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.any(),Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.getOwner(Mockito.any(),Mockito.eq(uuid))).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(),eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(),eq(uuid))).thenReturn(true);
|
||||
when(im.getOwner(any(),eq(uuid))).thenReturn(notUUID);
|
||||
|
||||
// Island
|
||||
Island island = mock(Island.class);
|
||||
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(island);
|
||||
when(im.getIsland(any(), eq(uuid))).thenReturn(island);
|
||||
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("commands.admin.team.add.name-not-owner", "[name]", "tastybento");
|
||||
Mockito.verify(island).showMembers(Mockito.any());
|
||||
verify(user).sendMessage("commands.admin.team.add.name-not-owner", "[name]", "tastybento");
|
||||
verify(user).sendMessage("commands.admin.info.team-members-title");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -240,19 +243,19 @@ public class AdminTeamAddCommandTest {
|
||||
AdminTeamAddCommand itl = new AdminTeamAddCommand(ac);
|
||||
String[] name = {"tastybento", "poslovich"};
|
||||
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(eq("poslovich"))).thenReturn(notUUID);
|
||||
|
||||
// Has island, has team, is owner
|
||||
when(im.hasIsland(Mockito.any(),Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.any(),Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.getOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(uuid);
|
||||
when(im.hasIsland(any(),eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(),eq(uuid))).thenReturn(true);
|
||||
when(im.getOwner(any(), eq(uuid))).thenReturn(uuid);
|
||||
|
||||
// Target has island
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(notUUID))).thenReturn(true);
|
||||
when(im.hasIsland(any(), eq(notUUID))).thenReturn(true);
|
||||
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("commands.admin.team.add.name-has-island", "[name]", "poslovich");
|
||||
verify(user).sendMessage("commands.admin.team.add.name-has-island", "[name]", "poslovich");
|
||||
|
||||
}
|
||||
|
||||
@ -264,18 +267,18 @@ public class AdminTeamAddCommandTest {
|
||||
AdminTeamAddCommand itl = new AdminTeamAddCommand(ac);
|
||||
String[] name = {"tastybento", "poslovich"};
|
||||
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(eq("poslovich"))).thenReturn(notUUID);
|
||||
|
||||
// Has island, no team
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.hasIsland(any(), eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(false);
|
||||
|
||||
// Target has island
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(notUUID))).thenReturn(true);
|
||||
when(im.hasIsland(any(), eq(notUUID))).thenReturn(true);
|
||||
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("commands.admin.team.add.name-has-island", "[name]", "poslovich");
|
||||
verify(user).sendMessage("commands.admin.team.add.name-has-island", "[name]", "poslovich");
|
||||
|
||||
}
|
||||
|
||||
@ -287,29 +290,29 @@ public class AdminTeamAddCommandTest {
|
||||
AdminTeamAddCommand itl = new AdminTeamAddCommand(ac);
|
||||
String[] name = {"tastybento", "poslovich"};
|
||||
|
||||
when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID);
|
||||
when(pm.getUUID(eq("tastybento"))).thenReturn(uuid);
|
||||
when(pm.getUUID(eq("poslovich"))).thenReturn(notUUID);
|
||||
|
||||
// Has island, no team
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.hasIsland(any(), eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(false);
|
||||
|
||||
// Target has no island
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(notUUID))).thenReturn(false);
|
||||
when(im.hasIsland(any(), eq(notUUID))).thenReturn(false);
|
||||
|
||||
// Island
|
||||
Island island = mock(Island.class);
|
||||
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(island);
|
||||
when(im.getIsland(any(), eq(uuid))).thenReturn(island);
|
||||
|
||||
// Player name
|
||||
when(pm.getName(Mockito.eq(uuid))).thenReturn("tastybento");
|
||||
when(pm.getName(Mockito.eq(notUUID))).thenReturn("poslovich");
|
||||
when(pm.getName(eq(uuid))).thenReturn("tastybento");
|
||||
when(pm.getName(eq(notUUID))).thenReturn("poslovich");
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Success
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(im).setJoinTeam(Mockito.eq(island), Mockito.eq(notUUID));
|
||||
Mockito.verify(user).sendMessage("commands.admin.team.add.success", TextVariables.NAME, name[1], "[owner]", name[0]);
|
||||
verify(im).setJoinTeam(eq(island), eq(notUUID));
|
||||
verify(user).sendMessage("commands.admin.team.add.success", TextVariables.NAME, name[1], "[owner]", name[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ public class AdminTeamKickCommandTest {
|
||||
assertTrue(itl.canExecute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
verify(user).sendMessage(eq("commands.admin.team.kick.cannot-kick-owner"));
|
||||
verify(is).showMembers(any());
|
||||
verify(user).sendMessage("commands.admin.info.team-members-title");
|
||||
verify(im, never()).removePlayer(eq(world), eq(notUUID));
|
||||
verify(pm, never()).clearHomeLocations(eq(world), eq(notUUID));
|
||||
verify(user, never()).sendMessage(eq("commands.admin.team.kick.success"), anyString(), anyString(), anyString(), anyString());
|
||||
|
@ -5,7 +5,9 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -15,9 +17,12 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -25,6 +30,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
@ -34,10 +40,12 @@ import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
@ -50,13 +58,13 @@ public class IslandInfoCommandTest {
|
||||
|
||||
@Mock
|
||||
private CompositeCommand ic;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
|
||||
@Mock
|
||||
private Island island;
|
||||
|
||||
private IslandInfoCommand iic;
|
||||
@ -67,6 +75,10 @@ public class IslandInfoCommandTest {
|
||||
private World world;
|
||||
@Mock
|
||||
private PlaceholdersManager phm;
|
||||
@Mock
|
||||
private @NonNull Location location;
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@ -77,6 +89,12 @@ public class IslandInfoCommandTest {
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
// IWM
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(plugin.getRanksManager()).thenReturn(new RanksManager());
|
||||
|
||||
// Bukkit
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
// Command manager
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
@ -84,10 +102,12 @@ public class IslandInfoCommandTest {
|
||||
// Player
|
||||
when(player.isOp()).thenReturn(false);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
when(player.getUniqueId()).thenReturn(uuid);
|
||||
when(player.getName()).thenReturn("tastybento");
|
||||
when(player.getWorld()).thenReturn(world);
|
||||
user = User.getInstance(player);
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getWorld()).thenReturn(world);
|
||||
when(user.getPlayer()).thenReturn(player);
|
||||
when(user.isPlayer()).thenReturn(true);
|
||||
//user = User.getInstance(player);
|
||||
// Set the User class plugin as this one
|
||||
User.setPlugin(plugin);
|
||||
|
||||
@ -98,12 +118,16 @@ public class IslandInfoCommandTest {
|
||||
// Return the same string
|
||||
when(phm.replacePlaceholders(any(), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(phm);
|
||||
// Translate
|
||||
when(user.getTranslation(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
when(user.getTranslation(anyString(), anyString(), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Island manager
|
||||
island = new Island(location, uuid, 100);
|
||||
when(location.toVector()).thenReturn(new Vector(1,2,3));
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
Optional<Island> optionalIsland = Optional.of(island);
|
||||
when(im.getIslandAt(any())).thenReturn(optionalIsland);
|
||||
when(island.showInfo(any())).thenReturn(true);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||
|
||||
// Players manager
|
||||
@ -141,7 +165,7 @@ public class IslandInfoCommandTest {
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringTooManyArgs() {
|
||||
assertFalse(iic.execute(user, "", Arrays.asList("hdhh", "hdhdhd")));
|
||||
verify(player).sendMessage("commands.help.header");
|
||||
verify(user).sendMessage("commands.help.header", "[label]", "commands.help.console");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,17 +176,7 @@ public class IslandInfoCommandTest {
|
||||
CommandSender console = mock(CommandSender.class);
|
||||
User sender = User.getInstance(console);
|
||||
assertFalse(iic.execute(sender, "", Collections.emptyList()));
|
||||
verify(console).sendMessage("commands.help.header");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandInfoCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsNoIslandFalseInfo() {
|
||||
when(island.showInfo(any())).thenReturn(false);
|
||||
assertFalse(iic.execute(user, "", Collections.emptyList()));
|
||||
verify(player).sendMessage("commands.admin.info.no-island");
|
||||
verify(user, never()).sendMessage("commands.help.header", "[label]", "commands.help.console");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -172,7 +186,7 @@ public class IslandInfoCommandTest {
|
||||
public void testExecuteUserStringListOfStringNoArgsNoIsland() {
|
||||
when(im.getIslandAt(any())).thenReturn(Optional.empty());
|
||||
assertFalse(iic.execute(user, "", Collections.emptyList()));
|
||||
verify(player).sendMessage("commands.admin.info.no-island");
|
||||
verify(user).sendMessage("commands.admin.info.no-island");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,7 +195,20 @@ public class IslandInfoCommandTest {
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsSuccess() {
|
||||
assertTrue(iic.execute(user, "", Collections.emptyList()));
|
||||
verify(island).showInfo(any());
|
||||
verify(user).sendMessage("commands.admin.info.title");
|
||||
verify(user).sendMessage(eq("commands.admin.info.island-uuid"), eq("[uuid]"), any());
|
||||
verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null), eq("[uuid]"), any());
|
||||
verify(user).sendMessage(eq("commands.admin.info.last-login"), eq("[date]"), any());
|
||||
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
|
||||
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
|
||||
verify(user).sendMessage("commands.admin.info.team-members-title");
|
||||
verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "ranks.owner");
|
||||
verify(user).sendMessage("commands.admin.info.island-protection-center", "[xyz]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.island-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.protection-range", "[range]", "100");
|
||||
verify(user).sendMessage("commands.admin.info.max-protection-range", "[range]", "100");
|
||||
verify(user).sendMessage("commands.admin.info.protection-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,7 +217,21 @@ public class IslandInfoCommandTest {
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringArgsSuccess() {
|
||||
assertTrue(iic.execute(user, "", Collections.singletonList("tastybento")));
|
||||
verify(island).showInfo(any());
|
||||
verify(user).sendMessage("commands.admin.info.title");
|
||||
verify(user).sendMessage(eq("commands.admin.info.island-uuid"), eq("[uuid]"), any());
|
||||
verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null), eq("[uuid]"), any());
|
||||
verify(user).sendMessage(eq("commands.admin.info.last-login"), eq("[date]"), any());
|
||||
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
|
||||
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
|
||||
verify(user).sendMessage("commands.admin.info.team-members-title");
|
||||
verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "ranks.owner");
|
||||
verify(user).sendMessage("commands.admin.info.island-protection-center", "[xyz]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.island-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0");
|
||||
verify(user).sendMessage("commands.admin.info.protection-range", "[range]", "100");
|
||||
verify(user).sendMessage("commands.admin.info.max-protection-range", "[range]", "100");
|
||||
verify(user).sendMessage("commands.admin.info.protection-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,7 +241,7 @@ public class IslandInfoCommandTest {
|
||||
public void testExecuteUserStringListOfStringArgsNoIsland() {
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
|
||||
assertFalse(iic.execute(user, "", Collections.singletonList("tastybento")));
|
||||
verify(player).sendMessage("general.errors.player-has-no-island");
|
||||
verify(user).sendMessage("general.errors.player-has-no-island");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,8 +251,8 @@ public class IslandInfoCommandTest {
|
||||
public void testExecuteUserStringListOfStringArgsUnknownPlayer() {
|
||||
when(pm.getUUID(any())).thenReturn(null);
|
||||
assertFalse(iic.execute(user, "", Collections.singletonList("tastybento")));
|
||||
verify(player).sendMessage("general.errors.unknown-player");
|
||||
verify(phm).replacePlaceholders(player, "general.errors.unknown-player");
|
||||
verify(user).sendMessage("general.errors.unknown-player", "[name]", "tastybento");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user