From f248faad72b0c463ad567cd22d3f8319cfbff1b1 Mon Sep 17 00:00:00 2001 From: Manevolent Date: Fri, 31 Aug 2018 21:54:15 -0400 Subject: [PATCH] Add support for more missing events --- pom.xml | 2 +- .../ts3j/event/ChannelUnsubscribedEvent.java | 47 +++++++++++++ .../ts3j/event/ClientChatComposingEvent.java | 14 ++++ .../ts3j/event/ClientPokeEvent.java | 18 +++++ .../event/ServerGroupClientAddedEvent.java | 53 +++++++++++++++ .../event/ServerGroupClientDeletedEvent.java | 53 +++++++++++++++ .../manevolent/ts3j/event/TS3Event.java | 10 +++ .../manevolent/ts3j/event/TS3Listener.java | 68 +++++++------------ .../client/LocalClientHandlerFull.java | 2 +- 9 files changed, 222 insertions(+), 45 deletions(-) create mode 100644 src/main/java/com/github/manevolent/ts3j/event/ChannelUnsubscribedEvent.java create mode 100644 src/main/java/com/github/manevolent/ts3j/event/ClientChatComposingEvent.java create mode 100644 src/main/java/com/github/manevolent/ts3j/event/ClientPokeEvent.java create mode 100644 src/main/java/com/github/manevolent/ts3j/event/ServerGroupClientAddedEvent.java create mode 100644 src/main/java/com/github/manevolent/ts3j/event/ServerGroupClientDeletedEvent.java diff --git a/pom.xml b/pom.xml index 5d85690..9e6206b 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 1.8 - 1.8 + 1.8 diff --git a/src/main/java/com/github/manevolent/ts3j/event/ChannelUnsubscribedEvent.java b/src/main/java/com/github/manevolent/ts3j/event/ChannelUnsubscribedEvent.java new file mode 100644 index 0000000..2950312 --- /dev/null +++ b/src/main/java/com/github/manevolent/ts3j/event/ChannelUnsubscribedEvent.java @@ -0,0 +1,47 @@ +package com.github.manevolent.ts3j.event; + +/* + * #%L + * TeamSpeak 3 Java API + * %% + * Copyright (C) 2014 Bert De Geyter + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ + +import com.github.manevolent.ts3j.api.ChannelProperty; + +import java.util.Map; + +public class ChannelUnsubscribedEvent extends BaseEvent { + + public ChannelUnsubscribedEvent(Map map) { + super(map); + } + + public int getChannelId() { + return getInt(ChannelProperty.CID); + } + + @Override + public void fire(TS3Listener listener) { + listener.onChannelUnsubscribed(this); + } +} diff --git a/src/main/java/com/github/manevolent/ts3j/event/ClientChatComposingEvent.java b/src/main/java/com/github/manevolent/ts3j/event/ClientChatComposingEvent.java new file mode 100644 index 0000000..16c9f39 --- /dev/null +++ b/src/main/java/com/github/manevolent/ts3j/event/ClientChatComposingEvent.java @@ -0,0 +1,14 @@ +package com.github.manevolent.ts3j.event; + +import java.util.Map; + +public class ClientChatComposingEvent extends BaseEvent { + public ClientChatComposingEvent(Map map) { + super(map); + } + + @Override + public void fire(TS3Listener listener) { + listener.onClientComposing(this); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/manevolent/ts3j/event/ClientPokeEvent.java b/src/main/java/com/github/manevolent/ts3j/event/ClientPokeEvent.java new file mode 100644 index 0000000..8ee5110 --- /dev/null +++ b/src/main/java/com/github/manevolent/ts3j/event/ClientPokeEvent.java @@ -0,0 +1,18 @@ +package com.github.manevolent.ts3j.event; + +import java.util.Map; + +public class ClientPokeEvent extends BaseEvent { + public ClientPokeEvent(Map map) { + super(map); + } + + public String getMessage() { + return get("msg"); + } + + @Override + public void fire(TS3Listener listener) { + listener.onClientPoke(this); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/manevolent/ts3j/event/ServerGroupClientAddedEvent.java b/src/main/java/com/github/manevolent/ts3j/event/ServerGroupClientAddedEvent.java new file mode 100644 index 0000000..2f5c785 --- /dev/null +++ b/src/main/java/com/github/manevolent/ts3j/event/ServerGroupClientAddedEvent.java @@ -0,0 +1,53 @@ +package com.github.manevolent.ts3j.event; + +/* + * #%L + * TeamSpeak 3 Java API + * %% + * Copyright (C) 2014 Bert De Geyter + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ + +import java.util.Map; + +public class ServerGroupClientAddedEvent extends BaseEvent { + + public ServerGroupClientAddedEvent(Map map) { + super(map); + } + + public int getServerGroupId() { + return getInt("sgid"); + } + + public int getClientId() { + return getInt("clid"); + } + + public String getName() { + return get("name"); + } + + @Override + public void fire(TS3Listener listener) { + listener.onServerGroupClientAdded(this); + } +} diff --git a/src/main/java/com/github/manevolent/ts3j/event/ServerGroupClientDeletedEvent.java b/src/main/java/com/github/manevolent/ts3j/event/ServerGroupClientDeletedEvent.java new file mode 100644 index 0000000..3450a29 --- /dev/null +++ b/src/main/java/com/github/manevolent/ts3j/event/ServerGroupClientDeletedEvent.java @@ -0,0 +1,53 @@ +package com.github.manevolent.ts3j.event; + +/* + * #%L + * TeamSpeak 3 Java API + * %% + * Copyright (C) 2014 Bert De Geyter + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ + +import java.util.Map; + +public class ServerGroupClientDeletedEvent extends BaseEvent { + + public ServerGroupClientDeletedEvent(Map map) { + super(map); + } + + public int getServerGroupId() { + return getInt("sgid"); + } + + public int getClientId() { + return getInt("clid"); + } + + public String getName() { + return get("name"); + } + + @Override + public void fire(TS3Listener listener) { + listener.onServerGroupClientRemove(this); + } +} diff --git a/src/main/java/com/github/manevolent/ts3j/event/TS3Event.java b/src/main/java/com/github/manevolent/ts3j/event/TS3Event.java index 44adebb..b04807f 100644 --- a/src/main/java/com/github/manevolent/ts3j/event/TS3Event.java +++ b/src/main/java/com/github/manevolent/ts3j/event/TS3Event.java @@ -69,6 +69,16 @@ public interface TS3Event { return new ClientUpdatedEvent(command.toMap()); case "notifychannelsubscribed": // CLIENT return new ChannelSubscribedEvent(command.toMap()); + case "notifychannelunsubscribed": // CLIENT + return new ChannelUnsubscribedEvent(command.toMap()); + case "notifyservergroupclientadded": // CLIENT + return new ServerGroupClientAddedEvent(command.toMap()); + case "notifyservergroupclientdeleted": // CLIENT + return new ServerGroupClientDeletedEvent(command.toMap()); + case "notifyclientpoke": // CLIENT + return new ClientPokeEvent(command.toMap()); + case "notifyclientchatcomposing": // CLIENT + return new ClientChatComposingEvent(command.toMap()); default: throw new IllegalArgumentException("unknown event: " + command.getName()); } diff --git a/src/main/java/com/github/manevolent/ts3j/event/TS3Listener.java b/src/main/java/com/github/manevolent/ts3j/event/TS3Listener.java index e75b3e0..5da5f49 100644 --- a/src/main/java/com/github/manevolent/ts3j/event/TS3Listener.java +++ b/src/main/java/com/github/manevolent/ts3j/event/TS3Listener.java @@ -26,48 +26,30 @@ package com.github.manevolent.ts3j.event; * #L% */ -import com.github.manevolent.ts3j.audio.Microphone; - public interface TS3Listener { - - void onTextMessage(TextMessageEvent e); - - void onClientJoin(ClientJoinEvent e); - - void onClientLeave(ClientLeaveEvent e); - - void onServerEdit(ServerEditedEvent e); - - void onChannelEdit(ChannelEditedEvent e); - - void onChannelDescriptionChanged(ChannelDescriptionEditedEvent e); - - void onClientMoved(ClientMovedEvent e); - - void onChannelCreate(ChannelCreateEvent e); - - void onChannelDeleted(ChannelDeletedEvent e); - - void onChannelMoved(ChannelMovedEvent e); - - void onChannelPasswordChanged(ChannelPasswordChangedEvent e); - - void onChannelList(ChannelListEvent e); - - void onPrivilegeKeyUsed(PrivilegeKeyUsedEvent e); - - void onChannelGroupList(ChannelGroupListEvent e); - - void onServerGroupList(ServerGroupListEvent e); - - void onClientNeededPermissions(ClientNeededPermissionsEvent e); - - void onClientChannelGroupChanged(ClientChannelGroupChangedEvent e); - - void onClientChanged(ClientUpdatedEvent e); - - void onDisconnected(DisconnectedEvent e); - - void onChannelSubscribed(ChannelSubscribedEvent e); - + default void onTextMessage(TextMessageEvent e) {} + default void onClientJoin(ClientJoinEvent e) {} + default void onClientLeave(ClientLeaveEvent e) {} + default void onServerEdit(ServerEditedEvent e) {} + default void onChannelEdit(ChannelEditedEvent e) {} + default void onChannelDescriptionChanged(ChannelDescriptionEditedEvent e) {} + default void onClientMoved(ClientMovedEvent e) {} + default void onChannelCreate(ChannelCreateEvent e) {} + default void onChannelDeleted(ChannelDeletedEvent e) {} + default void onChannelMoved(ChannelMovedEvent e) {} + default void onChannelPasswordChanged(ChannelPasswordChangedEvent e) {} + default void onChannelList(ChannelListEvent e) {} + default void onPrivilegeKeyUsed(PrivilegeKeyUsedEvent e) {} + default void onChannelGroupList(ChannelGroupListEvent e) {} + default void onServerGroupList(ServerGroupListEvent e) {} + default void onClientNeededPermissions(ClientNeededPermissionsEvent e) {} + default void onClientChannelGroupChanged(ClientChannelGroupChangedEvent e) {} + default void onClientChanged(ClientUpdatedEvent e) {} + default void onDisconnected(DisconnectedEvent e) {} + default void onChannelSubscribed(ChannelSubscribedEvent e) {} + default void onChannelUnsubscribed(ChannelUnsubscribedEvent e) {} + default void onServerGroupClientAdded(ServerGroupClientAddedEvent e) {} + default void onServerGroupClientRemove(ServerGroupClientDeletedEvent e) {} + default void onClientPoke(ClientPokeEvent e) {} + default void onClientComposing(ClientChatComposingEvent e) {} } diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/packet/handler/client/LocalClientHandlerFull.java b/src/main/java/com/github/manevolent/ts3j/protocol/packet/handler/client/LocalClientHandlerFull.java index 5ccf035..1833f0d 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/packet/handler/client/LocalClientHandlerFull.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/packet/handler/client/LocalClientHandlerFull.java @@ -42,7 +42,7 @@ public abstract class LocalClientHandlerFull extends LocalClientHandler { break; case COMMAND_LOW: - Ts3Debugging.debug("[COMMAND] [LOW] " + ((PacketBody2Command) packet.getBody()).getText()); + Ts3Debugging.debug("[COMMAND] [LOW] " + ((PacketBody3CommandLow) packet.getBody()).getText()); try { handleCommand(MultiCommand.parse(