Search in sources :

Example 16 with ServerImpl

use of org.javacord.core.entity.server.ServerImpl in project Javacord by BtoBastian.

the class GuildCreateHandler method handle.

@Override
public void handle(JsonNode packet) {
    if (packet.has("unavailable") && packet.get("unavailable").asBoolean()) {
        return;
    }
    long id = packet.get("id").asLong();
    if (api.getUnavailableServers().contains(id)) {
        ServerImpl server = new ServerImpl(api, packet);
        ServerBecomesAvailableEvent event = new ServerBecomesAvailableEventImpl(server);
        api.getEventDispatcher().dispatchServerBecomesAvailableEvent(server, event);
        return;
    }
    ServerImpl server = new ServerImpl(api, packet);
    ServerJoinEvent event = new ServerJoinEventImpl(server);
    api.getEventDispatcher().dispatchServerJoinEvent(server, event);
}
Also used : ServerBecomesAvailableEvent(org.javacord.api.event.server.ServerBecomesAvailableEvent) ServerBecomesAvailableEventImpl(org.javacord.core.event.server.ServerBecomesAvailableEventImpl) ServerJoinEvent(org.javacord.api.event.server.ServerJoinEvent) ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerJoinEventImpl(org.javacord.core.event.server.ServerJoinEventImpl)

Example 17 with ServerImpl

use of org.javacord.core.entity.server.ServerImpl 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 18 with ServerImpl

use of org.javacord.core.entity.server.ServerImpl in project Javacord by BtoBastian.

the class ChannelCreateHandler method handleServerTextChannel.

/**
 * Handles server text channel creation.
 *
 * @param channel The channel data.
 */
private void handleServerTextChannel(JsonNode channel) {
    long serverId = channel.get("guild_id").asLong();
    api.getPossiblyUnreadyServerById(serverId).ifPresent(server -> {
        ServerTextChannel textChannel = ((ServerImpl) server).getOrCreateServerTextChannel(channel);
        ServerChannelCreateEvent event = new ServerChannelCreateEventImpl(textChannel);
        api.getEventDispatcher().dispatchServerChannelCreateEvent((DispatchQueueSelector) server, server, event);
    });
}
Also used : ServerTextChannel(org.javacord.api.entity.channel.ServerTextChannel) ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerChannelCreateEvent(org.javacord.api.event.channel.server.ServerChannelCreateEvent) ServerChannelCreateEventImpl(org.javacord.core.event.channel.server.ServerChannelCreateEventImpl)

Example 19 with ServerImpl

use of org.javacord.core.entity.server.ServerImpl in project Javacord by BtoBastian.

the class ChannelCreateHandler method handleServerStageVoiceChannel.

/**
 * Handles server stage voice channel creation.
 *
 * @param channel The channel data.
 */
private void handleServerStageVoiceChannel(JsonNode channel) {
    long serverId = channel.get("guild_id").asLong();
    api.getPossiblyUnreadyServerById(serverId).ifPresent(server -> {
        ServerStageVoiceChannel voiceChannel = ((ServerImpl) server).getOrCreateServerStageVoiceChannel(channel);
        ServerChannelCreateEvent event = new ServerChannelCreateEventImpl(voiceChannel);
        api.getEventDispatcher().dispatchServerChannelCreateEvent((DispatchQueueSelector) server, server, event);
    });
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) ServerChannelCreateEvent(org.javacord.api.event.channel.server.ServerChannelCreateEvent) ServerStageVoiceChannel(org.javacord.api.entity.channel.ServerStageVoiceChannel) ServerChannelCreateEventImpl(org.javacord.core.event.channel.server.ServerChannelCreateEventImpl)

Example 20 with ServerImpl

use of org.javacord.core.entity.server.ServerImpl in project Javacord by BtoBastian.

the class ChannelUpdateHandler method handleServerChannel.

/**
 * Handles a server channel update.
 *
 * @param jsonChannel The channel data.
 */
private void handleServerChannel(JsonNode jsonChannel) {
    long channelId = jsonChannel.get("id").asLong();
    long guildId = jsonChannel.get("guild_id").asLong();
    ServerImpl server = api.getPossiblyUnreadyServerById(guildId).map(ServerImpl.class::cast).orElse(null);
    if (server == null) {
        return;
    }
    ServerChannelImpl channel = server.getChannelById(channelId).map(ServerChannelImpl.class::cast).orElse(null);
    if (channel == null) {
        return;
    }
    String oldName = channel.getName();
    String newName = jsonChannel.get("name").asText();
    if (!Objects.deepEquals(oldName, newName)) {
        channel.setName(newName);
        ServerChannelChangeNameEvent event = new ServerChannelChangeNameEventImpl(channel, newName, oldName);
        if (server.isReady()) {
            api.getEventDispatcher().dispatchServerChannelChangeNameEvent((DispatchQueueSelector) channel.getServer(), channel.getServer(), channel, event);
        }
    }
}
Also used : ServerImpl(org.javacord.core.entity.server.ServerImpl) RegularServerChannelImpl(org.javacord.core.entity.channel.RegularServerChannelImpl) ServerChannelImpl(org.javacord.core.entity.channel.ServerChannelImpl) ServerChannelChangeNameEvent(org.javacord.api.event.channel.server.ServerChannelChangeNameEvent) ServerChannelChangeNameEventImpl(org.javacord.core.event.channel.server.ServerChannelChangeNameEventImpl)

Aggregations

ServerImpl (org.javacord.core.entity.server.ServerImpl)25 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 DiscordApi (org.javacord.api.DiscordApi)9 PacketHandler (org.javacord.core.util.gateway.PacketHandler)9 MemberImpl (org.javacord.core.entity.user.MemberImpl)8 UserImpl (org.javacord.core.entity.user.UserImpl)7 User (org.javacord.api.entity.user.User)6 ArrayList (java.util.ArrayList)5 Objects (java.util.Objects)4 Role (org.javacord.api.entity.permission.Role)4 ServerChannelCreateEvent (org.javacord.api.event.channel.server.ServerChannelCreateEvent)4 ServerChannelCreateEventImpl (org.javacord.core.event.channel.server.ServerChannelCreateEventImpl)4 Collection (java.util.Collection)3 Set (java.util.Set)3 ServerTextChannel (org.javacord.api.entity.channel.ServerTextChannel)3 TextChannel (org.javacord.api.entity.channel.TextChannel)3 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2