Skip to content

Commit f5503b8

Browse files
committed
feat: leave command with limit
1 parent 6473d53 commit f5503b8

File tree

1 file changed

+19
-0
lines changed
  • src/main/java/me/creepermaxcz/mcbots

1 file changed

+19
-0
lines changed

src/main/java/me/creepermaxcz/mcbots/Main.java

+19
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,33 @@ else if (commandName.equalsIgnoreCase("list") || commandName.equalsIgnoreCase("l
459459

460460
else if (commandName.equalsIgnoreCase("leave") || commandName.equalsIgnoreCase("exit"))
461461
{
462+
int limit = -1;
463+
if (split.length >= 2) {
464+
try {
465+
limit = Integer.parseInt(split[1]);
466+
} catch (NumberFormatException e) {
467+
limit = 0;
468+
Log.warn("Invalid limit.");
469+
}
470+
}
471+
472+
int i = 0;
462473
if (!controlledBots.isEmpty()) {
463474
Log.info("Disconnecting controlled bots.");
464475
for (Bot bot : controlledBots) {
476+
if (i++ == limit) {
477+
break;
478+
}
479+
465480
bot.disconnect();
466481
}
467482
} else {
468483
Log.info("Disconnecting all bots.");
469484
for (Bot bot : bots) {
485+
if (i++ == limit) {
486+
break;
487+
}
488+
470489
bot.disconnect();
471490
}
472491
}

0 commit comments

Comments
 (0)