Search in sources :

Example 1 with RoleDeleteListener

use of de.btobastian.javacord.listener.role.RoleDeleteListener in project Javacord by BtoBastian.

the class GuildRoleDeleteHandler method handle.

@Override
public void handle(JSONObject packet) {
    String guildId = packet.getString("guild_id");
    String roleId = packet.getString("role_id");
    Server server = api.getServerById(guildId);
    final Role role = server.getRoleById(roleId);
    if (role == null) {
        return;
    }
    ((ImplServer) server).removeRole(role);
    listenerExecutorService.submit(new Runnable() {

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

Aggregations

Server (de.btobastian.javacord.entities.Server)1 ImplServer (de.btobastian.javacord.entities.impl.ImplServer)1 Role (de.btobastian.javacord.entities.permissions.Role)1 RoleDeleteListener (de.btobastian.javacord.listener.role.RoleDeleteListener)1 List (java.util.List)1