Search in sources :

Example 6 with MemberImpl

use of org.javacord.core.entity.user.MemberImpl in project Javacord by BtoBastian.

the class GuildBanAddHandler method handle.

@Override
public void handle(JsonNode packet) {
    api.getPossiblyUnreadyServerById(packet.get("guild_id").asLong()).map(server -> (ServerImpl) server).ifPresent(server -> {
        User user = new UserImpl(api, packet.get("user"), (MemberImpl) null, server);
        server.removeMember(user.getId());
        ServerMemberBanEvent event = new ServerMemberBanEventImpl(server, user);
        api.getEventDispatcher().dispatchServerMemberBanEvent(server, server, user, event);
    });
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerMemberBanEvent(org.javacord.api.event.server.member.ServerMemberBanEvent) User(org.javacord.api.entity.user.User) PacketHandler(org.javacord.core.util.gateway.PacketHandler) DiscordApi(org.javacord.api.DiscordApi) UserImpl(org.javacord.core.entity.user.UserImpl) ServerMemberBanEventImpl(org.javacord.core.event.server.member.ServerMemberBanEventImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) User(org.javacord.api.entity.user.User) ServerImpl(org.javacord.core.entity.server.ServerImpl) UserImpl(org.javacord.core.entity.user.UserImpl) ServerMemberBanEvent(org.javacord.api.event.server.member.ServerMemberBanEvent) ServerMemberBanEventImpl(org.javacord.core.event.server.member.ServerMemberBanEventImpl)

Example 7 with MemberImpl

use of org.javacord.core.entity.user.MemberImpl in project Javacord by BtoBastian.

the class GuildMemberRemoveHandler method handle.

@Override
public void handle(JsonNode packet) {
    api.getPossiblyUnreadyServerById(packet.get("guild_id").asLong()).map(server -> (ServerImpl) server).ifPresent(server -> {
        User user = new UserImpl(api, packet.get("user"), (MemberImpl) null, server);
        server.removeMember(user.getId());
        server.decrementMemberCount();
        ServerMemberLeaveEvent event = new ServerMemberLeaveEventImpl(server, user);
        api.getEventDispatcher().dispatchServerMemberLeaveEvent(server, server, user, event);
    });
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) User(org.javacord.api.entity.user.User) ServerMemberLeaveEvent(org.javacord.api.event.server.member.ServerMemberLeaveEvent) PacketHandler(org.javacord.core.util.gateway.PacketHandler) DiscordApi(org.javacord.api.DiscordApi) UserImpl(org.javacord.core.entity.user.UserImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) ServerMemberLeaveEventImpl(org.javacord.core.event.server.member.ServerMemberLeaveEventImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) User(org.javacord.api.entity.user.User) ServerMemberLeaveEvent(org.javacord.api.event.server.member.ServerMemberLeaveEvent) ServerImpl(org.javacord.core.entity.server.ServerImpl) UserImpl(org.javacord.core.entity.user.UserImpl) ServerMemberLeaveEventImpl(org.javacord.core.event.server.member.ServerMemberLeaveEventImpl)

Example 8 with MemberImpl

use of org.javacord.core.entity.user.MemberImpl in project Javacord by BtoBastian.

the class GuildBanRemoveHandler method handle.

@Override
public void handle(JsonNode packet) {
    api.getPossiblyUnreadyServerById(packet.get("guild_id").asLong()).map(server -> (ServerImpl) server).ifPresent(server -> {
        User user = new UserImpl(api, packet.get("user"), (MemberImpl) null, server);
        ServerMemberUnbanEvent event = new ServerMemberUnbanEventImpl(server, user);
        api.getEventDispatcher().dispatchServerMemberUnbanEvent(server, server, user, event);
    });
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerMemberUnbanEventImpl(org.javacord.core.event.server.member.ServerMemberUnbanEventImpl) User(org.javacord.api.entity.user.User) PacketHandler(org.javacord.core.util.gateway.PacketHandler) DiscordApi(org.javacord.api.DiscordApi) UserImpl(org.javacord.core.entity.user.UserImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) ServerMemberUnbanEvent(org.javacord.api.event.server.member.ServerMemberUnbanEvent) ServerMemberUnbanEventImpl(org.javacord.core.event.server.member.ServerMemberUnbanEventImpl) User(org.javacord.api.entity.user.User) ServerImpl(org.javacord.core.entity.server.ServerImpl) UserImpl(org.javacord.core.entity.user.UserImpl) ServerMemberUnbanEvent(org.javacord.api.event.server.member.ServerMemberUnbanEvent)

Example 9 with MemberImpl

use of org.javacord.core.entity.user.MemberImpl in project Javacord by BtoBastian.

the class GuildMemberAddHandler method handle.

@Override
public void handle(JsonNode packet) {
    api.getPossiblyUnreadyServerById(packet.get("guild_id").asLong()).map(server -> (ServerImpl) server).ifPresent(server -> {
        MemberImpl member = server.addMember(packet);
        server.incrementMemberCount();
        User user = new UserImpl(api, packet.get("user"), member, server);
        ServerMemberJoinEvent event = new ServerMemberJoinEventImpl(server, user);
        api.getEventDispatcher().dispatchServerMemberJoinEvent(server, server, user, event);
    });
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerMemberJoinEventImpl(org.javacord.core.event.server.member.ServerMemberJoinEventImpl) ServerMemberJoinEvent(org.javacord.api.event.server.member.ServerMemberJoinEvent) User(org.javacord.api.entity.user.User) PacketHandler(org.javacord.core.util.gateway.PacketHandler) DiscordApi(org.javacord.api.DiscordApi) UserImpl(org.javacord.core.entity.user.UserImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) ServerMemberJoinEvent(org.javacord.api.event.server.member.ServerMemberJoinEvent) User(org.javacord.api.entity.user.User) ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerMemberJoinEventImpl(org.javacord.core.event.server.member.ServerMemberJoinEventImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) UserImpl(org.javacord.core.entity.user.UserImpl)

Example 10 with MemberImpl

use of org.javacord.core.entity.user.MemberImpl in project Javacord by BtoBastian.

the class VoiceStateUpdateHandler method handleServerVoiceChannel.

private void handleServerVoiceChannel(JsonNode packet, long userId) {
    api.getPossiblyUnreadyServerById(packet.get("guild_id").asLong()).map(ServerImpl.class::cast).ifPresent(server -> {
        Member member = new MemberImpl(api, server, packet.get("member"), null);
        Optional<ServerVoiceChannelImpl> oldChannel = server.getConnectedVoiceChannel(userId).map(ServerVoiceChannelImpl.class::cast);
        Optional<ServerVoiceChannelImpl> newChannel;
        if (packet.hasNonNull("channel_id")) {
            newChannel = server.getVoiceChannelById(packet.get("channel_id").asLong()).map(ServerVoiceChannelImpl.class::cast);
        } else {
            newChannel = Optional.empty();
        }
        if (!newChannel.equals(oldChannel)) {
            oldChannel.ifPresent(channel -> {
                channel.removeConnectedUser(userId);
                dispatchServerVoiceChannelMemberLeaveEvent(member, newChannel.orElse(null), channel, server);
            });
            newChannel.ifPresent(channel -> {
                channel.addConnectedUser(userId);
                dispatchServerVoiceChannelMemberJoinEvent(member, channel, oldChannel.orElse(null), server);
            });
        }
        if (!packet.hasNonNull("member")) {
            logger.warn("Received VOICE_STATE_UPDATE packet without non-null member field: {}", packet);
            return;
        }
        MemberImpl newMember = new MemberImpl(api, server, packet.get("member"), null);
        Member oldMember = server.getRealMemberById(packet.get("user_id").asLong()).orElse(null);
        boolean newSelfMuted = packet.get("self_mute").asBoolean();
        boolean oldSelfMuted = server.isSelfMuted(userId);
        if (newSelfMuted != oldSelfMuted) {
            UserChangeSelfMutedEventImpl event = new UserChangeSelfMutedEventImpl(newMember, oldMember);
            api.getEventDispatcher().dispatchUserChangeSelfMutedEvent(server, server, newMember.getUser(), event);
        }
        boolean newSelfDeafened = packet.get("self_deaf").asBoolean();
        boolean oldSelfDeafened = server.isSelfDeafened(userId);
        if (newSelfDeafened != oldSelfDeafened) {
            UserChangeSelfDeafenedEventImpl event = new UserChangeSelfDeafenedEventImpl(newMember, oldMember);
            api.getEventDispatcher().dispatchUserChangeSelfDeafenedEvent(server, server, newMember.getUser(), event);
        }
        boolean newMuted = packet.get("mute").asBoolean();
        boolean oldMuted = server.isMuted(userId);
        if (newMuted != oldMuted) {
            server.setMuted(userId, newMuted);
            UserChangeMutedEventImpl event = new UserChangeMutedEventImpl(newMember, oldMember);
            api.getEventDispatcher().dispatchUserChangeMutedEvent(server, server, newMember.getUser(), event);
        }
        boolean newDeafened = packet.get("deaf").asBoolean();
        boolean oldDeafened = server.isDeafened(userId);
        if (newDeafened != oldDeafened) {
            server.setDeafened(userId, newDeafened);
            UserChangeDeafenedEventImpl event = new UserChangeDeafenedEventImpl(newMember, oldMember);
            api.getEventDispatcher().dispatchUserChangeDeafenedEvent(server, server, newMember.getUser(), event);
        }
    });
}
Also used : UserChangeSelfDeafenedEventImpl(org.javacord.core.event.user.UserChangeSelfDeafenedEventImpl) MemberImpl(org.javacord.core.entity.user.MemberImpl) UserChangeSelfMutedEventImpl(org.javacord.core.event.user.UserChangeSelfMutedEventImpl) UserChangeMutedEventImpl(org.javacord.core.event.user.UserChangeMutedEventImpl) Member(org.javacord.core.entity.user.Member) ServerVoiceChannelImpl(org.javacord.core.entity.channel.ServerVoiceChannelImpl) UserChangeDeafenedEventImpl(org.javacord.core.event.user.UserChangeDeafenedEventImpl)

Aggregations

MemberImpl (org.javacord.core.entity.user.MemberImpl)10 ServerImpl (org.javacord.core.entity.server.ServerImpl)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 UserImpl (org.javacord.core.entity.user.UserImpl)6 DiscordApi (org.javacord.api.DiscordApi)5 User (org.javacord.api.entity.user.User)5 PacketHandler (org.javacord.core.util.gateway.PacketHandler)5 Member (org.javacord.core.entity.user.Member)3 TextChannel (org.javacord.api.entity.channel.TextChannel)2 DispatchQueueSelector (org.javacord.core.util.event.DispatchQueueSelector)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Logger (org.apache.logging.log4j.Logger)1 ServerTextChannel (org.javacord.api.entity.channel.ServerTextChannel)1