Search in sources :

Example 1 with ServerJoinListener

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);
        }
    });
}
Also used : ServerJoinListener(de.btobastian.javacord.listener.server.ServerJoinListener) ImplServer(de.btobastian.javacord.entities.impl.ImplServer) Server(de.btobastian.javacord.entities.Server) ImplServer(de.btobastian.javacord.entities.impl.ImplServer) List(java.util.List)

Aggregations

Server (de.btobastian.javacord.entities.Server)1 ImplServer (de.btobastian.javacord.entities.impl.ImplServer)1 ServerJoinListener (de.btobastian.javacord.listener.server.ServerJoinListener)1 List (java.util.List)1