Skip to content

Commit 549596d

Browse files
committed
banClients: Use arrays instead of collections, like everywhere else
I don't really like this, to be honest. Collections would be far superior to accepting arrays as parameters. However, alea iacta est, and having just one or two API methods with a different method layout would be kind of weird. Perhaps we can do some kind of an "Array 2.0" at some point in time.
1 parent 35e1da6 commit 549596d

3 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/main/java/com/github/theholywaffle/teamspeak3/TS3Api.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
import java.io.InputStream;
3838
import java.io.OutputStream;
39-
import java.util.Collection;
4039
import java.util.List;
4140
import java.util.Map;
4241
import java.util.regex.Pattern;
@@ -614,7 +613,7 @@ public int[] banClient(int clientId, String reason) {
614613
* @see Client#getId()
615614
* @see #addBan(String, String, String, long, String)
616615
*/
617-
public int[] banClients(Collection<Integer> clientIds, long timeInSeconds, String reason, boolean continueOnError) {
616+
public int[] banClients(int[] clientIds, long timeInSeconds, String reason, boolean continueOnError) {
618617
return asyncApi.banClients(clientIds, timeInSeconds, reason, continueOnError).getUninterruptibly();
619618
}
620619

src/main/java/com/github/theholywaffle/teamspeak3/TS3ApiAsync.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ public CommandFuture<int[]> banClient(int clientId, long timeInSeconds) {
600600
* @see #addBan(String, String, String, long, String)
601601
*/
602602
public CommandFuture<int[]> banClient(int clientId, long timeInSeconds, String reason) {
603-
Command cmd = BanCommands.banClient(Collections.singletonList(clientId), timeInSeconds, reason, false);
603+
Command cmd = BanCommands.banClient(new int[] {clientId}, timeInSeconds, reason, false);
604604
return executeAndReturnIntArray(cmd, "banid");
605605
}
606606

@@ -663,7 +663,10 @@ public CommandFuture<int[]> banClient(int clientId, String reason) {
663663
* @see Client#getId()
664664
* @see #addBan(String, String, String, long, String)
665665
*/
666-
public CommandFuture<int[]> banClients(Collection<Integer> clientIds, long timeInSeconds, String reason, boolean continueOnError) {
666+
public CommandFuture<int[]> banClients(int[] clientIds, long timeInSeconds, String reason, boolean continueOnError) {
667+
if (clientIds == null) throw new IllegalArgumentException("Client ID array was null");
668+
if (clientIds.length == 0) return CommandFuture.immediate(new int[0]); // Success
669+
667670
Command cmd = BanCommands.banClient(clientIds, timeInSeconds, reason, continueOnError);
668671
return executeAndReturnIntArray(cmd, "banid");
669672
}

src/main/java/com/github/theholywaffle/teamspeak3/commands/BanCommands.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam;
3131
import com.github.theholywaffle.teamspeak3.commands.parameter.OptionParam;
3232

33-
import java.util.Collection;
34-
3533
public final class BanCommands {
3634

3735
private BanCommands() {
@@ -53,14 +51,13 @@ public static Command banAdd(String ip, String name, String uid, String myTSId,
5351
return builder.build();
5452
}
5553

56-
public static Command banClient(Collection<Integer> clientIds, long timeInSeconds,
57-
String reason, boolean continueOnError) {
54+
public static Command banClient(int[] clientIds, long timeInSeconds, String reason, boolean continueOnError) {
5855
CommandBuilder builder = new CommandBuilder("banclient", 4);
5956
builder.addIf(timeInSeconds > 0, new KeyValueParam("time", timeInSeconds));
6057
builder.addIf(reason != null, new KeyValueParam("banreason", reason));
6158
builder.addIf(continueOnError, new OptionParam("continueonerror"));
6259

63-
ArrayParameter clients = new ArrayParameter(clientIds.size());
60+
ArrayParameter clients = new ArrayParameter(clientIds.length);
6461
for (int clientId : clientIds) {
6562
clients.add(new KeyValueParam("clid", clientId));
6663
}

0 commit comments

Comments
 (0)