diff --git a/src/main/java/world/bentobox/bentobox/Settings.java b/src/main/java/world/bentobox/bentobox/Settings.java index 78c94285a..f5733b029 100644 --- a/src/main/java/world/bentobox/bentobox/Settings.java +++ b/src/main/java/world/bentobox/bentobox/Settings.java @@ -162,6 +162,10 @@ public class Settings implements DataObject { @ConfigEntry(path = "island.name.max-length") private int nameMaxLength = 20; + @ConfigComment("How long a player must wait until they can ban a player") + @ConfigComment("after unbanning them. In minutes.") + @ConfigEntry(path = "island.ban-wait") + private int banWait = 10; // Ranks @ConfigEntry(path = "island.customranks") @@ -607,4 +611,19 @@ public class Settings implements DataObject { public void setNameMaxLength(int nameMaxLength) { this.nameMaxLength = nameMaxLength; } + + /** + * @return the banWait + */ + public int getBanWait() { + return banWait; + } + + /** + * @param banWait the banWait to set + */ + public void setBanWait(int banWait) { + this.banWait = banWait; + } + } \ No newline at end of file diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java index 412636302..653bd6e3c 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java @@ -59,17 +59,20 @@ public class IslandBanCommand extends CompositeCommand { } if (getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) { user.sendMessage("commands.island.ban.cannot-ban-member"); - return false; + return false; } if (getIslands().getIsland(getWorld(), playerUUID).isBanned(targetUUID)) { user.sendMessage("commands.island.ban.player-already-banned"); - return false; - } + return false; + } + if (getSettings().getBanWait() > 0 && !checkCooldown(user, targetUUID)) { + return false; + } User target = User.getInstance(targetUUID); // Cannot ban ops if (target.isOp()) { user.sendMessage("commands.island.ban.cannot-ban"); - return false; + return false; } // Finished error checking - start the banning return ban(user, target); @@ -84,7 +87,7 @@ public class IslandBanCommand extends CompositeCommand { 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; } // Banning was blocked, maybe due to an event cancellation. Fail silently. diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java index d4517513f..56de6e84a 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java @@ -31,7 +31,7 @@ public class IslandUnbanCommand extends CompositeCommand { // Show help showHelp(this, user); return false; - } + } UUID playerUUID = user.getUniqueId(); // Player issuing the command must have an island if (!getIslands().hasIsland(getWorld(), playerUUID)) { @@ -55,7 +55,7 @@ public class IslandUnbanCommand extends CompositeCommand { } if (!getIslands().getIsland(getWorld(), playerUUID).isBanned(targetUUID)) { user.sendMessage("commands.island.unban.player-not-banned"); - return false; + return false; } // Finished error checking - start the unbanning User targetUser = User.getInstance(targetUUID); @@ -66,6 +66,11 @@ public class IslandUnbanCommand extends CompositeCommand { if (getIslands().getIsland(getWorld(), user.getUniqueId()).removeFromBanList(targetUser.getUniqueId())) { user.sendMessage("general.success"); targetUser.sendMessage("commands.island.unban.you-are-unbanned", TextVariables.NAME, user.getName()); + // Set cooldown + if (getSettings().getBanWait() > 0 && getParent() != null) { + getParent().getSubCommand("ban").ifPresent(subCommand -> + subCommand.setCooldown(user.getUniqueId(), targetUser.getUniqueId(), getSettings().getBanWait() * 60)); + } return true; } // Unbanning was blocked, maybe due to an event cancellation. Fail silently. @@ -73,7 +78,7 @@ public class IslandUnbanCommand extends CompositeCommand { } @Override - public Optional> tabComplete(User user, String alias, List args) { + public Optional> tabComplete(User user, String alias, List args) { Island island = getIslands().getIsland(getWorld(), user.getUniqueId()); List options = island.getBanned().stream().map(getPlayers()::getName).collect(Collectors.toList()); String lastArg = !args.isEmpty() ? args.get(args.size()-1) : ""; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d2c46b4a7..c0f94e69e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -83,6 +83,9 @@ island: # These set the minimum and maximum size of a name. min-length: 4 max-length: 20 + # How long a player must wait until they can ban a player + # after unbanning them. In minutes. + ban-wait: 10 customranks: {} # These settings should not be edited uniqueId: config