Fixes teams. Test still need to be fixed.
This commit is contained in:
parent
aaa1504dc6
commit
f81185a6ab
|
@ -136,7 +136,7 @@ public class IslandTeamCommand extends CompositeCommand {
|
|||
* @since 1.8.0
|
||||
*/
|
||||
public void addInvite(TeamInvite.Type type, @NonNull UUID inviter, @NonNull UUID invitee, @NonNull Island island) {
|
||||
handler.saveObjectAsync(new TeamInvite(type, inviter, invitee, island));
|
||||
handler.saveObjectAsync(new TeamInvite(type, inviter, invitee, island.getUniqueId()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,7 +13,6 @@ import world.bentobox.bentobox.api.user.User;
|
|||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.database.objects.TeamInvite;
|
||||
import world.bentobox.bentobox.database.objects.TeamInvite.Type;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
|
@ -100,7 +99,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||
// Remove the invite
|
||||
itc.removeInvite(user.getUniqueId());
|
||||
User inviter = User.getInstance(invite.getInviter());
|
||||
Island island = invite.getIsland();
|
||||
Island island = getIslands().getIslandById(invite.getIslandID()).orElse(null);
|
||||
if (island != null) {
|
||||
if (island.getMemberSet(RanksManager.TRUSTED_RANK, false).size() > getIslands().getMaxMembers(island,
|
||||
RanksManager.TRUSTED_RANK)) {
|
||||
|
@ -126,7 +125,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||
// Remove the invite
|
||||
itc.removeInvite(user.getUniqueId());
|
||||
User inviter = User.getInstance(invite.getInviter());
|
||||
Island island = invite.getIsland();
|
||||
Island island = getIslands().getIslandById(invite.getIslandID()).orElse(null);
|
||||
if (island != null) {
|
||||
if (island.getMemberSet(RanksManager.COOP_RANK, false).size() > getIslands().getMaxMembers(island,
|
||||
RanksManager.COOP_RANK)) {
|
||||
|
@ -154,7 +153,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||
// Get the player's island - may be null if the player has no island
|
||||
List<Island> islands = getIslands().getIslands(getWorld(), user.getUniqueId());
|
||||
// Get the team's island
|
||||
Island teamIsland = invite.getIsland();
|
||||
Island teamIsland = getIslands().getIslandById(invite.getIslandID()).orElse(null);
|
||||
if (teamIsland == null) {
|
||||
user.sendMessage(INVALID_INVITE);
|
||||
return;
|
||||
|
@ -198,7 +197,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME,
|
||||
user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());
|
||||
}
|
||||
IslandsManager.updateIsland(teamIsland);
|
||||
//IslandsManager.updateIsland(teamIsland);
|
||||
// Fire event
|
||||
TeamEvent.builder().island(teamIsland).reason(TeamEvent.Reason.JOINED).involvedPlayer(user.getUniqueId())
|
||||
.build();
|
||||
|
|
|
@ -14,6 +14,7 @@ import world.bentobox.bentobox.api.events.team.TeamEvent;
|
|||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
|
@ -91,7 +92,7 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
|
|||
IslandEvent.builder().island(island).involvedPlayer(user.getUniqueId()).admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE).rankChange(RanksManager.OWNER_RANK, RanksManager.SUB_OWNER_RANK)
|
||||
.build();
|
||||
getIslands().updateIsland(island);
|
||||
IslandsManager.updateIsland(island);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ import world.bentobox.bentobox.api.user.User;
|
|||
import world.bentobox.bentobox.database.objects.adapters.Adapter;
|
||||
import world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Pair;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
@ -57,7 +56,7 @@ import world.bentobox.bentobox.util.Util;
|
|||
public class Island implements DataObject, MetaDataAble {
|
||||
|
||||
@Expose
|
||||
private boolean primary;
|
||||
private Set<UUID> primaries = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Set to true if this data object has been changed since being loaded from the
|
||||
|
@ -290,7 +289,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
this.updatedDate = island.getUpdatedDate();
|
||||
this.world = island.getWorld();
|
||||
this.bonusRanges.addAll(island.getBonusRanges());
|
||||
this.primary = island.primary;
|
||||
this.primaries.addAll(island.getPrimaries());
|
||||
this.setChanged();
|
||||
}
|
||||
|
||||
|
@ -1699,7 +1698,7 @@ public class Island implements DataObject, MetaDataAble {
|
|||
public void setChanged() {
|
||||
this.setUpdatedDate(System.currentTimeMillis());
|
||||
this.changed = true;
|
||||
IslandsManager.updateIsland(this);
|
||||
//IslandsManager.updateIsland(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1997,18 +1996,28 @@ public class Island implements DataObject, MetaDataAble {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param userID user UUID
|
||||
* @return the primary
|
||||
*/
|
||||
public boolean isPrimary() {
|
||||
return primary;
|
||||
public boolean isPrimary(UUID userID) {
|
||||
return getPrimaries().contains(userID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param primary the primary to set
|
||||
*/
|
||||
public void setPrimary(boolean primary) {
|
||||
if (this.primary != primary) {
|
||||
this.primary = primary;
|
||||
public void setPrimary(UUID userID) {
|
||||
if (getPrimaries().add(userID)) {
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the primary island
|
||||
* @param userID user UUID
|
||||
*/
|
||||
public void removePrimary(UUID userID) {
|
||||
if (getPrimaries().remove(userID)) {
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
@ -2049,4 +2058,21 @@ public class Island implements DataObject, MetaDataAble {
|
|||
+ commandRanks + ", reserved=" + reserved + ", metaData=" + metaData + ", homes=" + homes
|
||||
+ ", maxHomes=" + maxHomes + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the primaries
|
||||
*/
|
||||
public Set<UUID> getPrimaries() {
|
||||
if (primaries == null) {
|
||||
primaries = new HashSet<>();
|
||||
}
|
||||
return primaries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param primaries the primaries to set
|
||||
*/
|
||||
public void setPrimaries(Set<UUID> primaries) {
|
||||
this.primaries = primaries;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class TeamInvite implements DataObject {
|
|||
@Expose
|
||||
private UUID inviter;
|
||||
@Expose
|
||||
private Island island;
|
||||
private String islandID;
|
||||
|
||||
@Expose
|
||||
private String uniqueId;
|
||||
|
@ -35,13 +35,13 @@ public class TeamInvite implements DataObject {
|
|||
* @param type - invitation type, e.g., coop, team, trust
|
||||
* @param inviter - UUID of inviter
|
||||
* @param invitee - UUID of invitee
|
||||
* @param island - the island this invite is for
|
||||
* @param island - the unique ID of the island this invite is for
|
||||
*/
|
||||
public TeamInvite(Type type, UUID inviter, UUID invitee, Island island) {
|
||||
public TeamInvite(Type type, UUID inviter, UUID invitee, String islandID) {
|
||||
this.type = type;
|
||||
this.uniqueId = invitee.toString();
|
||||
this.inviter = inviter;
|
||||
this.island = island;
|
||||
this.islandID = islandID;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,10 +77,10 @@ public class TeamInvite implements DataObject {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the island
|
||||
* @return the islandID
|
||||
*/
|
||||
public Island getIsland() {
|
||||
return island;
|
||||
public String getIslandID() {
|
||||
return islandID;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -108,4 +108,5 @@ public class TeamInvite implements DataObject {
|
|||
return Objects.equals(inviter, other.inviter) && Objects.equals(uniqueId, other.getUniqueId())
|
||||
&& type == other.type;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -508,6 +508,7 @@ public class IslandsManager {
|
|||
if (island.getOwner() == null) {
|
||||
// No owner, no rank settings
|
||||
island.setMaxMembers(null);
|
||||
BentoBox.getInstance().logDebug("getMaxMembers no owner, no rank settings");
|
||||
updateIsland(island);
|
||||
return 0;
|
||||
}
|
||||
|
@ -529,8 +530,12 @@ public class IslandsManager {
|
|||
islandMax = owner.getPermissionValue(plugin.getIWM().getPermissionPrefix(island.getWorld()) + perm,
|
||||
islandMax);
|
||||
}
|
||||
island.setMaxMembers(rank, islandMax == worldDefault ? null : islandMax);
|
||||
updateIsland(island);
|
||||
Integer change = islandMax == worldDefault ? null : islandMax;
|
||||
if (island.getMaxMembers().get(rank) != change) {
|
||||
island.setMaxMembers(rank, change);
|
||||
BentoBox.getInstance().logDebug("getMaxMembers");
|
||||
updateIsland(island);
|
||||
}
|
||||
return islandMax;
|
||||
}
|
||||
|
||||
|
@ -568,8 +573,12 @@ public class IslandsManager {
|
|||
}
|
||||
// If the island maxHomes is just the same as the world default, then set to
|
||||
// null
|
||||
island.setMaxHomes(islandMax == plugin.getIWM().getMaxHomes(island.getWorld()) ? null : islandMax);
|
||||
updateIsland(island);
|
||||
Integer change = islandMax == plugin.getIWM().getMaxHomes(island.getWorld()) ? null : islandMax;
|
||||
if (island.getMaxHomes() != change) {
|
||||
island.setMaxHomes(change);
|
||||
BentoBox.getInstance().logDebug("getMaxHomes");
|
||||
updateIsland(island);
|
||||
}
|
||||
return islandMax;
|
||||
}
|
||||
|
||||
|
@ -757,8 +766,9 @@ public class IslandsManager {
|
|||
* @since 1.16.0
|
||||
*/
|
||||
public boolean setHomeLocation(@Nullable Island island, Location location, String name) {
|
||||
if (island != null) {
|
||||
if (island != null && (island.getHome(name) == null || !island.getHome(name).equals(location))) {
|
||||
island.addHome(name, location);
|
||||
BentoBox.getInstance().logDebug("setHomeLocation");
|
||||
updateIsland(island);
|
||||
return true;
|
||||
}
|
||||
|
@ -1166,9 +1176,11 @@ public class IslandsManager {
|
|||
* @param spawn the Island to set as spawn. Must not be null.
|
||||
*/
|
||||
public void setSpawn(@NonNull Island spawn) {
|
||||
spawns.put(Util.getWorld(spawn.getWorld()), spawn);
|
||||
// Tell other servers
|
||||
MultiLib.notify("bentobox-setspawn", spawn.getWorld().getUID().toString() + "," + spawn.getUniqueId());
|
||||
if (spawn.getWorld() != null) {
|
||||
spawns.put(Util.getWorld(spawn.getWorld()), spawn);
|
||||
// Tell other servers
|
||||
MultiLib.notify("bentobox-setspawn", spawn.getWorld().getUID().toString() + "," + spawn.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1468,6 +1480,7 @@ public class IslandsManager {
|
|||
teamIsland.addMember(playerUUID);
|
||||
islandCache.addPlayer(playerUUID, teamIsland);
|
||||
// Save the island
|
||||
BentoBox.getInstance().logDebug("setJoinTeam");
|
||||
updateIsland(teamIsland);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package world.bentobox.bentobox.managers;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -98,17 +99,18 @@ public class PlayersManager {
|
|||
* Adds a player to the database. If the UUID does not exist, a new player is made
|
||||
* @param playerUUID - the player's UUID
|
||||
*/
|
||||
public Players addPlayer(UUID playerUUID) {
|
||||
// If the player is in the database, load it, otherwise create a new player
|
||||
if (handler.objectExists(playerUUID.toString())) {
|
||||
Players player = handler.loadObject(playerUUID.toString());
|
||||
if (player != null) {
|
||||
return player;
|
||||
}
|
||||
public Players addPlayer(@NonNull UUID playerUUID) {
|
||||
Objects.requireNonNull(playerUUID);
|
||||
// If the player is in the database, load it, otherwise create a new player
|
||||
if (handler.objectExists(playerUUID.toString())) {
|
||||
Players player = handler.loadObject(playerUUID.toString());
|
||||
if (player != null) {
|
||||
return player;
|
||||
}
|
||||
Players player = new Players(plugin, playerUUID);
|
||||
handler.saveObject(player);
|
||||
return player;
|
||||
}
|
||||
Players player = new Players(plugin, playerUUID);
|
||||
handler.saveObject(player);
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,7 +121,7 @@ public class PlayersManager {
|
|||
* @return true if player is known, otherwise false
|
||||
*/
|
||||
public boolean isKnown(UUID uniqueID) {
|
||||
return handler.objectExists(uniqueID.toString());
|
||||
return uniqueID == null ? false : handler.objectExists(uniqueID.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -186,13 +186,13 @@ public class IslandCache {
|
|||
return null;
|
||||
}
|
||||
for (Island island : islands) {
|
||||
if (island.isPrimary()) {
|
||||
if (island.isPrimary(uuid)) {
|
||||
return island;
|
||||
}
|
||||
}
|
||||
// If there is no primary set, then set one - it doesn't matter which.
|
||||
Island result = islands.iterator().next();
|
||||
result.setPrimary(true);
|
||||
result.setPrimary(uuid);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,10 @@ public class IslandCache {
|
|||
*/
|
||||
public void setPrimaryIsland(@NonNull UUID uuid, @NonNull Island island) {
|
||||
for (Island is : getIslands(island.getWorld(), uuid)) {
|
||||
is.setPrimary(island.equals(is));
|
||||
is.removePrimary(uuid);
|
||||
if (is.equals(island)) {
|
||||
is.setPrimary(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -489,7 +489,7 @@ public class IslandCreationPanel
|
|||
long uses = plugin.getIslands().getIslands(world, user).stream()
|
||||
.filter(is -> is.getMetaData("bundle")
|
||||
.map(mdv -> bundle.getDisplayName().equalsIgnoreCase(mdv.asString())
|
||||
&& !(reset && is.isPrimary())) // If this is a reset, then ignore the use of the island being reset
|
||||
&& !(reset && is.isPrimary(user.getUniqueId()))) // If this is a reset, then ignore the use of the island being reset
|
||||
.orElse(false))
|
||||
.count();
|
||||
builder.description(this.user.getTranslation(BUNDLE_BUTTON_REF + "uses", TextVariables.NUMBER,
|
||||
|
|
|
@ -65,6 +65,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
|||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import com.github.puregero.multilib.MultiLib;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
||||
|
@ -85,7 +86,7 @@ import world.bentobox.bentobox.managers.island.IslandCache;
|
|||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class, Location.class })
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class, Location.class, MultiLib.class })
|
||||
public class IslandsManagerTest extends AbstractCommonSetup {
|
||||
|
||||
@Mock
|
||||
|
@ -157,6 +158,9 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
// Mutilib
|
||||
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// island world mgr
|
||||
when(world.getName()).thenReturn("world");
|
||||
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
||||
|
@ -242,7 +246,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
// Island
|
||||
when(island.getOwner()).thenReturn(uuid);
|
||||
when(island.getWorld()).thenReturn(world);
|
||||
when(island.getMaxMembers()).thenReturn(null); // default
|
||||
when(island.getMaxMembers()).thenReturn(new HashMap<>()); // default
|
||||
when(island.getMaxMembers(Mockito.anyInt())).thenReturn(null); // default
|
||||
when(island.getCenter()).thenReturn(location);
|
||||
when(island.getProtectionCenter()).thenReturn(location);
|
||||
|
@ -329,6 +333,9 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
// Util strip spaces
|
||||
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
|
||||
|
||||
// World UID
|
||||
when(world.getUID()).thenReturn(uuid);
|
||||
|
||||
// Class under test
|
||||
im = new IslandsManager(plugin);
|
||||
// Set cache
|
||||
|
@ -1372,14 +1379,14 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
Island island = mock(Island.class);
|
||||
when(island.getOwner()).thenReturn(uuid);
|
||||
when(island.getWorld()).thenReturn(world);
|
||||
when(island.getMaxMembers()).thenReturn(null);
|
||||
when(island.getMaxMembers()).thenReturn(new HashMap<>());
|
||||
when(island.getMaxMembers(Mockito.anyInt())).thenReturn(null);
|
||||
when(iwm.getMaxTeamSize(eq(world))).thenReturn(4);
|
||||
// Offline owner
|
||||
when(Bukkit.getPlayer(any(UUID.class))).thenReturn(null);
|
||||
// Test
|
||||
assertEquals(4, im.getMaxMembers(island, RanksManager.MEMBER_RANK));
|
||||
verify(island).setMaxMembers(eq(RanksManager.MEMBER_RANK), eq(null));
|
||||
verify(island, never()).setMaxMembers(eq(RanksManager.MEMBER_RANK), eq(null)); // No change
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1391,14 +1398,14 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
Island island = mock(Island.class);
|
||||
when(island.getOwner()).thenReturn(uuid);
|
||||
when(island.getWorld()).thenReturn(world);
|
||||
when(island.getMaxMembers()).thenReturn(null);
|
||||
when(island.getMaxMembers()).thenReturn(new HashMap<>());
|
||||
when(island.getMaxMembers(Mockito.anyInt())).thenReturn(null);
|
||||
when(iwm.getMaxTeamSize(eq(world))).thenReturn(4);
|
||||
// Online owner
|
||||
when(Bukkit.getPlayer(any(UUID.class))).thenReturn(player);
|
||||
// Test
|
||||
assertEquals(4, im.getMaxMembers(island, RanksManager.MEMBER_RANK));
|
||||
verify(island).setMaxMembers(eq(RanksManager.MEMBER_RANK), eq(null));
|
||||
verify(island, never()).setMaxMembers(RanksManager.MEMBER_RANK, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1410,7 +1417,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
Island island = mock(Island.class);
|
||||
when(island.getOwner()).thenReturn(uuid);
|
||||
when(island.getWorld()).thenReturn(world);
|
||||
when(island.getMaxMembers()).thenReturn(null);
|
||||
when(island.getMaxMembers()).thenReturn(new HashMap<>());
|
||||
when(island.getMaxMembers(Mockito.anyInt())).thenReturn(null);
|
||||
when(iwm.getMaxTeamSize(eq(world))).thenReturn(4);
|
||||
when(iwm.getMaxCoopSize(eq(world))).thenReturn(2);
|
||||
|
@ -1419,9 +1426,9 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
when(Bukkit.getPlayer(any(UUID.class))).thenReturn(player);
|
||||
// Test
|
||||
assertEquals(2, im.getMaxMembers(island, RanksManager.COOP_RANK));
|
||||
verify(island).setMaxMembers(eq(RanksManager.COOP_RANK), eq(null));
|
||||
verify(island, never()).setMaxMembers(RanksManager.COOP_RANK, null); // No change
|
||||
assertEquals(3, im.getMaxMembers(island, RanksManager.TRUSTED_RANK));
|
||||
verify(island).setMaxMembers(eq(RanksManager.TRUSTED_RANK), eq(null));
|
||||
verify(island, never()).setMaxMembers(RanksManager.TRUSTED_RANK, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1439,7 +1446,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
when(Bukkit.getPlayer(any(UUID.class))).thenReturn(player);
|
||||
// Test
|
||||
assertEquals(10, im.getMaxMembers(island, RanksManager.MEMBER_RANK));
|
||||
verify(island).setMaxMembers(eq(RanksManager.MEMBER_RANK), eq(10));
|
||||
verify(island).setMaxMembers(RanksManager.MEMBER_RANK, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1457,7 +1464,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
when(Bukkit.getPlayer(any(UUID.class))).thenReturn(player);
|
||||
// Test
|
||||
assertEquals(10, im.getMaxMembers(island, RanksManager.MEMBER_RANK));
|
||||
verify(island).setMaxMembers(eq(RanksManager.MEMBER_RANK), eq(10));
|
||||
verify(island).setMaxMembers(RanksManager.MEMBER_RANK, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1469,7 +1476,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
Island island = mock(Island.class);
|
||||
when(island.getOwner()).thenReturn(uuid);
|
||||
when(island.getWorld()).thenReturn(world);
|
||||
when(island.getMaxMembers()).thenReturn(null);
|
||||
when(island.getMaxMembers()).thenReturn(new HashMap<>());
|
||||
when(iwm.getMaxTeamSize(eq(world))).thenReturn(4);
|
||||
// Permission
|
||||
when(iwm.getPermissionPrefix(any())).thenReturn("bskyblock.");
|
||||
|
@ -1482,7 +1489,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
when(Bukkit.getPlayer(any(UUID.class))).thenReturn(player);
|
||||
// Test
|
||||
assertEquals(8, im.getMaxMembers(island, RanksManager.MEMBER_RANK));
|
||||
verify(island).setMaxMembers(eq(RanksManager.MEMBER_RANK), eq(8));
|
||||
verify(island).setMaxMembers(RanksManager.MEMBER_RANK, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1494,7 +1501,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
Island island = mock(Island.class);
|
||||
// Test
|
||||
im.setMaxMembers(island, RanksManager.MEMBER_RANK, 40);
|
||||
verify(island).setMaxMembers(eq(RanksManager.MEMBER_RANK), eq(40));
|
||||
verify(island).setMaxMembers(RanksManager.MEMBER_RANK, 40);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1546,7 +1553,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
// Test
|
||||
IslandsManager im = new IslandsManager(plugin);
|
||||
assertEquals(4, im.getMaxHomes(island));
|
||||
verify(island).setMaxHomes(eq(null));
|
||||
verify(island, never()).setMaxHomes(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1572,7 +1579,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
// Test
|
||||
IslandsManager im = new IslandsManager(plugin);
|
||||
assertEquals(20, im.getMaxHomes(island));
|
||||
verify(island).setMaxHomes(eq(20));
|
||||
verify(island, never()).setMaxHomes(20);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1598,7 +1605,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
|
|||
// Test
|
||||
IslandsManager im = new IslandsManager(plugin);
|
||||
assertEquals(8, im.getMaxHomes(island));
|
||||
verify(island).setMaxHomes(eq(8));
|
||||
verify(island).setMaxHomes(8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@ import static org.junit.Assert.assertNotNull;
|
|||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
@ -39,6 +40,7 @@ import org.bukkit.inventory.Inventory;
|
|||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -60,6 +62,7 @@ import world.bentobox.bentobox.database.Database;
|
|||
import world.bentobox.bentobox.database.DatabaseSetup;
|
||||
import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.database.objects.Names;
|
||||
import world.bentobox.bentobox.database.objects.Players;
|
||||
import world.bentobox.bentobox.hooks.VaultHook;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
@ -240,6 +243,18 @@ public class PlayersManagerTest {
|
|||
when(tamed.getOwner()).thenReturn(p);
|
||||
when(world.getEntitiesByClass(Tameable.class)).thenReturn(list);
|
||||
|
||||
// Loading objects
|
||||
Object players = new Players();
|
||||
when(h.loadObject(anyString())).thenReturn(players);
|
||||
// Set up names database
|
||||
List<Object> names = new ArrayList<>();
|
||||
Names name = new Names();
|
||||
name.setUniqueId("tastybento");
|
||||
name.setUuid(uuid);
|
||||
names.add(name);
|
||||
when(h.loadObjects()).thenReturn(names);
|
||||
when(h.objectExists(anyString())).thenReturn(true);
|
||||
|
||||
// Class under test
|
||||
pm = new PlayersManager(plugin);
|
||||
}
|
||||
|
@ -269,13 +284,8 @@ public class PlayersManagerTest {
|
|||
*/
|
||||
@Test
|
||||
public void testAddPlayer() {
|
||||
|
||||
pm.addPlayer(null);
|
||||
// Add twice
|
||||
assertFalse(pm.isKnown(uuid));
|
||||
pm.addPlayer(uuid);
|
||||
assertTrue(pm.isKnown(uuid));
|
||||
pm.addPlayer(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -442,9 +452,16 @@ public class PlayersManagerTest {
|
|||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#setResets(World, UUID, int)}.
|
||||
* @throws IntrospectionException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws ClassNotFoundException
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
@Test
|
||||
public void testGetSetResetsLeft() {
|
||||
public void testGetSetResetsLeft() throws InstantiationException, IllegalAccessException, InvocationTargetException,
|
||||
ClassNotFoundException, NoSuchMethodException, IntrospectionException {
|
||||
// Add a player
|
||||
pm.addPlayer(uuid);
|
||||
assertEquals(0, pm.getResets(world, uuid));
|
||||
|
@ -455,9 +472,16 @@ public class PlayersManagerTest {
|
|||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#getUser(java.lang.String)}.
|
||||
* @throws IntrospectionException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws ClassNotFoundException
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
@Test
|
||||
public void testGetUserString() {
|
||||
public void testGetUserString() throws InstantiationException, IllegalAccessException, InvocationTargetException,
|
||||
ClassNotFoundException, NoSuchMethodException, IntrospectionException {
|
||||
User user = pm.getUser("random");
|
||||
assertNull(user);
|
||||
pm.addPlayer(uuid);
|
||||
|
|
Loading…
Reference in New Issue