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);
}
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);
});
}
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);
});
}
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);
});
}
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);
}
}
}
Aggregations