Search in sources :

Example 1 with ServerMemberAddListener

use of de.btobastian.javacord.listener.server.ServerMemberAddListener in project Javacord by BtoBastian.

the class GuildMemberAddHandler method handle.

@Override
public void handle(JSONObject packet) {
    final Server server = api.getServerById(packet.getString("guild_id"));
    final User user = api.getOrCreateUser(packet.getJSONObject("user"));
    if (server != null) {
        ((ImplServer) server).addMember(user);
        ((ImplServer) server).incrementMemberCount();
        listenerExecutorService.submit(new Runnable() {

            @Override
            public void run() {
                List<ServerMemberAddListener> listeners = api.getListeners(ServerMemberAddListener.class);
                synchronized (listeners) {
                    for (ServerMemberAddListener listener : listeners) {
                        try {
                            listener.onServerMemberAdd(api, user, server);
                        } catch (Throwable t) {
                            logger.warn("Uncaught exception in ServerMemberAddListener!", t);
                        }
                    }
                }
            }
        });
    }
}
Also used : User(de.btobastian.javacord.entities.User) ImplServer(de.btobastian.javacord.entities.impl.ImplServer) Server(de.btobastian.javacord.entities.Server) ImplServer(de.btobastian.javacord.entities.impl.ImplServer) List(java.util.List) ServerMemberAddListener(de.btobastian.javacord.listener.server.ServerMemberAddListener)

Aggregations

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