Skip to content

Commit b8ef6f1

Browse files
committed
Add selectVirtualServer overloads that also set the query's nickname
... which is a new feature added in TS3 server v3.4.0
1 parent 6d40579 commit b8ef6f1

3 files changed

Lines changed: 177 additions & 10 deletions

File tree

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

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3699,13 +3699,38 @@ public List<CustomPropertyAssignment> searchCustomClientProperty(String key, Str
36993699
* if the execution of a command fails
37003700
* @querycommands 1
37013701
* @see VirtualServer#getId()
3702+
* @see #selectVirtualServerById(int, String)
37023703
* @see #selectVirtualServerByPort(int)
37033704
* @see #selectVirtualServer(VirtualServer)
37043705
*/
37053706
public void selectVirtualServerById(int id) {
37063707
asyncApi.selectVirtualServerById(id).getUninterruptibly();
37073708
}
37083709

3710+
/**
3711+
* Moves the server query into the virtual server with the specified ID
3712+
* and sets the server query's nickname.
3713+
* <p>
3714+
* The nickname must be between 3 and 30 UTF-8 bytes long. BB codes will be ignored.
3715+
* </p>
3716+
*
3717+
* @param id
3718+
* the ID of the virtual server
3719+
* @param nickname
3720+
* the nickname, or {@code null} if the nickname should not be set
3721+
*
3722+
* @throws TS3CommandFailedException
3723+
* if the execution of a command fails
3724+
* @querycommands 1
3725+
* @see VirtualServer#getId()
3726+
* @see #selectVirtualServerById(int)
3727+
* @see #selectVirtualServerByPort(int, String)
3728+
* @see #selectVirtualServer(VirtualServer, String)
3729+
*/
3730+
public void selectVirtualServerById(int id, String nickname) {
3731+
asyncApi.selectVirtualServerById(id, nickname).getUninterruptibly();
3732+
}
3733+
37093734
/**
37103735
* Moves the server query into the virtual server with the specified voice port.
37113736
*
@@ -3717,12 +3742,37 @@ public void selectVirtualServerById(int id) {
37173742
* @querycommands 1
37183743
* @see VirtualServer#getPort()
37193744
* @see #selectVirtualServerById(int)
3745+
* @see #selectVirtualServerByPort(int, String)
37203746
* @see #selectVirtualServer(VirtualServer)
37213747
*/
37223748
public void selectVirtualServerByPort(int port) {
37233749
asyncApi.selectVirtualServerByPort(port).getUninterruptibly();
37243750
}
37253751

3752+
/**
3753+
* Moves the server query into the virtual server with the specified voice port
3754+
* and sets the server query's nickname.
3755+
* <p>
3756+
* The nickname must be between 3 and 30 UTF-8 bytes long. BB codes will be ignored.
3757+
* </p>
3758+
*
3759+
* @param port
3760+
* the voice port of the virtual server
3761+
* @param nickname
3762+
* the nickname, or {@code null} if the nickname should not be set
3763+
*
3764+
* @throws TS3CommandFailedException
3765+
* if the execution of a command fails
3766+
* @querycommands 1
3767+
* @see VirtualServer#getPort()
3768+
* @see #selectVirtualServerById(int, String)
3769+
* @see #selectVirtualServerByPort(int)
3770+
* @see #selectVirtualServer(VirtualServer, String)
3771+
*/
3772+
public void selectVirtualServerByPort(int port, String nickname) {
3773+
asyncApi.selectVirtualServerByPort(port, nickname).getUninterruptibly();
3774+
}
3775+
37263776
/**
37273777
* Moves the server query into the specified virtual server.
37283778
*
@@ -3734,11 +3784,35 @@ public void selectVirtualServerByPort(int port) {
37343784
* @querycommands 1
37353785
* @see #selectVirtualServerById(int)
37363786
* @see #selectVirtualServerByPort(int)
3787+
* @see #selectVirtualServer(VirtualServer, String)
37373788
*/
37383789
public void selectVirtualServer(VirtualServer server) {
37393790
asyncApi.selectVirtualServer(server).getUninterruptibly();
37403791
}
37413792

3793+
/**
3794+
* Moves the server query into the specified virtual server
3795+
* and sets the server query's nickname.
3796+
* <p>
3797+
* The nickname must be between 3 and 30 UTF-8 bytes long. BB codes will be ignored.
3798+
* </p>
3799+
*
3800+
* @param server
3801+
* the virtual server to move into
3802+
* @param nickname
3803+
* the nickname, or {@code null} if the nickname should not be set
3804+
*
3805+
* @throws TS3CommandFailedException
3806+
* if the execution of a command fails
3807+
* @querycommands 1
3808+
* @see #selectVirtualServerById(int, String)
3809+
* @see #selectVirtualServerByPort(int, String)
3810+
* @see #selectVirtualServer(VirtualServer)
3811+
*/
3812+
public void selectVirtualServer(VirtualServer server, String nickname) {
3813+
asyncApi.selectVirtualServer(server, nickname).getUninterruptibly();
3814+
}
3815+
37423816
/**
37433817
* Sends an offline message to the client with the given unique identifier.
37443818
* <p>
@@ -4026,10 +4100,12 @@ public void setMessageReadFlag(Message message, boolean read) {
40264100

40274101
/**
40284102
* Sets the nickname of the server query client.
4029-
* The nickname must be between 3 and 30 UTF-8 bytes long and BB codes will be ignored.
4103+
* <p>
4104+
* The nickname must be between 3 and 30 UTF-8 bytes long. BB codes will be ignored.
4105+
* </p>
40304106
*
40314107
* @param nickname
4032-
* the new nickname, may not contain any BB codes and may not be {@code null}
4108+
* the new nickname, may not be {@code null}
40334109
*
40344110
* @throws TS3CommandFailedException
40354111
* if the execution of a command fails

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

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4265,11 +4265,38 @@ public CommandFuture<List<CustomPropertyAssignment>> searchCustomClientProperty(
42654265
* if the execution of a command fails
42664266
* @querycommands 1
42674267
* @see VirtualServer#getId()
4268+
* @see #selectVirtualServerById(int, String)
42684269
* @see #selectVirtualServerByPort(int)
42694270
* @see #selectVirtualServer(VirtualServer)
42704271
*/
42714272
public CommandFuture<Void> selectVirtualServerById(int id) {
4272-
Command cmd = QueryCommands.useId(id);
4273+
return selectVirtualServerById(id, null);
4274+
}
4275+
4276+
/**
4277+
* Moves the server query into the virtual server with the specified ID
4278+
* and sets the server query's nickname.
4279+
* <p>
4280+
* The nickname must be between 3 and 30 UTF-8 bytes long. BB codes will be ignored.
4281+
* </p>
4282+
*
4283+
* @param id
4284+
* the ID of the virtual server
4285+
* @param nickname
4286+
* the nickname, or {@code null} if the nickname should not be set
4287+
*
4288+
* @return a future to track the progress of this command
4289+
*
4290+
* @throws TS3CommandFailedException
4291+
* if the execution of a command fails
4292+
* @querycommands 1
4293+
* @see VirtualServer#getId()
4294+
* @see #selectVirtualServerById(int)
4295+
* @see #selectVirtualServerByPort(int, String)
4296+
* @see #selectVirtualServer(VirtualServer, String)
4297+
*/
4298+
public CommandFuture<Void> selectVirtualServerById(int id, String nickname) {
4299+
Command cmd = QueryCommands.useId(id, nickname);
42734300
return executeAndReturnError(cmd);
42744301
}
42754302

@@ -4286,10 +4313,37 @@ public CommandFuture<Void> selectVirtualServerById(int id) {
42864313
* @querycommands 1
42874314
* @see VirtualServer#getPort()
42884315
* @see #selectVirtualServerById(int)
4316+
* @see #selectVirtualServerByPort(int, String)
42894317
* @see #selectVirtualServer(VirtualServer)
42904318
*/
42914319
public CommandFuture<Void> selectVirtualServerByPort(int port) {
4292-
Command cmd = QueryCommands.usePort(port);
4320+
return selectVirtualServerByPort(port, null);
4321+
}
4322+
4323+
/**
4324+
* Moves the server query into the virtual server with the specified voice port
4325+
* and sets the server query's nickname.
4326+
* <p>
4327+
* The nickname must be between 3 and 30 UTF-8 bytes long. BB codes will be ignored.
4328+
* </p>
4329+
*
4330+
* @param port
4331+
* the voice port of the virtual server
4332+
* @param nickname
4333+
* the nickname, or {@code null} if the nickname should not be set
4334+
*
4335+
* @return a future to track the progress of this command
4336+
*
4337+
* @throws TS3CommandFailedException
4338+
* if the execution of a command fails
4339+
* @querycommands 1
4340+
* @see VirtualServer#getPort()
4341+
* @see #selectVirtualServerById(int, String)
4342+
* @see #selectVirtualServerByPort(int)
4343+
* @see #selectVirtualServer(VirtualServer, String)
4344+
*/
4345+
public CommandFuture<Void> selectVirtualServerByPort(int port, String nickname) {
4346+
Command cmd = QueryCommands.usePort(port, nickname);
42934347
return executeAndReturnError(cmd);
42944348
}
42954349

@@ -4306,11 +4360,37 @@ public CommandFuture<Void> selectVirtualServerByPort(int port) {
43064360
* @querycommands 1
43074361
* @see #selectVirtualServerById(int)
43084362
* @see #selectVirtualServerByPort(int)
4363+
* @see #selectVirtualServer(VirtualServer, String)
43094364
*/
43104365
public CommandFuture<Void> selectVirtualServer(VirtualServer server) {
43114366
return selectVirtualServerById(server.getId());
43124367
}
43134368

4369+
/**
4370+
* Moves the server query into the specified virtual server
4371+
* and sets the server query's nickname.
4372+
* <p>
4373+
* The nickname must be between 3 and 30 UTF-8 bytes long. BB codes will be ignored.
4374+
* </p>
4375+
*
4376+
* @param server
4377+
* the virtual server to move into
4378+
* @param nickname
4379+
* the nickname, or {@code null} if the nickname should not be set
4380+
*
4381+
* @return a future to track the progress of this command
4382+
*
4383+
* @throws TS3CommandFailedException
4384+
* if the execution of a command fails
4385+
* @querycommands 1
4386+
* @see #selectVirtualServerById(int, String)
4387+
* @see #selectVirtualServerByPort(int, String)
4388+
* @see #selectVirtualServer(VirtualServer)
4389+
*/
4390+
public CommandFuture<Void> selectVirtualServer(VirtualServer server, String nickname) {
4391+
return selectVirtualServerById(server.getId(), nickname);
4392+
}
4393+
43144394
/**
43154395
* Sends an offline message to the client with the given unique identifier.
43164396
* <p>
@@ -4647,10 +4727,12 @@ public CommandFuture<Void> setMessageReadFlag(Message message, boolean read) {
46474727

46484728
/**
46494729
* Sets the nickname of the server query client.
4650-
* The nickname must be between 3 and 30 UTF-8 bytes long and BB codes will be ignored.
4730+
* <p>
4731+
* The nickname must be between 3 and 30 UTF-8 bytes long. BB codes will be ignored.
4732+
* </p>
46514733
*
46524734
* @param nickname
4653-
* the new nickname, may not contain any BB codes and may not be {@code null}
4735+
* the new nickname, may not be {@code null}
46544736
*
46554737
* @return a future to track the progress of this command
46564738
*

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import com.github.theholywaffle.teamspeak3.api.event.TS3EventType;
3030
import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam;
31+
import com.github.theholywaffle.teamspeak3.commands.parameter.OptionParam;
3132
import com.github.theholywaffle.teamspeak3.commands.parameter.ValueParam;
3233

3334
public final class QueryCommands {
@@ -70,12 +71,20 @@ public static Command serverNotifyUnregister() {
7071
return new CommandBuilder("servernotifyunregister").build();
7172
}
7273

73-
public static Command useId(int id) {
74-
return new CommandBuilder("use", 1).add(new KeyValueParam("sid", id)).build();
74+
public static Command useId(int id, String nickname) {
75+
CommandBuilder builder = new CommandBuilder("use", 3);
76+
builder.add(new KeyValueParam("sid", id));
77+
builder.add(new OptionParam("virtual"));
78+
builder.addIf(nickname != null, new KeyValueParam("client_nickname", nickname));
79+
return builder.build();
7580
}
7681

77-
public static Command usePort(int port) {
78-
return new CommandBuilder("use", 1).add(new KeyValueParam("port", port)).build();
82+
public static Command usePort(int port, String nickname) {
83+
CommandBuilder builder = new CommandBuilder("use", 3);
84+
builder.add(new KeyValueParam("port", port));
85+
builder.add(new OptionParam("virtual"));
86+
builder.addIf(nickname != null, new KeyValueParam("client_nickname", nickname));
87+
return builder.build();
7988
}
8089

8190
public static Command whoAmI() {

0 commit comments

Comments
 (0)