use of de.btobastian.javacord.listener.server.ServerJoinListener in project Javacord by BtoBastian.
the class GuildCreateHandler method handle.
@Override
public void handle(JSONObject packet) {
if (packet.has("unavailable") && packet.getBoolean("unavailable")) {
return;
}
String id = packet.getString("id");
if (api.getUnavailableServers().contains(id)) {
api.getUnavailableServers().remove(id);
new ImplServer(packet, api);
return;
}
if (api.getServerById(id) != null) {
// TODO update information
return;
}
final Server server = new ImplServer(packet, api);
listenerExecutorService.submit(new Runnable() {
@Override
public void run() {
List<ServerJoinListener> listeners = api.getListeners(ServerJoinListener.class);
synchronized (listeners) {
for (ServerJoinListener listener : listeners) {
try {
listener.onServerJoin(api, server);
} catch (Throwable t) {
logger.warn("Uncaught exception in ServerJoinListener!", t);
}
}
}
}
});
api.getThreadPool().getExecutorService().submit(new Runnable() {
@Override
public void run() {
// can cause a deadlock if someone blocks a listener
// with the #createServer or #acceptInvite method + #get
api.getInternalServerJoinListener().onServerJoin(api, server);
}
});
}
Aggregations