net.dv8tion.jda.api.events.guild.GuildBanEvent Java Examples

The following examples show how to use net.dv8tion.jda.api.events.guild.GuildBanEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GuildListener.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onEvent(@Nonnull GenericEvent event) {
    if (event instanceof GuildJoinEvent) {
        this.onGuildJoin((GuildJoinEvent) event);
    } else if (event instanceof GuildLeaveEvent) {
        this.onGuildLeave((GuildLeaveEvent) event);
    } else if (event instanceof GuildVoiceLeaveEvent) {
        this.onGuildVoiceLeave((GuildVoiceLeaveEvent) event);
    } else if (event instanceof GuildVoiceJoinEvent) {
        this.onGuildVoiceJoin((GuildVoiceJoinEvent) event);
    } else if (event instanceof GuildVoiceMoveEvent) {
        this.onGuildVoiceMove((GuildVoiceMoveEvent) event);
    } else if (event instanceof GuildBanEvent) {
        this.onGuildBan((GuildBanEvent) event);
    } else if (event instanceof GuildUnbanEvent) {
        this.onGuildUnban((GuildUnbanEvent) event);
    }
}
 
Example #2
Source File: MantaroListener.java    From MantaroBot with GNU General Public License v3.0 6 votes vote down vote up
private void logBan(GuildBanEvent event) {
    String hour = df.format(new Date(System.currentTimeMillis()));
    GuildData data = MantaroData.db().getGuild(event.getGuild()).getData();
    String logChannel = data.getGuildLogChannel();
    if (logChannel != null) {
        TextChannel tc = event.getGuild().getTextChannelById(logChannel);
        if (tc != null) {
            String message;
            if (data.getBannedMemberLog() != null) {
                message = new DynamicModifiers()
                        .set("hour", hour)
                        .mapEvent("event", event)
                        .mapUser("event.user", event.getUser())
                        .resolve(data.getBannedMemberLog());
            } else {
                message = EmoteReference.WARNING + "`[" + hour + "]` " + event.getUser().getName() + "#" + event.getUser().getDiscriminator() + " just got banned.";
            }
            tc.sendMessage(message).queue();
            logTotal++;
        }
    }
}
 
Example #3
Source File: DiscordBanListener.java    From DiscordSRV with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onGuildBan(GuildBanEvent event) {
    UUID linkedUuid = DiscordSRV.getPlugin().getAccountLinkManager().getUuid(event.getUser().getId());
    if (linkedUuid == null) {
        DiscordSRV.debug("Not handling ban for user " + event.getUser() + " because they didn't have a linked account");
        return;
    }

    OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(linkedUuid);
    if (!offlinePlayer.hasPlayedBefore()) return;

    if (!DiscordSRV.config().getBoolean("BanSynchronizationDiscordToMinecraft")) {
        DiscordSRV.debug("Not handling ban for user " + event.getUser() + " because doing so is disabled in the config");
        return;
    }

    Bukkit.getBanList(BanList.Type.NAME).addBan(offlinePlayer.getName(), LangUtil.Message.BAN_DISCORD_TO_MINECRAFT.toString(), null, "Discord");
}
 
Example #4
Source File: GuildBanHandler.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Override
protected Long handleInternally(DataObject content)
{
    final long id = content.getLong("guild_id");
    if (getJDA().getGuildSetupController().isLocked(id))
        return id;

    DataObject userJson = content.getObject("user");
    GuildImpl guild = (GuildImpl) getJDA().getGuildById(id);
    if (guild == null)
    {
        getJDA().getEventCache().cache(EventCache.Type.GUILD, id, responseNumber, allContent, this::handle);
        EventCache.LOG.debug("Received Guild Member {} event for a Guild not yet cached.", JDALogger.getLazyString(() -> banned ? "Ban" : "Unban"));
        return null;
    }

    User user = getJDA().getEntityBuilder().createFakeUser(userJson);

    if (banned)
    {
        getJDA().handleEvent(
                new GuildBanEvent(
                        getJDA(), responseNumber,
                        guild, user));
    }
    else
    {
        getJDA().handleEvent(
                new GuildUnbanEvent(
                        getJDA(), responseNumber,
                        guild, user));
    }
    return null;
}
 
Example #5
Source File: GuildListener.java    From SkyBot with GNU Affero General Public License v3.0 4 votes vote down vote up
private void onGuildBan(GuildBanEvent event) {
    modLogBanUnban(ActionType.BAN, event.getUser(), event.getGuild());
}
 
Example #6
Source File: PunishmentListener.java    From Arraybot with Apache License 2.0 4 votes vote down vote up
/**
 * When a member is banned.
 * @param event The event.
 */
@Override
public void onGuildBan(@NotNull GuildBanEvent event) {
    handlePunishment(event, event.getUser(), PunishmentType.BAN, null, false);
}