mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-13 19:01:28 +01:00
Adds invites to trust and coop (#971)
Implements https://github.com/BentoBoxWorld/BentoBox/issues/800 * WIP * Generic invites for team, coop and trusting. Needs play testing. https://github.com/BentoBoxWorld/BentoBox/issues/800 * Fixed tests and added handling in trust and coop commands * Completes invite, trust and coops command and tests. * Minor documentation/settings improvements * Renamed InviteType to Invite.Type * Fixed compilation error
This commit is contained in:
parent
d27ea949d0
commit
6f96f47ae5
@ -143,6 +143,11 @@ public class Settings implements ConfigObject {
|
|||||||
@ConfigEntry(path = "island.confirmation.commands.reset")
|
@ConfigEntry(path = "island.confirmation.commands.reset")
|
||||||
private boolean resetConfirmation = true;
|
private boolean resetConfirmation = true;
|
||||||
|
|
||||||
|
@ConfigComment("Ask the recipient to confirm trust or coop invites.")
|
||||||
|
@ConfigComment("Team invites will always require confirmation, for safety concerns.")
|
||||||
|
@ConfigEntry(path = "island.confirmation.invites", since = "1.8.0")
|
||||||
|
private boolean inviteConfirmation = false;
|
||||||
|
|
||||||
@ConfigComment("Sets the minimum length an island custom name is required to have.")
|
@ConfigComment("Sets the minimum length an island custom name is required to have.")
|
||||||
@ConfigEntry(path = "island.name.min-length")
|
@ConfigEntry(path = "island.name.min-length")
|
||||||
private int nameMinLength = 4;
|
private int nameMinLength = 4;
|
||||||
@ -560,5 +565,19 @@ public class Settings implements ConfigObject {
|
|||||||
this.clearRadius = clearRadius;
|
this.clearRadius = clearRadius;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the inviteConfirmation
|
||||||
|
* @since 1.8.0
|
||||||
|
*/
|
||||||
|
public boolean isInviteConfirmation() {
|
||||||
|
return inviteConfirmation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param inviteConfirmation the inviteConfirmation to set
|
||||||
|
* @since 1.8.0
|
||||||
|
*/
|
||||||
|
public void setInviteConfirmation(boolean inviteConfirmation) {
|
||||||
|
this.inviteConfirmation = inviteConfirmation;
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
package world.bentobox.bentobox.api.commands.island.team;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an invite
|
||||||
|
* @author tastybento
|
||||||
|
* @since 1.8.0
|
||||||
|
*/
|
||||||
|
public class Invite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of invitation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum Type {
|
||||||
|
COOP,
|
||||||
|
TEAM,
|
||||||
|
TRUST
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Type type;
|
||||||
|
private final UUID inviter;
|
||||||
|
private final UUID invitee;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param type
|
||||||
|
* @param inviter
|
||||||
|
* @param invitee
|
||||||
|
*/
|
||||||
|
public Invite(Type type, UUID inviter, UUID invitee) {
|
||||||
|
this.type = type;
|
||||||
|
this.inviter = inviter;
|
||||||
|
this.invitee = invitee;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the type
|
||||||
|
*/
|
||||||
|
public Type getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the inviter
|
||||||
|
*/
|
||||||
|
public UUID getInviter() {
|
||||||
|
return inviter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the invitee
|
||||||
|
*/
|
||||||
|
public UUID getInvitee() {
|
||||||
|
return invitee;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#hashCode()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(invitee, inviter, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!(obj instanceof Invite)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Invite other = (Invite) obj;
|
||||||
|
return Objects.equals(invitee, other.invitee) && Objects.equals(inviter, other.inviter) && type == other.type;
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,15 @@
|
|||||||
package world.bentobox.bentobox.api.commands.island.team;
|
package world.bentobox.bentobox.api.commands.island.team;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
@ -14,10 +18,17 @@ import world.bentobox.bentobox.api.user.User;
|
|||||||
|
|
||||||
public class IslandTeamCommand extends CompositeCommand {
|
public class IslandTeamCommand extends CompositeCommand {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invited list. Key is the invited party, value is the invite.
|
||||||
|
* @since 1.8.0
|
||||||
|
*/
|
||||||
|
private Map<UUID, Invite> inviteList;
|
||||||
|
|
||||||
private IslandTeamInviteCommand inviteCommand;
|
private IslandTeamInviteCommand inviteCommand;
|
||||||
|
|
||||||
public IslandTeamCommand(CompositeCommand parent) {
|
public IslandTeamCommand(CompositeCommand parent) {
|
||||||
super(parent, "team");
|
super(parent, "team");
|
||||||
|
inviteList = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -81,10 +92,54 @@ public class IslandTeamCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the inviteCommand
|
*
|
||||||
|
* @param type
|
||||||
|
* @param inviter
|
||||||
|
* @param invitee
|
||||||
|
* @since 1.8.0
|
||||||
*/
|
*/
|
||||||
public IslandTeamInviteCommand getInviteCommand() {
|
public void addInvite(Invite.Type type, @NonNull UUID inviter, @NonNull UUID invitee) {
|
||||||
return inviteCommand;
|
inviteList.put(invitee, new Invite(type, inviter, invitee));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param invitee
|
||||||
|
* @return
|
||||||
|
* @since 1.8.0
|
||||||
|
*/
|
||||||
|
public boolean isInvited(@NonNull UUID invitee) {
|
||||||
|
return inviteList.containsKey(invitee);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get whoever invited invitee
|
||||||
|
* @param invitee - uuid
|
||||||
|
* @return UUID of inviter, or null if invitee has not been invited
|
||||||
|
* @since 1.8.0
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public UUID getInviter(UUID invitee) {
|
||||||
|
return isInvited(invitee) ? inviteList.get(invitee).getInviter() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the invite for an invitee.
|
||||||
|
* @param invitee - UUID of invitee
|
||||||
|
* @return invite or null if none
|
||||||
|
* @since 1.8.0
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Invite getInvite(UUID invitee) {
|
||||||
|
return inviteList.get(invitee);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a pending invite.
|
||||||
|
* @param uniqueId - UUID of invited user
|
||||||
|
* @since 1.8.0
|
||||||
|
*/
|
||||||
|
public void removeInvite(@NonNull UUID uniqueId) {
|
||||||
|
inviteList.remove(uniqueId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import java.util.UUID;
|
|||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
|
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
@ -20,10 +21,12 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
*/
|
*/
|
||||||
public class IslandTeamCoopCommand extends CompositeCommand {
|
public class IslandTeamCoopCommand extends CompositeCommand {
|
||||||
|
|
||||||
|
private IslandTeamCommand itc;
|
||||||
private @Nullable UUID targetUUID;
|
private @Nullable UUID targetUUID;
|
||||||
|
|
||||||
public IslandTeamCoopCommand(CompositeCommand parentCommand) {
|
public IslandTeamCoopCommand(IslandTeamCommand parentCommand) {
|
||||||
super(parentCommand, "coop");
|
super(parentCommand, "coop");
|
||||||
|
this.itc = parentCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -72,6 +75,11 @@ public class IslandTeamCoopCommand extends CompositeCommand {
|
|||||||
user.sendMessage("commands.island.team.coop.already-has-rank");
|
user.sendMessage("commands.island.team.coop.already-has-rank");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (itc.isInvited(targetUUID) && itc.getInviter(targetUUID).equals(user.getUniqueId()) && itc.getInvite(targetUUID).getType().equals(Type.COOP)) {
|
||||||
|
// Prevent spam
|
||||||
|
user.sendMessage("commands.island.team.invite.errors.you-have-already-invited");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,9 +88,19 @@ public class IslandTeamCoopCommand extends CompositeCommand {
|
|||||||
User target = User.getInstance(targetUUID);
|
User target = User.getInstance(targetUUID);
|
||||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||||
if (island != null) {
|
if (island != null) {
|
||||||
|
if (getPlugin().getSettings().isInviteConfirmation()) {
|
||||||
|
// Put the invited player (key) onto the list with inviter (value)
|
||||||
|
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
||||||
|
itc.addInvite(Invite.Type.COOP, user.getUniqueId(), target.getUniqueId());
|
||||||
|
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName());
|
||||||
|
// Send message to online player
|
||||||
|
target.sendMessage("commands.island.team.coop.name-has-invited-you", TextVariables.NAME, user.getName());
|
||||||
|
target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
|
||||||
|
} else {
|
||||||
island.setRank(target, RanksManager.COOP_RANK);
|
island.setRank(target, RanksManager.COOP_RANK);
|
||||||
user.sendMessage("commands.island.team.coop.success", TextVariables.NAME, target.getName());
|
user.sendMessage("commands.island.team.coop.success", TextVariables.NAME, target.getName());
|
||||||
target.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, user.getName());
|
target.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, user.getName());
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Should not happen
|
// Should not happen
|
||||||
|
@ -6,14 +6,14 @@ import java.util.UUID;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||||
|
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
@ -40,8 +40,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||||||
public boolean canExecute(User user, String label, List<String> args) {
|
public boolean canExecute(User user, String label, List<String> args) {
|
||||||
playerUUID = user.getUniqueId();
|
playerUUID = user.getUniqueId();
|
||||||
// Check if player has been invited
|
// Check if player has been invited
|
||||||
BiMap<UUID, UUID> inviteList = itc.getInviteCommand().getInviteList();
|
if (!itc.isInvited(playerUUID)) {
|
||||||
if (!inviteList.containsKey(playerUUID)) {
|
|
||||||
user.sendMessage("commands.island.team.invite.errors.none-invited-you");
|
user.sendMessage("commands.island.team.invite.errors.none-invited-you");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -51,12 +50,14 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Get the island owner
|
// Get the island owner
|
||||||
prospectiveOwnerUUID = inviteList.get(playerUUID);
|
prospectiveOwnerUUID = itc.getInviter(playerUUID);
|
||||||
if (!getIslands().hasIsland(getWorld(), prospectiveOwnerUUID)) {
|
if (!getIslands().hasIsland(getWorld(), prospectiveOwnerUUID)) {
|
||||||
user.sendMessage("commands.island.team.invite.errors.invalid-invite");
|
user.sendMessage("commands.island.team.invite.errors.invalid-invite");
|
||||||
inviteList.remove(playerUUID);
|
itc.removeInvite(playerUUID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Invite invite = itc.getInvite(playerUUID);
|
||||||
|
if (invite.getType().equals(Type.TEAM)) {
|
||||||
// Fire event so add-ons can run commands, etc.
|
// Fire event so add-ons can run commands, etc.
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
IslandBaseEvent event = TeamEvent.builder()
|
||||||
.island(getIslands().getIsland(getWorld(), prospectiveOwnerUUID))
|
.island(getIslands().getIsland(getWorld(), prospectiveOwnerUUID))
|
||||||
@ -66,12 +67,57 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
return !event.isCancelled();
|
return !event.isCancelled();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
askConfirmation(user, user.getTranslation("commands.island.team.invite.accept.confirmation"), () -> {
|
// Get the invite
|
||||||
|
Invite invite = itc.getInvite(playerUUID);
|
||||||
|
switch (invite.getType()) {
|
||||||
|
case COOP:
|
||||||
|
askConfirmation(user, () -> acceptCoopInvite(user, invite));
|
||||||
|
break;
|
||||||
|
case TRUST:
|
||||||
|
askConfirmation(user, () -> acceptTrustInvite(user, invite));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
askConfirmation(user, user.getTranslation("commands.island.team.invite.accept.confirmation"), () -> acceptTeamInvite(user, invite));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void acceptTrustInvite(User user, Invite invite) {
|
||||||
// Remove the invite
|
// Remove the invite
|
||||||
itc.getInviteCommand().getInviteList().remove(playerUUID);
|
itc.removeInvite(playerUUID);
|
||||||
|
User inviter = User.getInstance(invite.getInviter());
|
||||||
|
if (inviter != null) {
|
||||||
|
Island island = getIslands().getIsland(getWorld(), inviter);
|
||||||
|
if (island != null) {
|
||||||
|
island.setRank(user, RanksManager.TRUSTED_RANK);
|
||||||
|
inviter.sendMessage("commands.island.team.trust.success", TextVariables.NAME, user.getName());
|
||||||
|
user.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, inviter.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void acceptCoopInvite(User user, Invite invite) {
|
||||||
|
// Remove the invite
|
||||||
|
itc.removeInvite(playerUUID);
|
||||||
|
User inviter = User.getInstance(invite.getInviter());
|
||||||
|
if (inviter != null) {
|
||||||
|
Island island = getIslands().getIsland(getWorld(), inviter);
|
||||||
|
if (island != null) {
|
||||||
|
island.setRank(user, RanksManager.COOP_RANK);
|
||||||
|
inviter.sendMessage("commands.island.team.coop.success", TextVariables.NAME, user.getName());
|
||||||
|
user.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, inviter.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void acceptTeamInvite(User user, Invite invite) {
|
||||||
|
// Remove the invite
|
||||||
|
itc.removeInvite(playerUUID);
|
||||||
// Put player into Spectator mode
|
// Put player into Spectator mode
|
||||||
user.setGameMode(GameMode.SPECTATOR);
|
user.setGameMode(GameMode.SPECTATOR);
|
||||||
// Get the player's island - may be null if the player has no island
|
// Get the player's island - may be null if the player has no island
|
||||||
@ -99,7 +145,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||||||
user.setGameMode(getIWM().getDefaultGameMode(getWorld()));
|
user.setGameMode(getIWM().getDefaultGameMode(getWorld()));
|
||||||
|
|
||||||
user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel());
|
user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel());
|
||||||
User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID));
|
User inviter = User.getInstance(invite.getInviter());
|
||||||
if (inviter != null) {
|
if (inviter != null) {
|
||||||
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName());
|
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName());
|
||||||
}
|
}
|
||||||
@ -111,9 +157,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(e);
|
Bukkit.getServer().getPluginManager().callEvent(e);
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanPlayer(User user) {
|
private void cleanPlayer(User user) {
|
||||||
|
@ -7,12 +7,9 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
|
||||||
import com.google.common.collect.HashBiMap;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
|
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
@ -22,10 +19,11 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
|
|
||||||
public class IslandTeamInviteCommand extends CompositeCommand {
|
public class IslandTeamInviteCommand extends CompositeCommand {
|
||||||
|
|
||||||
private BiMap<UUID, UUID> inviteList;
|
private IslandTeamCommand itc;
|
||||||
|
|
||||||
public IslandTeamInviteCommand(CompositeCommand islandCommand) {
|
public IslandTeamInviteCommand(IslandTeamCommand parent) {
|
||||||
super(islandCommand, "invite");
|
super(parent, "invite");
|
||||||
|
itc = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -33,7 +31,6 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||||||
setPermission("island.team");
|
setPermission("island.team");
|
||||||
setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
setDescription("commands.island.team.invite.description");
|
setDescription("commands.island.team.invite.description");
|
||||||
inviteList = HashBiMap.create();
|
|
||||||
setConfigurableRankCommand();
|
setConfigurableRankCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,10 +50,21 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
UUID playerUUID = user.getUniqueId();
|
UUID playerUUID = user.getUniqueId();
|
||||||
if (args.isEmpty() || args.size() > 1) {
|
if (args.isEmpty() || args.size() > 1) {
|
||||||
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far
|
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far and why
|
||||||
if (inviteList.containsKey(playerUUID)) {
|
if (itc.isInvited(playerUUID)) {
|
||||||
OfflinePlayer inviter = Bukkit.getServer().getOfflinePlayer(inviteList.get(playerUUID));
|
Invite invite = itc.getInvite(playerUUID);
|
||||||
user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, inviter.getName());
|
String name = getPlayers().getName(playerUUID);
|
||||||
|
switch (invite.getType()) {
|
||||||
|
case COOP:
|
||||||
|
user.sendMessage("commands.island.team.invite.name-has-invited-you.coop", TextVariables.NAME, name);
|
||||||
|
break;
|
||||||
|
case TRUST:
|
||||||
|
user.sendMessage("commands.island.team.invite.name-has-invited-you.trust", TextVariables.NAME, name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Show help
|
// Show help
|
||||||
@ -95,6 +103,11 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||||||
user.sendMessage("commands.island.team.invite.errors.already-on-team");
|
user.sendMessage("commands.island.team.invite.errors.already-on-team");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (itc.isInvited(invitedPlayerUUID) && itc.getInviter(invitedPlayerUUID).equals(user.getUniqueId()) && itc.getInvite(invitedPlayerUUID).getType().equals(Type.TEAM)) {
|
||||||
|
// Prevent spam
|
||||||
|
user.sendMessage("commands.island.team.invite.errors.you-have-already-invited");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return invite(user,invitedPlayer);
|
return invite(user,invitedPlayer);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -106,8 +119,8 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||||||
if (teamMembers.size() < maxSize) {
|
if (teamMembers.size() < maxSize) {
|
||||||
// If that player already has an invite out then retract it.
|
// If that player already has an invite out then retract it.
|
||||||
// Players can only have one invite one at a time - interesting
|
// Players can only have one invite one at a time - interesting
|
||||||
if (inviteList.containsValue(user.getUniqueId())) {
|
if (itc.isInvited(user.getUniqueId())) {
|
||||||
inviteList.inverse().remove(user.getUniqueId());
|
itc.removeInvite(user.getUniqueId());
|
||||||
user.sendMessage("commands.island.team.invite.removing-invite");
|
user.sendMessage("commands.island.team.invite.removing-invite");
|
||||||
}
|
}
|
||||||
// Fire event so add-ons can run commands, etc.
|
// Fire event so add-ons can run commands, etc.
|
||||||
@ -122,7 +135,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
// Put the invited player (key) onto the list with inviter (value)
|
// Put the invited player (key) onto the list with inviter (value)
|
||||||
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
||||||
inviteList.put(invitedPlayer.getUniqueId(), user.getUniqueId());
|
itc.addInvite(Invite.Type.TEAM, invitedPlayer.getUniqueId(), user.getUniqueId());
|
||||||
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, invitedPlayer.getName());
|
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, invitedPlayer.getName());
|
||||||
// Send message to online player
|
// Send message to online player
|
||||||
invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, user.getName());
|
invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, user.getName());
|
||||||
@ -148,14 +161,6 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||||||
return Optional.of(Util.tabLimit(options, lastArg));
|
return Optional.of(Util.tabLimit(options, lastArg));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Order is Invited, Inviter
|
|
||||||
* @return the inviteList
|
|
||||||
*/
|
|
||||||
public BiMap<UUID, UUID> getInviteList() {
|
|
||||||
return inviteList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the maximum team size for this player in this game based on the permission or the world's setting
|
* Gets the maximum team size for this player in this game based on the permission or the world's setting
|
||||||
* @param user user
|
* @param user user
|
||||||
|
@ -31,11 +31,11 @@ public class IslandTeamInviteRejectCommand extends CompositeCommand {
|
|||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
UUID playerUUID = user.getUniqueId();
|
UUID playerUUID = user.getUniqueId();
|
||||||
// Reject /island reject
|
// Reject /island reject
|
||||||
if (itc.getInviteCommand().getInviteList().containsKey(playerUUID)) {
|
if (itc.isInvited(playerUUID)) {
|
||||||
// Fire event so add-ons can run commands, etc.
|
// Fire event so add-ons can run commands, etc.
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
IslandBaseEvent event = TeamEvent.builder()
|
||||||
.island(getIslands()
|
.island(getIslands()
|
||||||
.getIsland(getWorld(), itc.getInviteCommand().getInviteList().get(playerUUID)))
|
.getIsland(getWorld(), itc.getInviter(playerUUID)))
|
||||||
.reason(TeamEvent.Reason.REJECT)
|
.reason(TeamEvent.Reason.REJECT)
|
||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build();
|
||||||
@ -45,10 +45,10 @@ public class IslandTeamInviteRejectCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove this player from the global invite list
|
// Remove this player from the global invite list
|
||||||
itc.getInviteCommand().getInviteList().remove(user.getUniqueId());
|
itc.removeInvite(user.getUniqueId());
|
||||||
user.sendMessage("commands.island.team.invite.reject.you-rejected-invite");
|
user.sendMessage("commands.island.team.invite.reject.you-rejected-invite");
|
||||||
|
|
||||||
User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID));
|
User inviter = User.getInstance(itc.getInviter(playerUUID));
|
||||||
if (inviter != null) {
|
if (inviter != null) {
|
||||||
inviter.sendMessage("commands.island.team.invite.reject.name-rejected-your-invite", TextVariables.NAME, user.getName());
|
inviter.sendMessage("commands.island.team.invite.reject.name-rejected-your-invite", TextVariables.NAME, user.getName());
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,10 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
|
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
@ -18,8 +21,12 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
*/
|
*/
|
||||||
public class IslandTeamTrustCommand extends CompositeCommand {
|
public class IslandTeamTrustCommand extends CompositeCommand {
|
||||||
|
|
||||||
public IslandTeamTrustCommand(CompositeCommand parentCommand) {
|
IslandTeamCommand itc;
|
||||||
|
private @Nullable UUID targetUUID;
|
||||||
|
|
||||||
|
public IslandTeamTrustCommand(IslandTeamCommand parentCommand) {
|
||||||
super(parentCommand, "trust");
|
super(parentCommand, "trust");
|
||||||
|
this.itc = parentCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -32,7 +39,7 @@ public class IslandTeamTrustCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean canExecute(User user, String label, List<String> args) {
|
||||||
if (args.size() != 1) {
|
if (args.size() != 1) {
|
||||||
// Show help
|
// Show help
|
||||||
showHelp(this, user);
|
showHelp(this, user);
|
||||||
@ -50,22 +57,18 @@ public class IslandTeamTrustCommand extends CompositeCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Get target player
|
// Get target player
|
||||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
targetUUID = getPlayers().getUUID(args.get(0));
|
||||||
if (targetUUID == null) {
|
if (targetUUID == null) {
|
||||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (getSettings().getTrustCooldown() <= 0 || !checkCooldown(user, island.getUniqueId(), targetUUID.toString())) && trustCmd(user, targetUUID);
|
// Check cooldown
|
||||||
}
|
if (getSettings().getTrustCooldown() > 0 && checkCooldown(user, island.getUniqueId(), targetUUID.toString())) {
|
||||||
|
|
||||||
private boolean trustCmd(User user, UUID targetUUID) {
|
|
||||||
// Player cannot trust themselves
|
|
||||||
if (user.getUniqueId().equals(targetUUID)) {
|
|
||||||
user.sendMessage("commands.island.team.trust.trust-in-yourself");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) {
|
// Player cannot coop themselves
|
||||||
user.sendMessage("commands.island.team.trust.members-trusted");
|
if (user.getUniqueId().equals(targetUUID)) {
|
||||||
|
user.sendMessage("commands.island.team.trust.trust-in-yourself");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
User target = User.getInstance(targetUUID);
|
User target = User.getInstance(targetUUID);
|
||||||
@ -74,11 +77,32 @@ public class IslandTeamTrustCommand extends CompositeCommand {
|
|||||||
user.sendMessage("commands.island.team.trust.player-already-trusted");
|
user.sendMessage("commands.island.team.trust.player-already-trusted");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (itc.isInvited(targetUUID) && itc.getInviter(targetUUID).equals(user.getUniqueId()) && itc.getInvite(targetUUID).getType().equals(Type.TRUST)) {
|
||||||
|
// Prevent spam
|
||||||
|
user.sendMessage("commands.island.team.invite.errors.you-have-already-invited");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
|
User target = User.getInstance(targetUUID);
|
||||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||||
if (island != null) {
|
if (island != null) {
|
||||||
|
if (getPlugin().getSettings().isInviteConfirmation()) {
|
||||||
|
// Put the invited player (key) onto the list with inviter (value)
|
||||||
|
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
||||||
|
itc.addInvite(Type.TRUST, user.getUniqueId(), target.getUniqueId());
|
||||||
|
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName());
|
||||||
|
// Send message to online player
|
||||||
|
target.sendMessage("commands.island.team.trust.name-has-invited-you", TextVariables.NAME, user.getName());
|
||||||
|
target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
|
||||||
|
} else {
|
||||||
island.setRank(target, RanksManager.TRUSTED_RANK);
|
island.setRank(target, RanksManager.TRUSTED_RANK);
|
||||||
user.sendMessage("commands.island.team.trust.success", TextVariables.NAME, target.getName());
|
user.sendMessage("commands.island.team.trust.success", TextVariables.NAME, target.getName());
|
||||||
target.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, user.getName());
|
target.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, user.getName());
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Should not happen
|
// Should not happen
|
||||||
@ -87,6 +111,35 @@ public class IslandTeamTrustCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||||
|
if (island != null) {
|
||||||
|
if (getPlugin().getSettings().isInviteConfirmation()) {
|
||||||
|
if (itc.isInvited(targetUUID) && itc.getInviter(targetUUID).equals(user.getUniqueId()) && itc.getInvite(targetUUID).getType().equals(Type.TRUST)) {
|
||||||
|
// Prevent spam
|
||||||
|
user.sendMessage("commands.island.team.invite.errors.you-have-already-invited");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Put the invited player (key) onto the list with inviter (value)
|
||||||
|
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
||||||
|
itc.addInvite(Type.TRUST, user.getUniqueId(), target.getUniqueId());
|
||||||
|
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName());
|
||||||
|
// Send message to online player
|
||||||
|
target.sendMessage("commands.island.team.trust.name-has-invited-you", TextVariables.NAME, user.getName());
|
||||||
|
target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
|
||||||
|
} else {
|
||||||
|
island.setRank(target, RanksManager.TRUSTED_RANK);
|
||||||
|
user.sendMessage("commands.island.team.trust.success", TextVariables.NAME, target.getName());
|
||||||
|
target.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, user.getName());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// Should not happen
|
||||||
|
user.sendMessage("general.errors.general");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
|
@ -78,6 +78,8 @@ island:
|
|||||||
kick: true
|
kick: true
|
||||||
leave: true
|
leave: true
|
||||||
reset: true
|
reset: true
|
||||||
|
# Ask the recipient to confirm trust or coop invites. Team invites always require confirmation.
|
||||||
|
invite: false
|
||||||
delay:
|
delay:
|
||||||
# Time in seconds that players have to stand still before teleport commands activate, e.g. island go.
|
# Time in seconds that players have to stand still before teleport commands activate, e.g. island go.
|
||||||
time: 0
|
time: 0
|
||||||
|
@ -480,6 +480,7 @@ commands:
|
|||||||
already-has-rank: "&cPlayer already has a rank!"
|
already-has-rank: "&cPlayer already has a rank!"
|
||||||
you-are-a-coop-member: "&2You were cooped by [name]"
|
you-are-a-coop-member: "&2You were cooped by [name]"
|
||||||
success: "&aYou cooped &b[name]."
|
success: "&aYou cooped &b[name]."
|
||||||
|
name-has-invited-you: "&a[name] has invited you to join be a coop member of their island."
|
||||||
uncoop:
|
uncoop:
|
||||||
description: "remove a coop rank from player"
|
description: "remove a coop rank from player"
|
||||||
parameters: "<player>"
|
parameters: "<player>"
|
||||||
@ -493,7 +494,7 @@ commands:
|
|||||||
description: "give a player trusted rank on your island"
|
description: "give a player trusted rank on your island"
|
||||||
parameters: "<player>"
|
parameters: "<player>"
|
||||||
trust-in-yourself: "&cTrust in yourself!"
|
trust-in-yourself: "&cTrust in yourself!"
|
||||||
members-trusted: "&cMembers are already trusted"
|
name-has-invited-you: "&a[name] has invited you to join be a trusted member of their island."
|
||||||
player-already-trusted: "&cPlayer is already trusted!"
|
player-already-trusted: "&cPlayer is already trusted!"
|
||||||
you-are-trusted: "&2You are trusted by &b[name]&a!"
|
you-are-trusted: "&2You are trusted by &b[name]&a!"
|
||||||
success: "&aYou trusted &b[name]&a."
|
success: "&aYou trusted &b[name]&a."
|
||||||
@ -520,6 +521,7 @@ commands:
|
|||||||
you-already-are-in-team: "&cYou are already on a team!"
|
you-already-are-in-team: "&cYou are already on a team!"
|
||||||
already-on-team: "&cThat player is already on a team!"
|
already-on-team: "&cThat player is already on a team!"
|
||||||
invalid-invite: "&cThat invite is no longer valid, sorry."
|
invalid-invite: "&cThat invite is no longer valid, sorry."
|
||||||
|
you-have-already-invited: "&cYou have already invited that player!"
|
||||||
parameters: "<player>"
|
parameters: "<player>"
|
||||||
you-can-invite: "&aYou can invite [number] more players."
|
you-can-invite: "&aYou can invite [number] more players."
|
||||||
accept:
|
accept:
|
||||||
|
@ -5,9 +5,9 @@ package world.bentobox.bentobox.api.commands.island.team;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@ -33,7 +33,6 @@ import org.powermock.reflect.Whitebox;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
@ -54,7 +53,7 @@ import world.bentobox.bentobox.managers.RanksManager;
|
|||||||
public class IslandTeamCoopCommandTest {
|
public class IslandTeamCoopCommandTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private CompositeCommand ic;
|
private IslandTeamCommand ic;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
@Mock
|
@Mock
|
||||||
private User user;
|
private User user;
|
||||||
@ -219,18 +218,6 @@ public class IslandTeamCoopCommandTest {
|
|||||||
verify(user).sendMessage(eq("commands.island.team.coop.already-has-rank"));
|
verify(user).sendMessage(eq("commands.island.team.coop.already-has-rank"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testCanExecuteCoolDownActive() {
|
|
||||||
when(s.getCoopCooldown()).thenReturn(10);
|
|
||||||
when(pm.getUUID(any())).thenReturn(uuid);
|
|
||||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
|
||||||
itl.setCooldown(uuid, uuid, 10);
|
|
||||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
|
@ -3,8 +3,12 @@ package world.bentobox.bentobox.api.commands.island.team;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
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.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -20,17 +24,14 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import org.powermock.reflect.Whitebox;
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
|
||||||
import com.google.common.collect.HashBiMap;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
|
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamEventBuilder;
|
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamEventBuilder;
|
||||||
@ -51,19 +52,26 @@ import world.bentobox.bentobox.managers.RanksManager;
|
|||||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class, TeamEvent.class })
|
@PrepareForTest({Bukkit.class, BentoBox.class, User.class, TeamEvent.class })
|
||||||
public class IslandTeamInviteAcceptCommandTest {
|
public class IslandTeamInviteAcceptCommandTest {
|
||||||
|
|
||||||
private IslandTeamCommand ic;
|
@Mock
|
||||||
|
private IslandTeamCommand itc;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
@Mock
|
||||||
private User user;
|
private User user;
|
||||||
|
@Mock
|
||||||
private IslandsManager im;
|
private IslandsManager im;
|
||||||
|
@Mock
|
||||||
private PlayersManager pm;
|
private PlayersManager pm;
|
||||||
private UUID notUUID;
|
private UUID notUUID;
|
||||||
@Mock
|
@Mock
|
||||||
private Settings s;
|
private Settings s;
|
||||||
|
@Mock
|
||||||
private Island island;
|
private Island island;
|
||||||
|
@Mock
|
||||||
private IslandTeamInviteAcceptCommand c;
|
private IslandTeamInviteAcceptCommand c;
|
||||||
private BiMap<UUID, UUID> biMap;
|
@Mock
|
||||||
private IslandTeamInviteCommand inviteCommand;
|
|
||||||
private PluginManager pim;
|
private PluginManager pim;
|
||||||
|
@Mock
|
||||||
|
private Invite invite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
@ -84,7 +92,6 @@ public class IslandTeamInviteAcceptCommandTest {
|
|||||||
// Player
|
// Player
|
||||||
Player p = mock(Player.class);
|
Player p = mock(Player.class);
|
||||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||||
user = mock(User.class);
|
|
||||||
when(user.isOp()).thenReturn(false);
|
when(user.isOp()).thenReturn(false);
|
||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
notUUID = UUID.randomUUID();
|
notUUID = UUID.randomUUID();
|
||||||
@ -97,53 +104,48 @@ public class IslandTeamInviteAcceptCommandTest {
|
|||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
|
|
||||||
// Parent command has no aliases
|
// Parent command has no aliases
|
||||||
ic = mock(IslandTeamCommand.class);
|
when(itc.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
when(itc.getPermissionPrefix()).thenReturn("bskyblock.");
|
||||||
when(ic.getPermissionPrefix()).thenReturn("bskyblock.");
|
when(itc.getInvite(any())).thenReturn(invite);
|
||||||
inviteCommand = mock(IslandTeamInviteCommand.class);
|
|
||||||
biMap = HashBiMap.create();
|
|
||||||
when(inviteCommand.getInviteList()).thenReturn(biMap);
|
|
||||||
when(ic.getInviteCommand()).thenReturn(inviteCommand);
|
|
||||||
|
|
||||||
// Player has island to begin with
|
// Player has island to begin with
|
||||||
im = mock(IslandsManager.class);
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(im.inTeam(any(), any(UUID.class))).thenReturn(true);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(im.isOwner(any(), any())).thenReturn(true);
|
||||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
when(im.getOwner(any(), any())).thenReturn(uuid);
|
||||||
when(im.getOwner(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
// Island
|
||||||
island = mock(Island.class);
|
when(island.getRank(any())).thenReturn(RanksManager.OWNER_RANK);
|
||||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
when(im.getIsland(any(), any(User.class))).thenReturn(island);
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
// Has team
|
// Has team
|
||||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
// Player Manager
|
// Player Manager
|
||||||
pm = mock(PlayersManager.class);
|
|
||||||
|
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
|
|
||||||
// Server & Scheduler
|
// Server & Scheduler
|
||||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||||
pim = mock(PluginManager.class);
|
|
||||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
// Locales
|
// Locales
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
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);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
when(user.getTranslation(Mockito.anyString())).thenReturn("mock translation2");
|
when(user.getTranslation(anyString())).thenReturn("mock translation2");
|
||||||
|
|
||||||
// IWM friendly name
|
// IWM friendly name
|
||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
|
// Invite
|
||||||
|
when(invite.getType()).thenReturn(Invite.Type.TEAM);
|
||||||
|
|
||||||
// Team invite accept command
|
// Team invite accept command
|
||||||
c = new IslandTeamInviteAcceptCommand(ic);
|
c = new IslandTeamInviteAcceptCommand(itc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,7 +180,7 @@ public class IslandTeamInviteAcceptCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testCanExecuteNoInvite() {
|
public void testCanExecuteNoInvite() {
|
||||||
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
|
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
|
||||||
Mockito.verify(user).sendMessage("commands.island.team.invite.errors.none-invited-you");
|
verify(user).sendMessage("commands.island.team.invite.errors.none-invited-you");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,10 +188,10 @@ public class IslandTeamInviteAcceptCommandTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecuteInTeam() {
|
public void testCanExecuteInTeam() {
|
||||||
biMap.put(uuid, notUUID);
|
when(itc.isInvited(any())).thenReturn(true);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
when(im.inTeam(any(), any())).thenReturn(true);
|
||||||
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
|
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
|
||||||
Mockito.verify(user).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
|
verify(user).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,12 +199,11 @@ public class IslandTeamInviteAcceptCommandTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecuteInvalidInvite() {
|
public void testCanExecuteInvalidInvite() {
|
||||||
biMap.put(uuid, notUUID);
|
when(itc.isInvited(any())).thenReturn(true);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false);
|
when(im.inTeam(any(), any())).thenReturn(false);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||||
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
|
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
|
||||||
Mockito.verify(user).sendMessage("commands.island.team.invite.errors.invalid-invite");
|
verify(user).sendMessage("commands.island.team.invite.errors.invalid-invite");
|
||||||
Mockito.verify(inviteCommand).getInviteList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -210,11 +211,45 @@ public class IslandTeamInviteAcceptCommandTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecuteOkay() {
|
public void testCanExecuteOkay() {
|
||||||
biMap.put(uuid, notUUID);
|
when(itc.isInvited(any())).thenReturn(true);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false);
|
when(itc.getInviter(any())).thenReturn(notUUID);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(itc.getInvite(any())).thenReturn(invite);
|
||||||
|
when(im.inTeam(any(), any())).thenReturn(false);
|
||||||
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||||
assertTrue(c.canExecute(user, "accept", Collections.emptyList()));
|
assertTrue(c.canExecute(user, "accept", Collections.emptyList()));
|
||||||
Mockito.verify(pim).callEvent(Mockito.any());
|
verify(pim).callEvent(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteAcceptCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCanExecuteOkayTrust() {
|
||||||
|
when(itc.isInvited(any())).thenReturn(true);
|
||||||
|
when(itc.getInviter(any())).thenReturn(notUUID);
|
||||||
|
when(itc.getInvite(any())).thenReturn(invite);
|
||||||
|
when(invite.getType()).thenReturn(Type.TRUST);
|
||||||
|
when(im.inTeam(any(), any())).thenReturn(false);
|
||||||
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||||
|
assertTrue(c.canExecute(user, "accept", Collections.emptyList()));
|
||||||
|
// No event
|
||||||
|
verify(pim, never()).callEvent(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteAcceptCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCanExecuteOkayCoop() {
|
||||||
|
when(itc.isInvited(any())).thenReturn(true);
|
||||||
|
when(itc.getInviter(any())).thenReturn(notUUID);
|
||||||
|
when(itc.getInvite(any())).thenReturn(invite);
|
||||||
|
when(invite.getType()).thenReturn(Invite.Type.COOP);
|
||||||
|
when(im.inTeam(any(), any())).thenReturn(false);
|
||||||
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||||
|
assertTrue(c.canExecute(user, "accept", Collections.emptyList()));
|
||||||
|
// No event
|
||||||
|
verify(pim, never()).callEvent(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -222,9 +257,11 @@ public class IslandTeamInviteAcceptCommandTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecuteEventBlocked() {
|
public void testCanExecuteEventBlocked() {
|
||||||
biMap.put(uuid, notUUID);
|
when(itc.isInvited(any())).thenReturn(true);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false);
|
when(itc.getInviter(any())).thenReturn(notUUID);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(itc.getInvite(any())).thenReturn(invite);
|
||||||
|
when(im.inTeam(any(), any())).thenReturn(false);
|
||||||
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||||
// Block event
|
// Block event
|
||||||
PowerMockito.mockStatic(TeamEvent.class);
|
PowerMockito.mockStatic(TeamEvent.class);
|
||||||
TeamEventBuilder teb = mock(TeamEventBuilder.class);
|
TeamEventBuilder teb = mock(TeamEventBuilder.class);
|
||||||
@ -236,7 +273,7 @@ public class IslandTeamInviteAcceptCommandTest {
|
|||||||
when(teb.build()).thenReturn(ibe);
|
when(teb.build()).thenReturn(ibe);
|
||||||
when(TeamEvent.builder()).thenReturn(teb);
|
when(TeamEvent.builder()).thenReturn(teb);
|
||||||
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
|
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
|
||||||
Mockito.verify(pim).callEvent(Mockito.any());
|
verify(pim).callEvent(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -244,8 +281,31 @@ public class IslandTeamInviteAcceptCommandTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteUserStringListOfString() {
|
public void testExecuteUserStringListOfString() {
|
||||||
|
// Team
|
||||||
assertTrue(c.execute(user, "accept", Collections.emptyList()));
|
assertTrue(c.execute(user, "accept", Collections.emptyList()));
|
||||||
Mockito.verify(user).getTranslation("commands.island.team.invite.accept.confirmation");
|
verify(user).getTranslation("commands.island.team.invite.accept.confirmation");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteAcceptCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteUserStringListOfStringCoop() {
|
||||||
|
// Coop
|
||||||
|
when(invite.getType()).thenReturn(Invite.Type.COOP);
|
||||||
|
assertTrue(c.execute(user, "accept", Collections.emptyList()));
|
||||||
|
verify(user).sendMessage("commands.confirmation.confirm", "[seconds]", "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteAcceptCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteUserStringListOfStringTrust() {
|
||||||
|
// Trust
|
||||||
|
when(invite.getType()).thenReturn(Invite.Type.TRUST);
|
||||||
|
assertTrue(c.execute(user, "accept", Collections.emptyList()));
|
||||||
|
verify(user).sendMessage("commands.confirmation.confirm", "[seconds]", "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package world.bentobox.bentobox.api.commands.island.team;
|
package world.bentobox.bentobox.api.commands.island.team;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -28,7 +25,6 @@ import org.powermock.reflect.Whitebox;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.managers.CommandsManager;
|
import world.bentobox.bentobox.managers.CommandsManager;
|
||||||
@ -46,14 +42,19 @@ import world.bentobox.bentobox.managers.RanksManager;
|
|||||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||||
public class IslandTeamInviteCommandTest {
|
public class IslandTeamInviteCommandTest {
|
||||||
|
|
||||||
private CompositeCommand ic;
|
@Mock
|
||||||
|
private IslandTeamCommand ic;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
@Mock
|
||||||
private User user;
|
private User user;
|
||||||
|
@Mock
|
||||||
private IslandsManager im;
|
private IslandsManager im;
|
||||||
|
@Mock
|
||||||
private PlayersManager pm;
|
private PlayersManager pm;
|
||||||
private UUID notUUID;
|
private UUID notUUID;
|
||||||
@Mock
|
@Mock
|
||||||
private Settings s;
|
private Settings s;
|
||||||
|
@Mock
|
||||||
private Island island;
|
private Island island;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,7 +76,6 @@ public class IslandTeamInviteCommandTest {
|
|||||||
// Player
|
// Player
|
||||||
Player p = mock(Player.class);
|
Player p = mock(Player.class);
|
||||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||||
user = mock(User.class);
|
|
||||||
when(user.isOp()).thenReturn(false);
|
when(user.isOp()).thenReturn(false);
|
||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
notUUID = UUID.randomUUID();
|
notUUID = UUID.randomUUID();
|
||||||
@ -88,16 +88,13 @@ public class IslandTeamInviteCommandTest {
|
|||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
|
|
||||||
// Parent command has no aliases
|
// Parent command has no aliases
|
||||||
ic = mock(CompositeCommand.class);
|
|
||||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||||
|
|
||||||
// Player has island to begin with
|
// 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(UUID.class))).thenReturn(true);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||||
when(im.getOwner(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
when(im.getOwner(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
||||||
island = mock(Island.class);
|
|
||||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
@ -106,8 +103,6 @@ public class IslandTeamInviteCommandTest {
|
|||||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
// Player Manager
|
// Player Manager
|
||||||
pm = mock(PlayersManager.class);
|
|
||||||
|
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
|
|
||||||
// Server & Scheduler
|
// Server & Scheduler
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package world.bentobox.bentobox.api.commands.island.team;
|
package world.bentobox.bentobox.api.commands.island.team;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.mockito.Matchers.anyString;
|
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.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -17,6 +17,7 @@ import java.util.UUID;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -29,13 +30,14 @@ import org.powermock.reflect.Whitebox;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
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.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.managers.CommandsManager;
|
import world.bentobox.bentobox.managers.CommandsManager;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
import world.bentobox.bentobox.managers.LocalesManager;
|
import world.bentobox.bentobox.managers.LocalesManager;
|
||||||
|
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
import world.bentobox.bentobox.managers.RanksManager;
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
|
|
||||||
@ -47,14 +49,19 @@ import world.bentobox.bentobox.managers.RanksManager;
|
|||||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||||
public class IslandTeamTrustCommandTest {
|
public class IslandTeamTrustCommandTest {
|
||||||
|
|
||||||
private CompositeCommand ic;
|
@Mock
|
||||||
|
private IslandTeamCommand ic;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
@Mock
|
||||||
private User user;
|
private User user;
|
||||||
|
@Mock
|
||||||
private IslandsManager im;
|
private IslandsManager im;
|
||||||
|
@Mock
|
||||||
private PlayersManager pm;
|
private PlayersManager pm;
|
||||||
private UUID notUUID;
|
private UUID notUUID;
|
||||||
@Mock
|
@Mock
|
||||||
private Settings s;
|
private Settings s;
|
||||||
|
@Mock
|
||||||
private Island island;
|
private Island island;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,13 +77,11 @@ public class IslandTeamTrustCommandTest {
|
|||||||
CommandsManager cm = mock(CommandsManager.class);
|
CommandsManager cm = mock(CommandsManager.class);
|
||||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||||
|
|
||||||
// Settings
|
|
||||||
when(plugin.getSettings()).thenReturn(s);
|
when(plugin.getSettings()).thenReturn(s);
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
Player p = mock(Player.class);
|
Player p = mock(Player.class);
|
||||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||||
user = mock(User.class);
|
|
||||||
when(user.isOp()).thenReturn(false);
|
when(user.isOp()).thenReturn(false);
|
||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
notUUID = UUID.randomUUID();
|
notUUID = UUID.randomUUID();
|
||||||
@ -89,27 +94,23 @@ public class IslandTeamTrustCommandTest {
|
|||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
|
|
||||||
// Parent command has no aliases
|
// Parent command has no aliases
|
||||||
ic = mock(CompositeCommand.class);
|
|
||||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||||
|
|
||||||
// Player has island to begin with
|
// Player has island to begin with
|
||||||
im = mock(IslandsManager.class);
|
when(im.hasIsland(any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(im.inTeam(any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(im.isOwner(any(), any())).thenReturn(true);
|
||||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
when(im.getOwner(any(), any())).thenReturn(uuid);
|
||||||
when(im.getOwner(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
// Island
|
||||||
island = mock(Island.class);
|
when(island.getRank(any())).thenReturn(RanksManager.OWNER_RANK);
|
||||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
when(im.getIsland(any(), Mockito.any(User.class))).thenReturn(island);
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
when(im.getIsland(any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
// Has team
|
// Has team
|
||||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
// Player Manager
|
// Player Manager
|
||||||
pm = mock(PlayersManager.class);
|
|
||||||
|
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
|
|
||||||
// Server & Scheduler
|
// Server & Scheduler
|
||||||
@ -119,102 +120,174 @@ public class IslandTeamTrustCommandTest {
|
|||||||
|
|
||||||
// Locales
|
// Locales
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
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);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
// IWM friendly name
|
// IWM friendly name
|
||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
|
PlaceholdersManager phm = mock(PlaceholdersManager.class);
|
||||||
|
when(phm.replacePlaceholders(any(), any())).thenAnswer(invocation -> invocation.getArgument(1, String.class));
|
||||||
|
// Placeholder manager
|
||||||
|
when(plugin.getPlaceholdersManager()).thenReturn(phm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
User.clearUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteNoisland() {
|
public void testCanExecuteNoisland() {
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
when(im.hasIsland(any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
when(im.inTeam(any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island"));
|
verify(user).sendMessage(eq("general.errors.no-island"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteLowRank() {
|
public void testCanExecuteLowRank() {
|
||||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
when(island.getRank(any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
|
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"));
|
verify(user).sendMessage(eq("general.errors.no-permission"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteNoTarget() {
|
public void testCanExecuteNoTarget() {
|
||||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
assertFalse(itl.canExecute(user, itl.getLabel(), new ArrayList<>()));
|
||||||
// Show help
|
// Show help
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteUnknownPlayer() {
|
public void testCanExecuteUnknownPlayer() {
|
||||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
when(pm.getUUID(any())).thenReturn(null);
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||||
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", "tastybento");
|
verify(user).sendMessage("general.errors.unknown-player", "[name]", "tastybento");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteSamePlayer() {
|
public void testCanExecuteSamePlayer() {
|
||||||
PowerMockito.mockStatic(User.class);
|
PowerMockito.mockStatic(User.class);
|
||||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||||
when(user.isOnline()).thenReturn(true);
|
when(user.isOnline()).thenReturn(true);
|
||||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||||
when(pm.getUUID(Mockito.any())).thenReturn(uuid);
|
when(pm.getUUID(any())).thenReturn(uuid);
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.trust.trust-in-yourself"));
|
verify(user).sendMessage(eq("commands.island.team.trust.trust-in-yourself"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecutePlayerHasRank() {
|
public void testCanExecutePlayerHasRank() {
|
||||||
PowerMockito.mockStatic(User.class);
|
PowerMockito.mockStatic(User.class);
|
||||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||||
when(user.isOnline()).thenReturn(true);
|
when(user.isOnline()).thenReturn(true);
|
||||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
when(im.inTeam(any(), any())).thenReturn(true);
|
||||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.singleton(notUUID));
|
when(im.getMembers(any(), any())).thenReturn(Collections.singleton(notUUID));
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("bento")));
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.trust.members-trusted"));
|
verify(user).sendMessage(eq("commands.island.team.trust.player-already-trusted"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCanExecuteCannottrustSelf() {
|
||||||
|
when(pm.getUUID(any())).thenReturn(uuid);
|
||||||
|
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||||
|
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||||
|
verify(user).sendMessage(eq("commands.island.team.trust.trust-in-yourself"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCanExecuteCannotAlreadyHasRank() {
|
||||||
|
UUID other = UUID.randomUUID();
|
||||||
|
when(pm.getUUID(any())).thenReturn(other);
|
||||||
|
when(im.getMembers(any(), any())).thenReturn(Collections.singleton(other));
|
||||||
|
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||||
|
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||||
|
verify(user).sendMessage(eq("commands.island.team.trust.player-already-trusted"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCanExecuteSuccess() {
|
||||||
|
UUID other = UUID.randomUUID();
|
||||||
|
when(pm.getUUID(any())).thenReturn(other);
|
||||||
|
when(im.getMembers(any(), any())).thenReturn(Collections.emptySet());
|
||||||
|
when(island.getRank(any())).thenReturn(RanksManager.VISITOR_RANK);
|
||||||
|
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||||
|
assertTrue(itl.canExecute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteCoolDownActive() {
|
public void testExecuteNullIsland() {
|
||||||
// 10 minutes = 600 seconds
|
// Can execute
|
||||||
when(s.getInviteCooldown()).thenReturn(10);
|
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||||
|
when(im.getMembers(any(), any())).thenReturn(Collections.emptySet());
|
||||||
|
when(island.getRank(any())).thenReturn(RanksManager.VISITOR_RANK);
|
||||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||||
String[] name = {"tastybento"};
|
assertTrue(itl.canExecute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
// Execute
|
||||||
|
when(im.getIsland(any(), Mockito.any(UUID.class))).thenReturn(null);
|
||||||
|
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||||
|
verify(user).sendMessage(eq("general.errors.general"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteSuccess() {
|
||||||
|
Player p = mock(Player.class);
|
||||||
|
when(p.getUniqueId()).thenReturn(notUUID);
|
||||||
|
User target = User.getInstance(p);
|
||||||
|
// Can execute
|
||||||
|
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||||
|
when(im.getMembers(any(), any())).thenReturn(Collections.emptySet());
|
||||||
|
when(island.getRank(any())).thenReturn(RanksManager.VISITOR_RANK);
|
||||||
|
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||||
|
assertTrue(itl.canExecute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
when(im.getIsland(any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||||
|
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||||
|
verify(user).sendMessage("commands.island.team.trust.success", TextVariables.NAME, null);
|
||||||
|
verify(island).setRank(target, RanksManager.TRUSTED_RANK);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user