mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +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,15 +82,22 @@ public class IslandBanCommand extends CompositeCommand {
|
||||
|
||||
private boolean ban(User user, User targetUser) {
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island.addToBanList(targetUser.getUniqueId())) {
|
||||
user.sendMessage("general.success");
|
||||
targetUser.sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, user.getName());
|
||||
// If the player is online, has an island and on the banned island, move them home immediately
|
||||
if (targetUser.isOnline() && getIslands().hasIsland(getWorld(), targetUser.getUniqueId()) && island.onIsland(targetUser.getLocation())) {
|
||||
getIslands().homeTeleport(getWorld(), targetUser.getPlayer());
|
||||
island.getWorld().playSound(targetUser.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
|
||||
|
||||
// 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())) {
|
||||
user.sendMessage("general.success");
|
||||
targetUser.sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, user.getName());
|
||||
// If the player is online, has an island and on the banned island, move them home immediately
|
||||
if (targetUser.isOnline() && getIslands().hasIsland(getWorld(), targetUser.getUniqueId()) && island.onIsland(targetUser.getLocation())) {
|
||||
getIslands().homeTeleport(getWorld(), targetUser.getPlayer());
|
||||
island.getWorld().playSound(targetUser.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
|
||||
}
|
||||
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.
|
||||
return false;
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.database.objects.Island;
|
||||
|
||||
@ -64,6 +65,11 @@ public class IslandBanlistCommand extends CompositeCommand {
|
||||
}
|
||||
// Send the strings
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,6 @@ public interface WorldSettings {
|
||||
*/
|
||||
int getResetLimit();
|
||||
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@ -155,6 +156,7 @@ public class Island implements DataObject {
|
||||
public long getCreatedDate(){
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -648,6 +648,7 @@ public class IslandWorldManager {
|
||||
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: "&cThat player cannot be banned."
|
||||
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"
|
||||
owner-banned-you: "&b[name]&c banned you from their island!"
|
||||
you-are-banned: "&bYou are banned from this island!"
|
||||
@ -383,6 +384,7 @@ commands:
|
||||
noone: "&aNo one is banned on this island"
|
||||
the-following: "&bThe following players are banned:"
|
||||
names: "&c[line]"
|
||||
you-can-ban: "&bYou can ban up to &e[number] &bmore players."
|
||||
settings:
|
||||
description: "display island settings"
|
||||
language:
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.api.commands.island;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@ -61,9 +58,6 @@ public class IslandBanCommandTest {
|
||||
private PlayersManager pm;
|
||||
private Island island;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
@ -121,7 +115,6 @@ public class IslandBanCommandTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,6 +234,7 @@ public class IslandBanCommandTest {
|
||||
when(targetUser.isPlayer()).thenReturn(true);
|
||||
when(targetUser.isOnline()).thenReturn(false);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser);
|
||||
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(-1);
|
||||
|
||||
// Allow adding to ban list
|
||||
when(island.addToBanList(Mockito.any())).thenReturn(true);
|
||||
@ -263,6 +257,7 @@ public class IslandBanCommandTest {
|
||||
when(targetUser.isPlayer()).thenReturn(true);
|
||||
when(targetUser.isOnline()).thenReturn(true);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser);
|
||||
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(-1);
|
||||
// Allow adding to ban list
|
||||
when(island.addToBanList(Mockito.any())).thenReturn(true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user