diff --git a/src/main/java/com/github/manevolent/ts3j/command/response/AbstractCommandResponse.java b/src/main/java/com/github/manevolent/ts3j/command/response/AbstractCommandResponse.java index 141b2a6..89648c6 100644 --- a/src/main/java/com/github/manevolent/ts3j/command/response/AbstractCommandResponse.java +++ b/src/main/java/com/github/manevolent/ts3j/command/response/AbstractCommandResponse.java @@ -1,5 +1,6 @@ package com.github.manevolent.ts3j.command.response; +import com.github.manevolent.ts3j.command.CommandException; import com.github.manevolent.ts3j.command.MultiCommand; import com.github.manevolent.ts3j.util.Ts3Debugging; @@ -22,21 +23,40 @@ public abstract class AbstractCommandResponse implements CommandResponse { * Completes the command without any post-mapping processing, lowering overhead. */ @Override - public void complete() - throws ExecutionException, InterruptedException { - future.get(); + public void complete() throws InterruptedException, CommandException { + try { + future.get(); + } catch (ExecutionException ex) { + if (ex.getCause() != null && ex.getCause() instanceof CommandException) + throw (CommandException) ex.getCause(); + else + throw new RuntimeException(ex); + } } @Override public T get(long timeoutMillis) - throws TimeoutException, ExecutionException, InterruptedException { - return map(future.get(timeoutMillis, TimeUnit.MILLISECONDS)); + throws TimeoutException, InterruptedException, CommandException { + try { + return map(future.get(timeoutMillis, TimeUnit.MILLISECONDS)); + } catch (ExecutionException ex) { + if (ex.getCause() != null && ex.getCause() instanceof CommandException) + throw (CommandException) ex.getCause(); + else + throw new RuntimeException(ex); + } } @Override - public T get() - throws ExecutionException, InterruptedException { - return map(future.get()); + public T get() throws InterruptedException, CommandException { + try { + return map(future.get()); + } catch (ExecutionException ex) { + if (ex.getCause() != null && ex.getCause() instanceof CommandException) + throw (CommandException) ex.getCause(); + else + throw new RuntimeException(ex); + } } public void completeSuccess(Iterable commands) { diff --git a/src/main/java/com/github/manevolent/ts3j/command/response/CommandResponse.java b/src/main/java/com/github/manevolent/ts3j/command/response/CommandResponse.java index 834f202..74f8e21 100644 --- a/src/main/java/com/github/manevolent/ts3j/command/response/CommandResponse.java +++ b/src/main/java/com/github/manevolent/ts3j/command/response/CommandResponse.java @@ -1,6 +1,7 @@ package com.github.manevolent.ts3j.command.response; import com.github.manevolent.ts3j.command.Command; +import com.github.manevolent.ts3j.command.CommandException; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -9,12 +10,11 @@ public interface CommandResponse { Command getCommand(); - default void complete() - throws ExecutionException, InterruptedException { + default void complete() throws InterruptedException, CommandException { get(); } - T get(long timeoutMillis) throws TimeoutException, ExecutionException, InterruptedException; - T get() throws ExecutionException, InterruptedException; + T get(long timeoutMillis) throws TimeoutException, InterruptedException, CommandException; + T get() throws InterruptedException, CommandException; } diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java index 3ce7af4..dd38ea1 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java @@ -887,7 +887,7 @@ public class LocalTeamspeakClientSocket */ public void clientAddPermission(int clientDatabaseId, Permission... permission) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { MultiCommand command = new MultiCommand( "clientaddperm", ProtocolRole.CLIENT, @@ -905,7 +905,7 @@ public class LocalTeamspeakClientSocket } public void clientDeletePermission(int clientDatabaseId, Permission... permission) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { MultiCommand command = new MultiCommand( "clientdelperm", ProtocolRole.CLIENT, @@ -923,7 +923,7 @@ public class LocalTeamspeakClientSocket } public void channelAddPermission(int channelId, Permission... permission) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { MultiCommand command = new MultiCommand( "channeladdperm", ProtocolRole.CLIENT, @@ -941,7 +941,7 @@ public class LocalTeamspeakClientSocket } public void channelClientAddPermission(int channelId, int clientDatabaseId, Permission... permission) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { MultiCommand command = new MultiCommand( "channelclientaddperm", ProtocolRole.CLIENT, @@ -960,7 +960,7 @@ public class LocalTeamspeakClientSocket } public void channelClientDeletePermission(int channelId, int clientDatabaseId, Permission... permission) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { MultiCommand command = new MultiCommand( "channeldelperm", ProtocolRole.CLIENT, @@ -1008,7 +1008,7 @@ public class LocalTeamspeakClientSocket specifies the ID of the recipient, whether it be a virtual server, a channel or a client. */ public void sendServerMessage(String message) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT); command.add(new CommandSingleParameter("targetmode", Integer.toString(3))); @@ -1023,7 +1023,7 @@ public class LocalTeamspeakClientSocket specifies the ID of the recipient, whether it be a virtual server, a channel or a client. */ public void sendChannelMessage(int channelId, String message) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT); command.add(new CommandSingleParameter("targetmode", Integer.toString(2))); @@ -1038,7 +1038,7 @@ public class LocalTeamspeakClientSocket specifies the ID of the recipient, whether it be a virtual server, a channel or a client. */ public void sendPrivateMessage(int clientId, String message) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT); command.add(new CommandSingleParameter("targetmode", Integer.toString(1))); @@ -1054,7 +1054,7 @@ public class LocalTeamspeakClientSocket channel has no password, the parameter can be omitted. */ public void clientMove(int clientId, int channelId, String password) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand("clientmove", ProtocolRole.CLIENT); command.add(new CommandSingleParameter("cid", Integer.toString(channelId))); @@ -1065,7 +1065,7 @@ public class LocalTeamspeakClientSocket } public void joinChannel(int channelId, String password) - throws InterruptedException, ExecutionException, TimeoutException, IOException { + throws InterruptedException, TimeoutException, IOException, CommandException { clientMove(getClientId(), channelId, password); } @@ -1075,7 +1075,7 @@ public class LocalTeamspeakClientSocket channel has no password, the parameter can be omitted. */ public Iterable listChannels() - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand("channellist", ProtocolRole.CLIENT); return executeCommand(command, x -> new Channel(x.toMap())).get(); @@ -1087,14 +1087,14 @@ public class LocalTeamspeakClientSocket channel has no password, the parameter can be omitted. */ public Iterable listClients() - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand("clientlist", ProtocolRole.CLIENT); return executeCommand(command, x -> new Client(x.toMap())).get(); } public void serverGroupAddClient(int groupId, int clientDatabaseId) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand("servergroupaddclient", ProtocolRole.CLIENT); command.add(new CommandSingleParameter("sgid", Integer.toString(groupId))); @@ -1104,7 +1104,7 @@ public class LocalTeamspeakClientSocket } public void serverGroupRemoveClient(int groupId, int clientDatabaseId) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand("servergroupdelclient", ProtocolRole.CLIENT); command.add(new CommandSingleParameter("sgid", Integer.toString(groupId))); @@ -1119,7 +1119,7 @@ public class LocalTeamspeakClientSocket channel has no password, the parameter can be omitted. */ public void clientPoke(int clientId, String message) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand("clientpoke", ProtocolRole.CLIENT); command.add(new CommandSingleParameter("clid", Integer.toString(clientId))); @@ -1135,7 +1135,7 @@ public class LocalTeamspeakClientSocket and may only have a maximum of 40 characters. */ public void kick(Collection clientIds, String message) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { MultiCommand command = new MultiCommand( "clientkick", ProtocolRole.CLIENT, @@ -1151,13 +1151,13 @@ public class LocalTeamspeakClientSocket executeCommand(command).complete(); } - public void subscribeAll() throws IOException, TimeoutException, ExecutionException, InterruptedException { + public void subscribeAll() throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand("channelsubscribeall", ProtocolRole.CLIENT); executeCommand(command).get(); } public Client getClientInfo(int clientId) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand( "clientinfo", ProtocolRole.CLIENT, @@ -1178,7 +1178,7 @@ public class LocalTeamspeakClientSocket } public Channel getChannelInfo(int channelId) - throws IOException, TimeoutException, ExecutionException, InterruptedException { + throws IOException, TimeoutException, InterruptedException, CommandException { Command command = new SingleCommand( "channelinfo", ProtocolRole.CLIENT, diff --git a/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java b/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java index 505e7c1..99da02f 100644 --- a/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java +++ b/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java @@ -13,7 +13,7 @@ public class ServerConnectionTest { public static void main(String[] args) throws Exception { Ts3Debugging.setEnabled(true); - LocalIdentity identity = LocalIdentity.read(new File("ident.ini")); + LocalIdentity identity = LocalIdentity.generateNew(10); LocalTeamspeakClientSocket client = new LocalTeamspeakClientSocket(); client.setIdentity(identity);