Search in sources :

Example 1 with ServerMemberRemoveListener

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

the class GuildMemberRemoveHandler 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).removeMember(user);
        ((ImplServer) server).decrementMemberCount();
        listenerExecutorService.submit(new Runnable() {

            @Override
            public void run() {
                List<ServerMemberRemoveListener> listeners = api.getListeners(ServerMemberRemoveListener.class);
                synchronized (listeners) {
                    for (ServerMemberRemoveListener listener : listeners) {
                        try {
                            listener.onServerMemberRemove(api, user, server);
                        } catch (Throwable t) {
                            logger.warn("Uncaught exception in ServerMemberRemoveListener!", 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) ServerMemberRemoveListener(de.btobastian.javacord.listener.server.ServerMemberRemoveListener)

Aggregations

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