Search in sources :

Example 1 with RoleCreateListener

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

the class GuildRoleCreateHandler method handle.

@Override
public void handle(JSONObject packet) {
    String guildId = packet.getString("guild_id");
    JSONObject roleJson = packet.getJSONObject("role");
    Server server = api.getServerById(guildId);
    final Role role = new ImplRole(roleJson, (ImplServer) server, api);
    listenerExecutorService.submit(new Runnable() {

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

Aggregations

Server (de.btobastian.javacord.entities.Server)1 ImplServer (de.btobastian.javacord.entities.impl.ImplServer)1 Role (de.btobastian.javacord.entities.permissions.Role)1 ImplRole (de.btobastian.javacord.entities.permissions.impl.ImplRole)1 RoleCreateListener (de.btobastian.javacord.listener.role.RoleCreateListener)1 List (java.util.List)1 JSONObject (org.json.JSONObject)1