-
-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/net/dv8tion/jda/api/events/channel/VoiceChannelEffectSendEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.dv8tion.jda.api.events.channel; | ||
|
||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.entities.channel.Channel; | ||
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Indicates that a {@link VoiceChannel.Effect voice channel effect} was sent in a {@link VoiceChannel}. | ||
*/ | ||
public class VoiceChannelEffectSendEvent extends GenericChannelEvent | ||
{ | ||
private final VoiceChannel.Effect effect; | ||
|
||
public VoiceChannelEffectSendEvent(@Nonnull JDA api, long responseNumber, Channel channel, VoiceChannel.Effect effect) | ||
{ | ||
super(api, responseNumber, channel); | ||
this.effect = effect; | ||
} | ||
|
||
@Nonnull | ||
public VoiceChannel getVoiceChannel() | ||
{ | ||
return getChannel().asVoiceChannel(); | ||
} | ||
|
||
@Nonnull | ||
public VoiceChannel.Effect getEffect() | ||
{ | ||
return effect; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/net/dv8tion/jda/internal/handle/VoiceChannelEffectSendHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.dv8tion.jda.internal.handle; | ||
|
||
import net.dv8tion.jda.api.entities.SoundboardSound; | ||
import net.dv8tion.jda.api.entities.User; | ||
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; | ||
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel.Effect; | ||
import net.dv8tion.jda.api.entities.emoji.EmojiUnion; | ||
import net.dv8tion.jda.api.events.channel.VoiceChannelEffectSendEvent; | ||
import net.dv8tion.jda.api.utils.data.DataObject; | ||
import net.dv8tion.jda.internal.JDAImpl; | ||
import net.dv8tion.jda.internal.entities.EntityBuilder; | ||
import net.dv8tion.jda.internal.entities.GuildImpl; | ||
|
||
public class VoiceChannelEffectSendHandler extends SocketHandler | ||
{ | ||
public VoiceChannelEffectSendHandler(JDAImpl api) | ||
{ | ||
super(api); | ||
} | ||
|
||
@Override | ||
protected Long handleInternally(DataObject content) | ||
{ | ||
final long guildId = content.getLong("guild_id"); | ||
if (getJDA().getGuildSetupController().isLocked(guildId)) | ||
return guildId; | ||
|
||
GuildImpl guild = (GuildImpl) getJDA().getGuildById(guildId); | ||
if (guild == null) | ||
{ | ||
getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle); | ||
return null; | ||
} | ||
|
||
final long channelId = content.getLong("channel_id"); | ||
VoiceChannel channel = guild.getVoiceChannelById(channelId); | ||
if (channel == null) | ||
{ | ||
getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle); | ||
return null; | ||
} | ||
|
||
User user = api.getUserById(content.getString("user_id")); | ||
EmojiUnion emoji = content.optObject("emoji").map(EntityBuilder::createEmoji).orElse(null); | ||
Effect.Animation animation = content.opt("animation_type") | ||
.map(rawAnimationType -> | ||
{ | ||
long animationId = content.getLong("animation_id"); | ||
Effect.Animation.Type type = Effect.Animation.Type.fromValue(Integer.parseInt(rawAnimationType.toString())); | ||
return new Effect.Animation(animationId, type); | ||
}) | ||
.orElse(null); | ||
SoundboardSound soundboardSound = content.opt("sound_id") | ||
.map(soundId -> guild.getSoundboardSoundById(soundId.toString())) | ||
.orElse(null); | ||
|
||
Effect effect = new Effect(channel, user, emoji, animation, soundboardSound); | ||
|
||
api.handleEvent(new VoiceChannelEffectSendEvent(api, responseNumber, channel, effect)); | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters