adjust test cases to previous changes
This commit is contained in:
parent
f77c48218a
commit
f25c027a2b
|
@ -182,5 +182,11 @@ public class Settings {
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "EntityGroup{" + "name=" + name + ", types=" + types + ", limit=" + limit + '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ public class JoinListener implements Listener {
|
|||
if (ibc != null) {
|
||||
// Clear permission limits
|
||||
ibc.getEntityLimits().clear();
|
||||
ibc.getEntityGroupLimits().clear();
|
||||
ibc.getBlockLimits().clear();
|
||||
}
|
||||
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
|
||||
|
@ -69,8 +70,8 @@ public class JoinListener implements Listener {
|
|||
Material m = Arrays.stream(Material.values()).filter(t -> t.name().equalsIgnoreCase(split[3])).findFirst().orElse(null);
|
||||
EntityGroup entgroup = addon.getSettings().getGroupLimitDefinitions().stream().filter(e -> e.getName().equalsIgnoreCase(split[3])).findFirst().orElse(null);
|
||||
|
||||
if (et == null && m == null) {
|
||||
logError(player.getName(), perms.getPermission(), split[3].toUpperCase(Locale.ENGLISH) + " is not a valid material or entity type.");
|
||||
if (entgroup == null && et == null && m == null) {
|
||||
logError(player.getName(), perms.getPermission(), split[3].toUpperCase(Locale.ENGLISH) + " is not a valid material or entity type/group.");
|
||||
break;
|
||||
}
|
||||
// Make an ibc if required
|
||||
|
@ -78,6 +79,7 @@ public class JoinListener implements Listener {
|
|||
ibc = new IslandBlockCount(islandId, gameMode);
|
||||
}
|
||||
if (entgroup != null) {
|
||||
// Entity group limit
|
||||
ibc.setEntityGroupLimit(entgroup.getName(), Math.max(ibc.getEntityGroupLimit(entgroup.getName()), Integer.valueOf(split[4])));
|
||||
} else if (et != null && m == null) {
|
||||
// Entity limit
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package bentobox.addon.limits.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
|
@ -38,6 +40,7 @@ import world.bentobox.bentobox.api.events.team.TeamEvent.TeamSetownerEvent;
|
|||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.limits.Limits;
|
||||
import world.bentobox.limits.Settings;
|
||||
import world.bentobox.limits.listeners.BlockLimitsListener;
|
||||
import world.bentobox.limits.listeners.JoinListener;
|
||||
import world.bentobox.limits.objects.IslandBlockCount;
|
||||
|
@ -53,6 +56,8 @@ public class JoinListenerTest {
|
|||
@Mock
|
||||
private Limits addon;
|
||||
@Mock
|
||||
private Settings settings;
|
||||
@Mock
|
||||
private GameModeAddon bskyblock;
|
||||
@Mock
|
||||
private Player player;
|
||||
|
@ -76,6 +81,9 @@ public class JoinListenerTest {
|
|||
when(addon.getGameModes()).thenReturn(Collections.singletonList(bskyblock));
|
||||
when(addon.getGameModeName(any())).thenReturn("bskyblock");
|
||||
when(addon.getGameModePermPrefix(any())).thenReturn("bskyblock.");
|
||||
when(addon.getSettings()).thenReturn(settings);
|
||||
// Settings
|
||||
when(settings.getGroupLimitDefinitions()).thenReturn(new ArrayList(Arrays.asList(new Settings.EntityGroup("friendly", new HashSet<>(), -1))));
|
||||
// Island Manager
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
when(island.getUniqueId()).thenReturn("unique_id");
|
||||
|
@ -244,7 +252,7 @@ public class JoinListenerTest {
|
|||
when(player.getEffectivePermissions()).thenReturn(perms);
|
||||
PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome");
|
||||
jl.onPlayerJoin(e);
|
||||
verify(addon).logError("Player tastybento has permission: 'bskyblock.island.limit.my.perm.for.game' but format must be 'bskyblock.island.limit.MATERIAL.NUMBER' or 'bskyblock.island.limit.ENTITY-TYPE.NUMBER' Ignoring...");
|
||||
verify(addon).logError("Player tastybento has permission: 'bskyblock.island.limit.my.perm.for.game' but format must be 'bskyblock.island.limit.MATERIAL.NUMBER', 'bskyblock.island.limit.ENTITY-TYPE.NUMBER', or 'bskyblock.island.limit.ENTITY-GROUP.NUMBER' Ignoring...");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -260,7 +268,7 @@ public class JoinListenerTest {
|
|||
when(player.getEffectivePermissions()).thenReturn(perms);
|
||||
PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome");
|
||||
jl.onPlayerJoin(e);
|
||||
verify(addon).logError("Player tastybento has permission: 'bskyblock.island.limit.mumbo.34' but MUMBO is not a valid material or entity type. Ignoring...");
|
||||
verify(addon).logError("Player tastybento has permission: 'bskyblock.island.limit.mumbo.34' but MUMBO is not a valid material or entity type/group. Ignoring...");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -328,6 +336,23 @@ public class JoinListenerTest {
|
|||
verify(addon, never()).logError(anyString());
|
||||
verify(ibc).setEntityLimit(eq(EntityType.BAT), eq(24));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.limits.listeners.JoinListener#onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent)}.
|
||||
*/
|
||||
@Test
|
||||
public void testOnPlayerJoinWithPermLimitsSuccessEntityGroup() {
|
||||
Set<PermissionAttachmentInfo> perms = new HashSet<>();
|
||||
PermissionAttachmentInfo permAtt = mock(PermissionAttachmentInfo.class);
|
||||
when(permAtt.getPermission()).thenReturn("bskyblock.island.limit.friendly.24");
|
||||
when(permAtt.getValue()).thenReturn(true);
|
||||
perms.add(permAtt);
|
||||
when(player.getEffectivePermissions()).thenReturn(perms);
|
||||
PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome");
|
||||
jl.onPlayerJoin(e);
|
||||
verify(addon, never()).logError(anyString());
|
||||
verify(ibc).setEntityGroupLimit(eq("friendly"), eq(24));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.limits.listeners.JoinListener#onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent)}.
|
||||
|
|
Loading…
Reference in New Issue