mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-23 15:51:39 +01:00
Added test classes for Team Kick and Leave.
Fixed bugs in the team classes. Completed the Island Info command.
This commit is contained in:
parent
c7d9fed400
commit
030e7e44ca
@ -59,16 +59,15 @@ commands:
|
||||
deaths: "Deaths: [number]"
|
||||
resets-left: "Resets left: [number]/[total]"
|
||||
team-members-title: "Team members:"
|
||||
owner-suffix: "(Owner)"
|
||||
player-prefix: "&b"
|
||||
team-owner-format: "&a[name] [rank]"
|
||||
team-member-format: "&b[name] [rank]"
|
||||
island-location: "Island location: [xyz]"
|
||||
island-coords: "Island coordinates: [xz1] to [xz2]"
|
||||
protection-range: "Protection range: [range]"
|
||||
protection-coords: "Protection coordinates: [xz1] to [xz2]"
|
||||
is-spawn: "Island is a spawn island"
|
||||
is-locked: "Island is locked"
|
||||
is-unlocked: "Island is unlocked"
|
||||
banned-players: "Banned players:"
|
||||
banned-players: "Banned players:"
|
||||
banned-format: "&c[name]"
|
||||
version:
|
||||
description: "display %bsb_plugin_name% and addons versions"
|
||||
setrange:
|
||||
@ -160,6 +159,7 @@ commands:
|
||||
cancel:
|
||||
description: "cancel the pending invite to join your island"
|
||||
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[player] left your island"
|
||||
@ -168,6 +168,7 @@ commands:
|
||||
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:
|
||||
description: "demote a player on your island down a rank"
|
||||
parameters: "<player>"
|
||||
|
4
pom.xml
4
pom.xml
@ -12,7 +12,7 @@
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<powermock.version>1.7.1</powermock.version>
|
||||
<powermock.version>1.7.4</powermock.version>
|
||||
</properties>
|
||||
<build>
|
||||
<defaultGoal>clean package install</defaultGoal>
|
||||
@ -93,7 +93,7 @@
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.7.9</version>
|
||||
<version>0.8.1</version>
|
||||
<configuration>
|
||||
<append>true</append>
|
||||
</configuration>
|
||||
|
@ -19,6 +19,7 @@ import us.tastybento.bskyblock.commands.island.IslandSetnameCommand;
|
||||
import us.tastybento.bskyblock.commands.island.IslandSettingsCommand;
|
||||
import us.tastybento.bskyblock.commands.island.IslandUnbanCommand;
|
||||
import us.tastybento.bskyblock.commands.island.teams.IslandTeamCommand;
|
||||
import us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand;
|
||||
|
||||
public class IslandCommand extends CompositeCommand {
|
||||
|
||||
@ -50,6 +51,8 @@ public class IslandCommand extends CompositeCommand {
|
||||
new IslandBanlistCommand(this);
|
||||
// Team commands
|
||||
new IslandTeamCommand(this);
|
||||
new IslandTeamInviteCommand(this);
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -28,6 +28,7 @@ public class AdminInfoCommand extends CompositeCommand {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
// 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(getPlugin(), user)).orElse(false)) {
|
||||
user.sendMessage("commands.admin.info.no-island");
|
||||
@ -45,7 +46,7 @@ public class AdminInfoCommand extends CompositeCommand {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
// Get rank
|
||||
// Show info for this player
|
||||
getPlugin().getIslands().getIsland(targetUUID).showInfo(getPlugin(), user);
|
||||
return true;
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
|
||||
//new IslandTeamPromoteCommand(this, "demote");
|
||||
new IslandTeamSetownerCommand(this);
|
||||
new IslandTeamKickCommand(this);
|
||||
new IslandTeamInviteAcceptCommand(this);
|
||||
new IslandTeamInviteRejectCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,6 +57,8 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
|
||||
user.sendMessage("commands.island.team.invite.errors.island-is-full");
|
||||
}
|
||||
}
|
||||
// Show members of island
|
||||
getIslands().getIsland(playerUUID).showMembers(getPlugin(), user);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
@ -14,8 +15,8 @@ import us.tastybento.bskyblock.database.objects.Island;
|
||||
|
||||
public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
|
||||
|
||||
public IslandTeamInviteAcceptCommand(IslandTeamInviteCommand islandTeamInviteCommand) {
|
||||
super(islandTeamInviteCommand, "accept");
|
||||
public IslandTeamInviteAcceptCommand(CompositeCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "accept");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,6 +10,7 @@ import java.util.UUID;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
@ -19,8 +20,8 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
|
||||
|
||||
private static final String NAME_PLACEHOLDER = "[name]";
|
||||
|
||||
public IslandTeamInviteCommand(IslandTeamCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "invite");
|
||||
public IslandTeamInviteCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "invite");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -28,9 +29,6 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
|
||||
setPermission(Constants.PERMPREFIX + "island.team");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.team.invite.description");
|
||||
|
||||
new IslandTeamInviteAcceptCommand(this);
|
||||
new IslandTeamInviteRejectCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,10 +58,10 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
|
||||
// Only online players can be invited
|
||||
UUID invitedPlayerUUID = getPlayers().getUUID(args.get(0));
|
||||
if (invitedPlayerUUID == null) {
|
||||
user.sendMessage("general.errors.offline-player");
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
User invitedPlayer = User.getInstance(inviteList.get(invitedPlayerUUID));
|
||||
User invitedPlayer = User.getInstance(invitedPlayerUUID);
|
||||
if (!invitedPlayer.isOnline()) {
|
||||
user.sendMessage("general.errors.offline-player");
|
||||
return false;
|
||||
|
@ -4,14 +4,15 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
|
||||
public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand {
|
||||
|
||||
public IslandTeamInviteRejectCommand(IslandTeamInviteCommand islandTeamInviteCommand) {
|
||||
super(islandTeamInviteCommand, "reject");
|
||||
public IslandTeamInviteRejectCommand(CompositeCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "reject");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,13 +8,14 @@ import java.util.UUID;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
|
||||
public class IslandTeamKickCommand extends AbstractIslandTeamCommand {
|
||||
|
||||
Set<UUID> kickSet;
|
||||
|
||||
public IslandTeamKickCommand(IslandTeamCommand islandTeamCommand) {
|
||||
public IslandTeamKickCommand(CompositeCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "kick");
|
||||
}
|
||||
|
||||
@ -31,11 +32,11 @@ public class IslandTeamKickCommand extends AbstractIslandTeamCommand {
|
||||
public boolean execute(User user, List<String> args) {
|
||||
if (!getPlayers().inTeam(user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (!getTeamLeader(user).equals(user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
@ -46,17 +47,22 @@ public class IslandTeamKickCommand extends AbstractIslandTeamCommand {
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (targetUUID.equals(user.getUniqueId())) {
|
||||
user.sendMessage("commands.island.kick.cannot-kick");
|
||||
return false;
|
||||
}
|
||||
if (!getIslands().getMembers(user.getUniqueId()).contains(targetUUID)) {
|
||||
user.sendMessage("general.errors.not-in-team");
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (!getSettings().isKickConfirmation() || kickSet.contains(targetUUID)) {
|
||||
kickSet.remove(targetUUID);
|
||||
User.getInstance(targetUUID).sendMessage("commands.island.team.kick.leader-kicked");
|
||||
getIslands().removePlayer(targetUUID);
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("commands.island.team.kick.type-again");
|
||||
kickSet.add(targetUUID);
|
||||
@ -69,8 +75,8 @@ public class IslandTeamKickCommand extends AbstractIslandTeamCommand {
|
||||
user.sendMessage("general.errors.command-cancelled");
|
||||
}
|
||||
}}.runTaskLater(getPlugin(), getSettings().getKickWait() * 20);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,13 +8,14 @@ import java.util.UUID;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
|
||||
public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand {
|
||||
|
||||
Set<UUID> leaveSet;
|
||||
|
||||
public IslandTeamLeaveCommand(IslandTeamCommand islandTeamCommand) {
|
||||
public IslandTeamLeaveCommand(CompositeCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "leave");
|
||||
}
|
||||
|
||||
@ -31,8 +32,12 @@ public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand {
|
||||
if (!getPlayers().inTeam(user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().hasIsland(user.getUniqueId())) {
|
||||
user.sendMessage("commands.island.team.leave.cannot-leave");
|
||||
return false;
|
||||
}
|
||||
if (!getSettings().isKickConfirmation() || leaveSet.contains(user.getUniqueId())) {
|
||||
if (!getSettings().isLeaveConfirmation() || leaveSet.contains(user.getUniqueId())) {
|
||||
leaveSet.remove(user.getUniqueId());
|
||||
UUID leaderUUID = getIslands().getTeamLeader(user.getUniqueId());
|
||||
if (leaderUUID != null) {
|
||||
@ -53,7 +58,7 @@ public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand {
|
||||
user.sendMessage("general.errors.command-cancelled");
|
||||
}
|
||||
}}.runTaskLater(getPlugin(), getSettings().getLeaveWait() * 20);
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,11 +3,12 @@ package us.tastybento.bskyblock.commands.island.teams;
|
||||
import java.util.List;
|
||||
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
|
||||
public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand {
|
||||
|
||||
public IslandTeamPromoteCommand(IslandTeamCommand islandTeamCommand, String string) {
|
||||
public IslandTeamPromoteCommand(CompositeCommand islandTeamCommand, String string) {
|
||||
super(islandTeamCommand, string);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
@ -15,7 +16,7 @@ import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
|
||||
|
||||
public IslandTeamSetownerCommand(IslandTeamCommand islandTeamCommand) {
|
||||
public IslandTeamSetownerCommand(CompositeCommand islandTeamCommand) {
|
||||
super(islandTeamCommand, "setleader");
|
||||
}
|
||||
|
||||
|
@ -643,7 +643,7 @@ public class Island implements DataObject {
|
||||
public void setWorld(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show info on the island
|
||||
* @param plugin
|
||||
@ -651,7 +651,6 @@ public class Island implements DataObject {
|
||||
* @return true always
|
||||
*/
|
||||
public boolean showInfo(BSkyBlock plugin, User user) {
|
||||
// TODO show ranks
|
||||
user.sendMessage("commands.admin.info.title");
|
||||
user.sendMessage("commands.admin.info.owner", "[owner]", plugin.getPlayers().getName(owner), "[uuid]", owner.toString());
|
||||
Date d = new Date(plugin.getServer().getOfflinePlayer(owner).getLastPlayed());
|
||||
@ -660,22 +659,51 @@ public class Island implements DataObject {
|
||||
String resets = String.valueOf(plugin.getPlayers().getResetsLeft(owner));
|
||||
String total = plugin.getSettings().getResetLimit() < 0 ? "Unlimited" : String.valueOf(plugin.getSettings().getResetLimit());
|
||||
user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total);
|
||||
user.sendMessage("commands.admin.info.team-members-title");
|
||||
user.sendMessage("commands.admin.info.owner-suffix");
|
||||
user.sendMessage("commands.admin.info.player-prefix");
|
||||
String location = center.toVector().toString();
|
||||
user.sendMessage("commands.admin.info.island-location", "[xyz]", location);
|
||||
String from = center.toVector().subtract(new Vector(range, 0, range)).toString();
|
||||
String to = center.toVector().add(new Vector(range, 0, range)).toString();
|
||||
user.sendMessage("commands.admin.info.island-coords", "[xz1]", from, "[xz2]", to);
|
||||
// Show team members
|
||||
showMembers(plugin, user);
|
||||
Vector location = center.toVector();
|
||||
user.sendMessage("commands.admin.info.island-location", "[xyz]", xyz(location));
|
||||
Vector from = center.toVector().subtract(new Vector(range, 0, range)).setY(0);
|
||||
Vector to = center.toVector().add(new Vector(range-1, 0, range-1)).setY(center.getWorld().getMaxHeight());
|
||||
user.sendMessage("commands.admin.info.island-coords", "[xz1]", xyz(from), "[xz2]", xyz(to));
|
||||
user.sendMessage("commands.admin.info.protection-range", "[range]", String.valueOf(range));
|
||||
String pfrom = center.toVector().subtract(new Vector(protectionRange, 0, protectionRange)).toString();
|
||||
String pto = center.toVector().add(new Vector(protectionRange, 0, protectionRange)).toString();
|
||||
user.sendMessage("commands.admin.info.protection-coords", "[xz1]", pfrom, "[xz2]", pto);
|
||||
user.sendMessage("commands.admin.info.is-spawn");
|
||||
user.sendMessage("commands.admin.info.is-locked");
|
||||
user.sendMessage("commands.admin.info.is-unlocked");
|
||||
user.sendMessage("commands.admin.info.banned-players");
|
||||
Vector pfrom = center.toVector().subtract(new Vector(protectionRange, 0, protectionRange)).setY(0);
|
||||
Vector pto = center.toVector().add(new Vector(protectionRange-1, 0, protectionRange-1)).setY(center.getWorld().getMaxHeight());;
|
||||
user.sendMessage("commands.admin.info.protection-coords", "[xz1]", xyz(pfrom), "[xz2]", xyz(pto));
|
||||
if (spawn) {
|
||||
user.sendMessage("commands.admin.info.is-spawn");
|
||||
}
|
||||
Set<UUID> banned = getBanned();
|
||||
if (!banned.isEmpty()) {
|
||||
user.sendMessage("commands.admin.info.banned-players");
|
||||
banned.forEach(u -> user.sendMessage("commands.admin.info.banned-format", "[name]", plugin.getPlayers().getName(u)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String xyz(Vector location) {
|
||||
return location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the members of this island
|
||||
* @param plugin
|
||||
* @param user - user who is requesting
|
||||
*/
|
||||
public void showMembers(BSkyBlock plugin, User user) {
|
||||
if (plugin.getPlayers().inTeam(user.getUniqueId())) {
|
||||
user.sendMessage("commands.admin.info.team-members-title");
|
||||
members.forEach((u, i) -> {
|
||||
if (owner.equals(u)) {
|
||||
user.sendMessage("commands.admin.info.team-owner-format", "[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", "[name]", plugin.getPlayers().getName(u)
|
||||
, "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -669,7 +669,6 @@ public class IslandsManager {
|
||||
return false;
|
||||
}
|
||||
// Get the player's island
|
||||
Optional<Island> ii = getIslandAt(loc);
|
||||
return getIslandAt(loc).filter(i -> i.onIsland(loc)).map(i -> i.getMemberSet().contains(player.getUniqueId())).orElse(false);
|
||||
}
|
||||
|
||||
@ -809,5 +808,4 @@ public class IslandsManager {
|
||||
islandCache.clear();
|
||||
handler.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class IslandCache {
|
||||
plugin.logWarning("Denied island is owned by " + plugin.getPlayers().getName(newIsland.getOwner()));
|
||||
plugin.logWarning(newIsland.getOwner().toString() + ".yml");
|
||||
} else {
|
||||
plugin.logWarning("Denied island is unowned and was just found in the islands folder. Skipping it...");
|
||||
plugin.logWarning("Denied island is unowned and is a database duplicate. Skipping it...");
|
||||
}
|
||||
plugin.logWarning("Recommend that the denied player file is deleted otherwise weird things can happen.");
|
||||
return false;
|
||||
|
@ -0,0 +1,228 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.commands.island.teams;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
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.IslandsManager;
|
||||
import us.tastybento.bskyblock.managers.LocalesManager;
|
||||
import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class IslandTeamKickCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private IslandCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// 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(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
ic = mock(IslandCommand.class);
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any())).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any())).thenReturn(true);
|
||||
when(im.getTeamLeader(Mockito.any())).thenReturn(uuid);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(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(plugin.getLocalesManager()).thenReturn(lm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamKickCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTeam() {
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-team"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamKickCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNotTeamLeader() {
|
||||
when(im.getTeamLeader(Mockito.any())).thenReturn(notUUID);
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-leader"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamKickCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTarget() {
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, new ArrayList<>()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamKickCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamKickCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSamePlayer() {
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(uuid);
|
||||
assertFalse(itl.execute(user, Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.kick.cannot-kick"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamKickCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteDifferentPlayerNotInTeam() {
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.getMembers(Mockito.any())).thenReturn(new HashSet<>());
|
||||
assertFalse(itl.execute(user, Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-in-team"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamKickCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoConfirmation() {
|
||||
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())).thenReturn(members);
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertTrue(itl.execute(user, Arrays.asList(name)));
|
||||
Mockito.verify(im).removePlayer(notUUID);
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamKickCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteWithConfirmation() {
|
||||
when(s.isKickConfirmation()).thenReturn(true);
|
||||
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
|
||||
Set<UUID> members = new HashSet<>();
|
||||
members.add(notUUID);
|
||||
when(im.getMembers(Mockito.any())).thenReturn(members);
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, Arrays.asList(name)));
|
||||
// Confirmation required
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.kick.type-again"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.commands.island.teams;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
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.IslandsManager;
|
||||
import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class IslandTeamLeaveCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private IslandCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = 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.getName()).thenReturn("tastybento");
|
||||
|
||||
// Parent command has no aliases
|
||||
ic = mock(IslandCommand.class);
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any())).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any())).thenReturn(true);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamLeaveCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTeam() {
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
|
||||
assertFalse(itl.execute(user, new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-team"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamLeaveCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteInTeamLeader() {
|
||||
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
|
||||
assertFalse(itl.execute(user, new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.leave.cannot-leave"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamLeaveCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoConfirmation() {
|
||||
when(s.isLeaveConfirmation()).thenReturn(false);
|
||||
when(im.hasIsland(Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.isOwner(Mockito.eq(uuid))).thenReturn(false);
|
||||
// Add a team leader - null
|
||||
when(im.getTeamLeader(Mockito.any())).thenReturn(null);
|
||||
|
||||
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
|
||||
assertTrue(itl.execute(user, new ArrayList<>()));
|
||||
Mockito.verify(im).removePlayer(uuid);
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamLeaveCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteWithConfirmation() {
|
||||
when(s.isLeaveConfirmation()).thenReturn(true);
|
||||
// 3 second timeout
|
||||
when(s.getLeaveWait()).thenReturn(3L);
|
||||
when(im.hasIsland(Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.isOwner(Mockito.eq(uuid))).thenReturn(false);
|
||||
// Add a team leader - null
|
||||
when(im.getTeamLeader(Mockito.any())).thenReturn(null);
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
}
|
@ -68,24 +68,6 @@ public class IslandsManagerTest {
|
||||
private Location location;
|
||||
private BlockState blockState;
|
||||
|
||||
/*
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
Server server = mock(Server.class);
|
||||
world = mock(World.class);
|
||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
when(server.getWorld("world")).thenReturn(world);
|
||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
||||
Bukkit.setServer(server);
|
||||
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user