use of de.btobastian.javacord.entities.impl.ImplServer in project Javacord by BtoBastian.
the class GuildBanRemoveHandler 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);
listenerExecutorService.submit(new Runnable() {
@Override
public void run() {
List<ServerMemberUnbanListener> listeners = api.getListeners(ServerMemberUnbanListener.class);
synchronized (listeners) {
for (ServerMemberUnbanListener listener : listeners) {
try {
listener.onServerMemberUnban(api, user.getId(), server);
} catch (Throwable t) {
logger.warn("Uncaught exception in ServerMemberUnbanListener!", t);
}
}
}
}
});
}
}
use of de.btobastian.javacord.entities.impl.ImplServer 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);
}
});
}
use of de.btobastian.javacord.entities.impl.ImplServer 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);
}
}
}
}
});
}
}
use of de.btobastian.javacord.entities.impl.ImplServer 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);
}
}
}
}
});
}
}
use of de.btobastian.javacord.entities.impl.ImplServer in project Javacord by BtoBastian.
the class GuildUpdateHandler method handle.
@Override
public void handle(JSONObject packet) {
if (packet.has("unavailable") && packet.getBoolean("unavailable")) {
return;
}
final ImplServer server = (ImplServer) api.getServerById(packet.getString("id"));
String name = packet.getString("name");
if (!server.getName().equals(name)) {
final String oldName = server.getName();
server.setName(name);
listenerExecutorService.submit(new Runnable() {
@Override
public void run() {
List<ServerChangeNameListener> listeners = api.getListeners(ServerChangeNameListener.class);
synchronized (listeners) {
for (ServerChangeNameListener listener : listeners) {
try {
listener.onServerChangeName(api, server, oldName);
} catch (Throwable t) {
logger.warn("Uncaught exception in ServerChangeNameListener!", t);
}
}
}
}
});
}
Region region = Region.getRegionByKey(packet.getString("region"));
if (server.getRegion() != region) {
final Region oldRegion = server.getRegion();
server.setRegion(region);
listenerExecutorService.submit(new Runnable() {
@Override
public void run() {
List<ServerChangeRegionListener> listeners = api.getListeners(ServerChangeRegionListener.class);
synchronized (listeners) {
for (ServerChangeRegionListener listener : listeners) {
try {
listener.onServerChangeRegion(api, server, oldRegion);
} catch (Throwable t) {
logger.warn("Uncaught exception in ServerChangeRegionListener!", t);
}
}
}
}
});
}
String ownerId = packet.getString("owner_id");
if (!server.getOwnerId().equals(ownerId)) {
final String oldOwnerId = server.getOwnerId();
server.setOwnerId(ownerId);
listenerExecutorService.submit(new Runnable() {
@Override
public void run() {
List<ServerChangeOwnerListener> listeners = api.getListeners(ServerChangeOwnerListener.class);
synchronized (listeners) {
for (ServerChangeOwnerListener listener : listeners) {
try {
listener.onServerChangeOwner(api, server, oldOwnerId);
} catch (Throwable t) {
logger.warn("Uncaught exception in ServerChangeOwnerListener!", t);
}
}
}
}
});
}
String icon = packet.isNull("icon") ? null : packet.getString("icon");
if (server.getIconHash() != null && !server.getIconHash().equals(icon)) {
final String oldIcon = server.getIconHash();
server.setIconHash(icon);
listenerExecutorService.submit(new Runnable() {
@Override
public void run() {
List<ServerChangeIconListener> listeners = api.getListeners(ServerChangeIconListener.class);
synchronized (listeners) {
for (ServerChangeIconListener listener : listeners) {
try {
listener.onServerChangeIcon(api, server, oldIcon);
} catch (Throwable t) {
logger.warn("Uncaught exception in ServerChangeIconListener!", t);
}
}
}
}
});
} else if (server.getIconHash() == null && server.getIconHash() != icon) {
final String oldIcon = server.getIconHash();
server.setIconHash(icon);
listenerExecutorService.submit(new Runnable() {
@Override
public void run() {
List<ServerChangeIconListener> listeners = api.getListeners(ServerChangeIconListener.class);
synchronized (listeners) {
for (ServerChangeIconListener listener : listeners) {
try {
listener.onServerChangeIcon(api, server, oldIcon);
} catch (Throwable t) {
logger.warn("Uncaught exception in ServerChangeIconListener!", t);
}
}
}
}
});
}
}
Aggregations