mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 13:45:14 +01:00
Added ban limit (#getBanLimit() in WorldSettings)
Closes #423. I had some trouble with unit testings, that's why I didn't update them to test the new features :(
This commit is contained in:
parent
efd0aba8e8
commit
c078d8dce6
@ -82,6 +82,10 @@ public class IslandBanCommand extends CompositeCommand {
|
|||||||
|
|
||||||
private boolean ban(User user, User targetUser) {
|
private boolean ban(User user, User targetUser) {
|
||||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||||
|
|
||||||
|
// Check if player can ban any more players
|
||||||
|
int banLimit = user.getPermissionValue(getPermissionPrefix() + "ban.maxlimit", getIWM().getBanLimit(getWorld()));
|
||||||
|
if (banLimit <= -1 || island.getBanned().size() < banLimit) {
|
||||||
if (island.addToBanList(targetUser.getUniqueId())) {
|
if (island.addToBanList(targetUser.getUniqueId())) {
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
targetUser.sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, user.getName());
|
targetUser.sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, user.getName());
|
||||||
@ -92,6 +96,9 @@ public class IslandBanCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
user.sendMessage("commands.island.ban.cannot-ban-more-players");
|
||||||
|
}
|
||||||
// Banning was blocked, maybe due to an event cancellation. Fail silently.
|
// Banning was blocked, maybe due to an event cancellation. Fail silently.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
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;
|
||||||
|
|
||||||
@ -64,6 +65,11 @@ public class IslandBanlistCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
// Send the strings
|
// Send the strings
|
||||||
lines.forEach(l -> user.sendMessage("commands.island.banlist.names", "[line]", l));
|
lines.forEach(l -> user.sendMessage("commands.island.banlist.names", "[line]", l));
|
||||||
|
|
||||||
|
int banLimit = user.getPermissionValue(getPermissionPrefix() + "ban.maxlimit", getIWM().getBanLimit(getWorld()));
|
||||||
|
if (banLimit <= -1 || island.getBanned().size() < banLimit) {
|
||||||
|
user.sendMessage("commands.island.banlist.you-can-ban", TextVariables.NUMBER, String.valueOf(banLimit - island.getBanned().size()));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +226,6 @@ public interface WorldSettings {
|
|||||||
*/
|
*/
|
||||||
int getResetLimit();
|
int getResetLimit();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the island reset time stamp. Any player who last logged in before this time will have resets zeroed
|
* Get the island reset time stamp. Any player who last logged in before this time will have resets zeroed
|
||||||
*/
|
*/
|
||||||
@ -272,4 +271,13 @@ public interface WorldSettings {
|
|||||||
*/
|
*/
|
||||||
boolean isRequireConfirmationToSetHomeInTheEnd();
|
boolean isRequireConfirmationToSetHomeInTheEnd();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets ban limit for this world.
|
||||||
|
* Once exceeded, island members won't be able to ban any more players from their island.
|
||||||
|
* Set it to -1 for unlimited.
|
||||||
|
* <br/>
|
||||||
|
* Permission to increase the limit: {@code (permissionprefix).ban.maxlimit.(value)}
|
||||||
|
* @return the ban limit for this world.
|
||||||
|
*/
|
||||||
|
int getBanLimit();
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,7 @@ public class Island implements DataObject {
|
|||||||
members.put(playerUUID, RanksManager.MEMBER_RANK);
|
members.put(playerUUID, RanksManager.MEMBER_RANK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds target to a list of banned players for this island. May be blocked by the event being cancelled.
|
* Adds target to a list of banned players for this island. May be blocked by the event being cancelled.
|
||||||
* If the player is a member, coop or trustee, they will be removed from those lists.
|
* If the player is a member, coop or trustee, they will be removed from those lists.
|
||||||
@ -155,6 +156,7 @@ public class Island implements DataObject {
|
|||||||
public long getCreatedDate(){
|
public long getCreatedDate(){
|
||||||
return createdDate;
|
return createdDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Island Guard flag's setting. If this is a protection flag, the this will be the
|
* Gets the Island Guard flag's setting. If this is a protection flag, the this will be the
|
||||||
* rank needed to bypass this flag. If it is a Settings flag, any non-zero value means the
|
* rank needed to bypass this flag. If it is a Settings flag, any non-zero value means the
|
||||||
|
@ -648,6 +648,7 @@ public class IslandWorldManager {
|
|||||||
return gameModes.get(Util.getWorld(world)).getWorldSettings().getDeathsMax();
|
return gameModes.get(Util.getWorld(world)).getWorldSettings().getDeathsMax();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getBanLimit(World world) {
|
||||||
|
return gameModes.get(Util.getWorld(world)).getWorldSettings().getBanLimit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,6 +369,7 @@ commands:
|
|||||||
cannot-ban-yourself: "&cYou cannot ban yourself!"
|
cannot-ban-yourself: "&cYou cannot ban yourself!"
|
||||||
cannot-ban: "&cThat player cannot be banned."
|
cannot-ban: "&cThat player cannot be banned."
|
||||||
cannot-ban-member: "&cKick the team member first, then ban."
|
cannot-ban-member: "&cKick the team member first, then ban."
|
||||||
|
cannot-ban-more-players: "&cYou reached the ban limit, you cannot ban any more players from your island."
|
||||||
player-already-banned: "&cPlayer is already banned"
|
player-already-banned: "&cPlayer is already banned"
|
||||||
owner-banned-you: "&b[name]&c banned you from their island!"
|
owner-banned-you: "&b[name]&c banned you from their island!"
|
||||||
you-are-banned: "&bYou are banned from this island!"
|
you-are-banned: "&bYou are banned from this island!"
|
||||||
@ -383,6 +384,7 @@ commands:
|
|||||||
noone: "&aNo one is banned on this island"
|
noone: "&aNo one is banned on this island"
|
||||||
the-following: "&bThe following players are banned:"
|
the-following: "&bThe following players are banned:"
|
||||||
names: "&c[line]"
|
names: "&c[line]"
|
||||||
|
you-can-ban: "&bYou can ban up to &e[number] &bmore players."
|
||||||
settings:
|
settings:
|
||||||
description: "display island settings"
|
description: "display island settings"
|
||||||
language:
|
language:
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package world.bentobox.bentobox.api.commands.island;
|
package world.bentobox.bentobox.api.commands.island;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@ -61,9 +58,6 @@ public class IslandBanCommandTest {
|
|||||||
private PlayersManager pm;
|
private PlayersManager pm;
|
||||||
private Island island;
|
private Island island;
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
@ -121,7 +115,6 @@ public class IslandBanCommandTest {
|
|||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -241,6 +234,7 @@ public class IslandBanCommandTest {
|
|||||||
when(targetUser.isPlayer()).thenReturn(true);
|
when(targetUser.isPlayer()).thenReturn(true);
|
||||||
when(targetUser.isOnline()).thenReturn(false);
|
when(targetUser.isOnline()).thenReturn(false);
|
||||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser);
|
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser);
|
||||||
|
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(-1);
|
||||||
|
|
||||||
// Allow adding to ban list
|
// Allow adding to ban list
|
||||||
when(island.addToBanList(Mockito.any())).thenReturn(true);
|
when(island.addToBanList(Mockito.any())).thenReturn(true);
|
||||||
@ -263,6 +257,7 @@ public class IslandBanCommandTest {
|
|||||||
when(targetUser.isPlayer()).thenReturn(true);
|
when(targetUser.isPlayer()).thenReturn(true);
|
||||||
when(targetUser.isOnline()).thenReturn(true);
|
when(targetUser.isOnline()).thenReturn(true);
|
||||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser);
|
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser);
|
||||||
|
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(-1);
|
||||||
// Allow adding to ban list
|
// Allow adding to ban list
|
||||||
when(island.addToBanList(Mockito.any())).thenReturn(true);
|
when(island.addToBanList(Mockito.any())).thenReturn(true);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user