+11
-9
src/main/java/com/github/puregero/minecraftstresstest/MinecraftStressTest.java
+11
-9
src/main/java/com/github/puregero/minecraftstresstest/MinecraftStressTest.java
···
14
14
15
15
public class MinecraftStressTest {
16
16
17
-
private static final int BOT_COUNT = Integer.parseInt(System.getProperty("bot.count", "1"));
18
17
private static final String ADDRESS = System.getProperty("bot.ip", "127.0.0.1");
19
18
private static final int PORT = Integer.parseInt(System.getProperty("bot.port", "25565"));
20
19
private static final int DELAY_BETWEEN_BOTS_MS = Integer.parseInt(System.getProperty("bot.login.delay.ms", "100"));
21
20
21
+
private static final String DEFAULT_BOT_COUNT = "1";
22
+
private static int BOT_COUNT = Integer.parseInt(System.getProperty("bot.count", DEFAULT_BOT_COUNT));
23
+
24
+
private static final List<Bot> bots = new ArrayList<>();
22
25
private static final EventLoopGroup workerGroup = new NioEventLoopGroup();
23
26
24
27
public static void main(String[] a) {
25
-
List<Bot> bots = new ArrayList<>();
26
-
27
-
updateBotCount(bots, BOT_COUNT);
28
+
updateBotCount();
28
29
29
30
Scanner scanner = new Scanner(System.in);
30
31
···
36
37
if (args[0].equalsIgnoreCase("count") || args[0].equalsIgnoreCase("botcount")) {
37
38
int botCount = Math.max(0, Integer.parseInt(args[1]));
38
39
System.out.println("Setting bot count to " + botCount);
39
-
updateBotCount(bots, botCount);
40
+
BOT_COUNT = botCount;
41
+
updateBotCount();
40
42
} else if (args[0].equalsIgnoreCase("speed")) {
41
43
double speed = Math.max(0.0, Double.parseDouble(args[1]));
42
44
System.out.println("Setting speed to " + speed);
···
47
49
Bot.RADIUS = radius;
48
50
} else {
49
51
System.out.println("Commands:");
50
-
System.out.println("count <number of bots>");
52
+
System.out.println("count <number of bots> (Default: " + DEFAULT_BOT_COUNT + ")");
51
53
System.out.println("speed <value> (Default: " + Bot.DEFAULT_SPEED + ")");
52
54
System.out.println("radius <value> (Default: " + Bot.DEFAULT_RADIUS + ")");
53
55
}
···
59
61
System.out.println("stdin ended");
60
62
}
61
63
62
-
private static void updateBotCount(List<Bot> bots, int botCount) {
63
-
while (bots.size() > botCount) {
64
+
private static void updateBotCount() {
65
+
while (bots.size() > BOT_COUNT) {
64
66
bots.remove(bots.size() - 1).close();
65
67
}
66
68
67
-
while (bots.size() < botCount) {
69
+
while (bots.size() < BOT_COUNT) {
68
70
bots.add(connectBot(System.getProperty("bot.name", "Bot") + (bots.size() + 1), ADDRESS, PORT));
69
71
try {
70
72
Thread.sleep(DELAY_BETWEEN_BOTS_MS);