net.dv8tion.jda.api.utils.cache.CacheFlag Java Examples
The following examples show how to use
net.dv8tion.jda.api.utils.cache.CacheFlag.
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: AudioEchoExample.java From JDA with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws LoginException { if (args.length == 0) { System.err.println("Unable to start without token!"); System.exit(1); } String token = args[0]; // We only need 2 gateway intents enabled for this example: EnumSet<GatewayIntent> intents = EnumSet.of( // We need messages in guilds to accept commands from users GatewayIntent.GUILD_MESSAGES, // We need voice states to connect to the voice channel GatewayIntent.GUILD_VOICE_STATES ); // Start the JDA session with light mode (minimal cache) JDABuilder.createLight(token, intents) // Use provided token from command line arguments .addEventListeners(new AudioEchoExample()) // Start listening with this listener .setActivity(Activity.listening("to jams")) // Inform users that we are jammin' it out .setStatus(OnlineStatus.DO_NOT_DISTURB) // Please don't disturb us while we're jammin' .enableCache(CacheFlag.VOICE_STATE) // Enable the VOICE_STATE cache to find a user's connected voice channel .build(); // Login with these options }
Example #2
Source File: EntityBuilder.java From JDA with Apache License 2.0 | 6 votes |
@Nullable public PermissionOverride createPermissionOverride(DataObject override, AbstractChannelImpl<?, ?> chan) { String type = override.getString("type"); final long id = override.getLong("id"); boolean role = type.equals("role"); if (role && chan.getGuild().getRoleById(id) == null) throw new NoSuchElementException("Attempted to create a PermissionOverride for a non-existent role! JSON: " + override); if (!role && !type.equals("member")) throw new IllegalArgumentException("Provided with an unknown PermissionOverride type! JSON: " + override); if (!role && id != api.getSelfUser().getIdLong() && !api.isCacheFlagSet(CacheFlag.MEMBER_OVERRIDES)) return null; long allow = override.getLong("allow"); long deny = override.getLong("deny"); PermissionOverrideImpl permOverride = (PermissionOverrideImpl) chan.getOverrideMap().get(id); if (permOverride == null) { permOverride = new PermissionOverrideImpl(chan, id, role); chan.getOverrideMap().put(id, permOverride); } return permOverride.setAllow(allow).setDeny(deny); }
Example #3
Source File: EntityBuilder.java From JDA with Apache License 2.0 | 6 votes |
private void createGuildEmotePass(GuildImpl guildObj, DataArray array) { if (!getJDA().isCacheFlagSet(CacheFlag.EMOTE)) return; SnowflakeCacheViewImpl<Emote> emoteView = guildObj.getEmotesView(); try (UnlockHook hook = emoteView.writeLock()) { TLongObjectMap<Emote> emoteMap = emoteView.getMap(); for (int i = 0; i < array.length(); i++) { DataObject object = array.getObject(i); if (object.isNull("id")) { LOG.error("Received GUILD_CREATE with an emoji with a null ID. JSON: {}", object); continue; } final long emoteId = object.getLong("id"); emoteMap.put(emoteId, createEmote(guildObj, object, false)); } } }
Example #4
Source File: DefaultShardManagerBuilder.java From JDA with Apache License 2.0 | 5 votes |
private DefaultShardManagerBuilder applyIntents() { EnumSet<CacheFlag> disabledCache = EnumSet.allOf(CacheFlag.class); for (CacheFlag flag : CacheFlag.values()) { GatewayIntent requiredIntent = flag.getRequiredIntent(); if (requiredIntent == null || (requiredIntent.getRawValue() & intents) != 0) disabledCache.remove(flag); } boolean enableMembers = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0; return setChunkingFilter(enableMembers ? ChunkingFilter.ALL : ChunkingFilter.NONE) .setMemberCachePolicy(enableMembers ? MemberCachePolicy.ALL : MemberCachePolicy.DEFAULT) .setDisabledCache(disabledCache); }
Example #5
Source File: DefaultShardManagerBuilder.java From JDA with Apache License 2.0 | 5 votes |
private DefaultShardManagerBuilder applyLight() { return this.setMemberCachePolicy(MemberCachePolicy.NONE) .setChunkingFilter(ChunkingFilter.NONE) .disableCache(EnumSet.allOf(CacheFlag.class)) .setLargeThreshold(50); }
Example #6
Source File: DefaultShardManagerBuilder.java From JDA with Apache License 2.0 | 5 votes |
private DefaultShardManagerBuilder applyDefault() { return this.setMemberCachePolicy(MemberCachePolicy.DEFAULT) .setChunkingFilter(ChunkingFilter.NONE) .disableCache(CacheFlag.CLIENT_STATUS, CacheFlag.ACTIVITY) .setLargeThreshold(250); }
Example #7
Source File: MemberImpl.java From JDA with Apache License 2.0 | 5 votes |
public MemberImpl(GuildImpl guild, User user) { this.api = (JDAImpl) user.getJDA(); this.guild = new SnowflakeReference<>(guild, api::getGuildById); this.user = user; this.joinDate = 0; boolean cacheState = api.isCacheFlagSet(CacheFlag.VOICE_STATE) || user.equals(api.getSelfUser()); boolean cacheOnline = api.isCacheFlagSet(CacheFlag.CLIENT_STATUS); this.voiceState = cacheState ? new GuildVoiceStateImpl(this) : null; this.clientStatus = cacheOnline ? Collections.synchronizedMap(new EnumMap<>(ClientType.class)) : null; }
Example #8
Source File: ShardingMetaConfig.java From JDA with Apache License 2.0 | 5 votes |
public ShardingMetaConfig( int maxBufferSize, @Nullable IntFunction<? extends ConcurrentMap<String, String>> contextProvider, @Nullable EnumSet<CacheFlag> cacheFlags, EnumSet<ConfigFlag> flags, Compression compression) { super(maxBufferSize, null, cacheFlags, flags); this.compression = compression; this.contextProvider = contextProvider; }
Example #9
Source File: MetaConfig.java From JDA with Apache License 2.0 | 5 votes |
public MetaConfig( int maxBufferSize, @Nullable ConcurrentMap<String, String> mdcContextMap, @Nullable EnumSet<CacheFlag> cacheFlags, EnumSet<ConfigFlag> flags) { this.maxBufferSize = maxBufferSize; this.cacheFlags = cacheFlags == null ? EnumSet.allOf(CacheFlag.class) : cacheFlags; this.enableMDC = flags.contains(ConfigFlag.MDC_CONTEXT); if (enableMDC) this.mdcContextMap = mdcContextMap == null ? new ConcurrentHashMap<>() : null; else this.mdcContextMap = null; this.useShutdownHook = flags.contains(ConfigFlag.SHUTDOWN_HOOK); }
Example #10
Source File: DefaultShardManagerBuilder.java From JDA with Apache License 2.0 | 5 votes |
private void checkIntents() { boolean membersIntent = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0; if (!membersIntent && memberCachePolicy == MemberCachePolicy.ALL) throw new IllegalStateException("Cannot use MemberCachePolicy.ALL without GatewayIntent.GUILD_MEMBERS enabled!"); else if (!membersIntent && chunkingFilter != ChunkingFilter.NONE) DefaultShardManager.LOG.warn("Member chunking is disabled due to missing GUILD_MEMBERS intent."); if (!automaticallyDisabled.isEmpty()) { JDAImpl.LOG.warn("Automatically disabled CacheFlags due to missing intents"); // List each missing intent automaticallyDisabled.stream() .map(it -> "Disabled CacheFlag." + it + " (missing GatewayIntent." + it.getRequiredIntent() + ")") .forEach(JDAImpl.LOG::warn); // Tell user how to disable this warning JDAImpl.LOG.warn("You can manually disable these flags to remove this warning by using disableCache({}) on your DefaultShardManagerBuilder", automaticallyDisabled.stream() .map(it -> "CacheFlag." + it) .collect(Collectors.joining(", "))); // Only print this warning once automaticallyDisabled.clear(); } if (cacheFlags.isEmpty()) return; EnumSet<GatewayIntent> providedIntents = GatewayIntent.getIntents(intents); for (CacheFlag flag : cacheFlags) { GatewayIntent intent = flag.getRequiredIntent(); if (intent != null && !providedIntents.contains(intent)) throw new IllegalArgumentException("Cannot use CacheFlag." + flag + " without GatewayIntent." + intent + "!"); } }
Example #11
Source File: JDABuilder.java From JDA with Apache License 2.0 | 5 votes |
private JDABuilder applyDefault() { return this.setMemberCachePolicy(MemberCachePolicy.DEFAULT) .setChunkingFilter(ChunkingFilter.NONE) .disableCache(CacheFlag.CLIENT_STATUS, CacheFlag.ACTIVITY) .setLargeThreshold(250); }
Example #12
Source File: JDABuilder.java From JDA with Apache License 2.0 | 5 votes |
private JDABuilder applyLight() { return this.setMemberCachePolicy(MemberCachePolicy.NONE) .setChunkingFilter(ChunkingFilter.NONE) .disableCache(EnumSet.allOf(CacheFlag.class)) .setLargeThreshold(50); }
Example #13
Source File: JDABuilder.java From JDA with Apache License 2.0 | 5 votes |
private JDABuilder applyIntents() { EnumSet<CacheFlag> disabledCache = EnumSet.allOf(CacheFlag.class); for (CacheFlag flag : CacheFlag.values()) { GatewayIntent requiredIntent = flag.getRequiredIntent(); if (requiredIntent == null || (requiredIntent.getRawValue() & intents) != 0) disabledCache.remove(flag); } boolean enableMembers = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0; return setChunkingFilter(enableMembers ? ChunkingFilter.ALL : ChunkingFilter.NONE) .setMemberCachePolicy(enableMembers ? MemberCachePolicy.ALL : MemberCachePolicy.DEFAULT) .setDisabledCache(disabledCache); }
Example #14
Source File: JDABuilder.java From JDA with Apache License 2.0 | 5 votes |
private void checkIntents() { boolean membersIntent = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0; if (!membersIntent && memberCachePolicy == MemberCachePolicy.ALL) throw new IllegalStateException("Cannot use MemberCachePolicy.ALL without GatewayIntent.GUILD_MEMBERS enabled!"); else if (!membersIntent && chunkingFilter != ChunkingFilter.NONE) JDAImpl.LOG.warn("Member chunking is disabled due to missing GUILD_MEMBERS intent."); if (!automaticallyDisabled.isEmpty()) { JDAImpl.LOG.warn("Automatically disabled CacheFlags due to missing intents"); // List each missing intent automaticallyDisabled.stream() .map(it -> "Disabled CacheFlag." + it + " (missing GatewayIntent." + it.getRequiredIntent() + ")") .forEach(JDAImpl.LOG::warn); // Tell user how to disable this warning JDAImpl.LOG.warn("You can manually disable these flags to remove this warning by using disableCache({}) on your JDABuilder", automaticallyDisabled.stream() .map(it -> "CacheFlag." + it) .collect(Collectors.joining(", "))); // Only print this warning once automaticallyDisabled.clear(); } if (cacheFlags.isEmpty()) return; EnumSet<GatewayIntent> providedIntents = GatewayIntent.getIntents(intents); for (CacheFlag flag : cacheFlags) { GatewayIntent intent = flag.getRequiredIntent(); if (intent != null && !providedIntents.contains(intent)) throw new IllegalArgumentException("Cannot use CacheFlag." + flag + " without GatewayIntent." + intent + "!"); } }
Example #15
Source File: SkyBot.java From SkyBot with GNU Affero General Public License v3.0 | 4 votes |
private SkyBot() throws Exception { // Set our animated emotes as default reactions MessageUtils.setErrorReaction("a:_no:577795484060483584"); MessageUtils.setSuccessReaction("a:_yes:577795293546938369"); // Load in our container final Variables variables = new Variables(); final DunctebotConfig config = variables.getConfig(); final CommandManager commandManager = variables.getCommandManager(); final Logger logger = LoggerFactory.getLogger(SkyBot.class); // Set the user-agent of the bot WebUtils.setUserAgent("Mozilla/5.0 (compatible; SkyBot/" + Settings.VERSION + "; +https://dunctebot.com;)"); EmbedUtils.setEmbedBuilder( () -> new EmbedBuilder() .setColor(Settings.DEFAULT_COLOUR) // .setFooter("DuncteBot", Settings.DEFAULT_ICON) // .setTimestamp(Instant.now()) ); Settings.PREFIX = config.discord.prefix; // Set some defaults for rest-actions RestAction.setPassContext(true); RestAction.setDefaultFailure(ignore(UNKNOWN_MESSAGE)); // If any rest-action doesn't get executed within 2 minutes we will mark it as failed RestAction.setDefaultTimeout(2L, TimeUnit.MINUTES); if (variables.useApi()) { logger.info(TextColor.GREEN + "Using api for all connections" + TextColor.RESET); } else { logger.warn("Using SQLite as the database"); logger.warn("Please note that is is not recommended for production"); } //Load the settings before loading the bot GuildSettingsUtils.loadAllSettings(variables); //Set the token to a string final String token = config.discord.token; //But this time we are going to shard it final int totalShards = config.discord.totalShards; this.activityProvider = (shardId) -> Activity.playing( config.discord.prefix + "help | Shard " + (shardId + 1) ); final LongLongPair commandCount = commandManager.getCommandCount(); logger.info("{} commands with {} aliases loaded.", commandCount.getFirst(), commandCount.getSecond()); LavalinkManager.ins.start(config, variables.getAudioUtils()); final EventManager eventManager = new EventManager(variables); // Build our shard manager final DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.create( GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.GUILD_MESSAGES ) .setToken(token) .setShardsTotal(totalShards) .setActivityProvider(this.activityProvider) .setBulkDeleteSplittingEnabled(false) .setEventManagerProvider((id) -> eventManager) // Keep guild owners, voice members and patrons in cache .setMemberCachePolicy(MemberCachePolicy.DEFAULT.or(PATRON_POLICY)) // .setMemberCachePolicy(MemberCachePolicy.NONE) // Enable lazy loading .setChunkingFilter(ChunkingFilter.NONE) // Enable lazy loading for guilds other than our own // .setChunkingFilter((guildId) -> guildId == Settings.SUPPORT_GUILD_ID) .enableCache(CacheFlag.VOICE_STATE, CacheFlag.EMOTE, CacheFlag.MEMBER_OVERRIDES) .disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS) .setHttpClientBuilder( new OkHttpClient.Builder() .connectTimeout(30L, TimeUnit.SECONDS) .readTimeout(30L, TimeUnit.SECONDS) .writeTimeout(30L, TimeUnit.SECONDS) ); this.startGameTimer(); // If lavalink is enabled we will hook it into jda if (LavalinkManager.ins.isEnabled()) { builder.setVoiceDispatchInterceptor(LavalinkManager.ins.getLavalink().getVoiceInterceptor()); } this.shardManager = builder.build(); HelpEmbeds.init(commandManager); // Load the web server if we are not running "locally" // TODO: change this config value to "web_server" or something if (!config.discord.local) { webRouter = new WebRouter(shardManager, variables); } }
Example #16
Source File: EntityBuilder.java From JDA with Apache License 2.0 | 4 votes |
public void createPresence(MemberImpl member, DataObject presenceJson) { if (member == null) throw new NullPointerException("Provided member was null!"); boolean cacheGame = getJDA().isCacheFlagSet(CacheFlag.ACTIVITY); boolean cacheStatus = getJDA().isCacheFlagSet(CacheFlag.CLIENT_STATUS); DataArray activityArray = !cacheGame || presenceJson.isNull("activities") ? null : presenceJson.getArray("activities"); DataObject clientStatusJson = !cacheStatus || presenceJson.isNull("client_status") ? null : presenceJson.getObject("client_status"); OnlineStatus onlineStatus = OnlineStatus.fromKey(presenceJson.getString("status")); List<Activity> activities = new ArrayList<>(); boolean parsedActivity = false; if (cacheGame && activityArray != null) { for (int i = 0; i < activityArray.length(); i++) { try { activities.add(createActivity(activityArray.getObject(i))); parsedActivity = true; } catch (Exception ex) { String userId; userId = member.getUser().getId(); if (LOG.isDebugEnabled()) LOG.warn("Encountered exception trying to parse a presence! UserId: {} JSON: {}", userId, activityArray, ex); else LOG.warn("Encountered exception trying to parse a presence! UserId: {} Message: {} Enable debug for details", userId, ex.getMessage()); } } } if (cacheGame && parsedActivity) member.setActivities(activities); member.setOnlineStatus(onlineStatus); if (clientStatusJson != null) { for (String key : clientStatusJson.keys()) { ClientType type = ClientType.fromKey(key); OnlineStatus status = OnlineStatus.fromKey(clientStatusJson.getString(key)); member.setOnlineStatus(type, status); } } }
Example #17
Source File: MetaConfig.java From JDA with Apache License 2.0 | 4 votes |
@Nonnull public EnumSet<CacheFlag> getCacheFlags() { return cacheFlags; }
Example #18
Source File: JDAImpl.java From JDA with Apache License 2.0 | 4 votes |
public boolean isCacheFlagSet(CacheFlag flag) { return metaConfig.getCacheFlags().contains(flag); }
Example #19
Source File: PresenceUpdateHandler.java From JDA with Apache License 2.0 | 4 votes |
@Override protected Long handleInternally(DataObject content) { // Ignore events for relationships, presences are guild only to us if (content.isNull("guild_id")) { log.debug("Received PRESENCE_UPDATE without guild_id. Ignoring event."); return null; } //Do a pre-check to see if this is for a Guild, and if it is, if the guild is currently locked or not cached. final long guildId = content.getLong("guild_id"); if (getJDA().getGuildSetupController().isLocked(guildId)) return guildId; GuildImpl guild = (GuildImpl) getJDA().getGuildById(guildId); if (guild == null) { getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle); EventCache.LOG.debug("Received a PRESENCE_UPDATE for a guild that is not yet cached! GuildId:{} UserId: {}", guildId, content.getObject("user").get("id")); return null; } DataObject jsonUser = content.getObject("user"); final long userId = jsonUser.getLong("id"); UserImpl user = (UserImpl) getJDA().getUsersView().get(userId); // The user is not yet known to us, maybe due to lazy loading. Try creating it. if (user == null) { // If this presence update doesn't have a user or the status is offline we ignore it if (jsonUser.isNull("username") || "offline".equals(content.get("status"))) return null; // We should have somewhat enough information to create this member, so lets do it! user = (UserImpl) createMember(content, guildId, guild, jsonUser).getUser(); } if (jsonUser.hasKey("username")) { // username implies this is an update to a user - fire events and update properties getJDA().getEntityBuilder().updateUser(user, jsonUser); } //Now that we've update the User's info, lets see if we need to set the specific Presence information. // This is stored in the Member objects. //We set the activities to null to prevent parsing if the cache was disabled final DataArray activityArray = !getJDA().isCacheFlagSet(CacheFlag.ACTIVITY) || content.isNull("activities") ? null : content.getArray("activities"); List<Activity> newActivities = new ArrayList<>(); boolean parsedActivity = parseActivities(userId, activityArray, newActivities); MemberImpl member = (MemberImpl) guild.getMember(user); //Create member from presence if not offline if (member == null) { if (jsonUser.isNull("username") || "offline".equals(content.get("status"))) { log.trace("Ignoring incomplete PRESENCE_UPDATE for member with id {} in guild with id {}", userId, guildId); return null; } member = createMember(content, guildId, guild, jsonUser); } if (getJDA().isCacheFlagSet(CacheFlag.CLIENT_STATUS) && !content.isNull("client_status")) handleClientStatus(content, member); // Check if activities changed if (parsedActivity) handleActivities(newActivities, member); //The member is already cached, so modify the presence values and fire events as needed. OnlineStatus status = OnlineStatus.fromKey(content.getString("status")); if (!member.getOnlineStatus().equals(status)) { OnlineStatus oldStatus = member.getOnlineStatus(); member.setOnlineStatus(status); getJDA().getEntityBuilder().updateMemberCache(member); getJDA().handleEvent( new UserUpdateOnlineStatusEvent( getJDA(), responseNumber, member, oldStatus)); } return null; }
Example #20
Source File: JDABuilder.java From JDA with Apache License 2.0 | 4 votes |
private JDABuilder setDisabledCache(EnumSet<CacheFlag> flags) { disableCache(flags); this.automaticallyDisabled.addAll(flags); return this; }
Example #21
Source File: DefaultShardManagerBuilder.java From JDA with Apache License 2.0 | 4 votes |
private DefaultShardManagerBuilder setDisabledCache(EnumSet<CacheFlag> flags) { this.disableCache(flags); this.automaticallyDisabled.addAll(flags); return this; }
Example #22
Source File: JDABuilder.java From JDA with Apache License 2.0 | 3 votes |
/** * Enable specific cache flags. * <br>This will not disable any currently set cache flags. * * @param flag * {@link CacheFlag} to enable * @param flags * Other flags to enable * * @throws IllegalArgumentException * If provided with null * * @return The JDABuilder instance. Useful for chaining. * * @see #enableCache(Collection) * @see #disableCache(CacheFlag, CacheFlag...) */ @Nonnull public JDABuilder enableCache(@Nonnull CacheFlag flag, @Nonnull CacheFlag... flags) { Checks.notNull(flag, "CacheFlag"); Checks.noneNull(flags, "CacheFlag"); cacheFlags.addAll(EnumSet.of(flag, flags)); return this; }
Example #23
Source File: JDABuilder.java From JDA with Apache License 2.0 | 3 votes |
/** * Flags used to disable parts of the JDA cache to reduce the runtime memory footprint. * <br>Shortcut for {@code setEnabledCacheFlags(EnumSet.complementOf(flags))} * * @param flags * EnumSet containing the flags for cache services that should be <b>disabled</b> * * @return The JDABuilder instance. Useful for chaining. * * @deprecated We add CacheFlags to the enum over time which will be disabled when using this method. * This introduces breaking changes due to the way the setter works. * You should use {@link #enableCache(Collection)} and {@link #disableCache(Collection)} instead, * to disable and enable cache flags without side-effects that may break in future versions. */ @Nonnull @Deprecated @ReplaceWith("enableCache(flags) and disableCache(flags)") @DeprecatedSince("4.2.0") public JDABuilder setDisabledCacheFlags(@Nullable EnumSet<CacheFlag> flags) { return setEnabledCacheFlags(flags == null ? EnumSet.allOf(CacheFlag.class) : EnumSet.complementOf(flags)); }
Example #24
Source File: JDABuilder.java From JDA with Apache License 2.0 | 3 votes |
/** * Disable specific cache flags. * <br>This will not enable any currently unset cache flags. * * @param flags * The {@link CacheFlag CacheFlags} to disable * * @throws IllegalArgumentException * If provided with null * * @return The JDABuilder instance. Useful for chaining. * * @see #disableCache(CacheFlag, CacheFlag...) * @see #enableCache(Collection) */ @Nonnull public JDABuilder disableCache(@Nonnull Collection<CacheFlag> flags) { Checks.noneNull(flags, "CacheFlags"); automaticallyDisabled.removeAll(flags); cacheFlags.removeAll(flags); return this; }
Example #25
Source File: JDABuilder.java From JDA with Apache License 2.0 | 3 votes |
/** * Disable specific cache flags. * <br>This will not enable any currently unset cache flags. * * @param flag * {@link CacheFlag} to disable * @param flags * Other flags to disable * * @throws IllegalArgumentException * If provided with null * * @return The JDABuilder instance. Useful for chaining. * * @see #disableCache(Collection) * @see #enableCache(CacheFlag, CacheFlag...) */ @Nonnull public JDABuilder disableCache(@Nonnull CacheFlag flag, @Nonnull CacheFlag... flags) { Checks.notNull(flag, "CacheFlag"); Checks.noneNull(flags, "CacheFlag"); return disableCache(EnumSet.of(flag, flags)); }
Example #26
Source File: JDABuilder.java From JDA with Apache License 2.0 | 3 votes |
/** * Enable specific cache flags. * <br>This will not disable any currently set cache flags. * * @param flags * The {@link CacheFlag CacheFlags} to enable * * @throws IllegalArgumentException * If provided with null * * @return The JDABuilder instance. Useful for chaining. * * @see #enableCache(CacheFlag, CacheFlag...) * @see #disableCache(Collection) */ @Nonnull public JDABuilder enableCache(@Nonnull Collection<CacheFlag> flags) { Checks.noneNull(flags, "CacheFlags"); cacheFlags.addAll(flags); return this; }
Example #27
Source File: JDABuilder.java From JDA with Apache License 2.0 | 3 votes |
/** * Flags used to enable selective parts of the JDA cache to reduce the runtime memory footprint. * <br><b>It is highly recommended to use {@link #setDisabledCacheFlags(EnumSet)} instead * for backwards compatibility</b>. We might add more flags in the future which you then effectively disable * when updating and not changing your setting here. * * @param flags * EnumSet containing the flags for cache services that should be <b>enabled</b> * * @return The JDABuilder instance. Useful for chaining. * * @see #setDisabledCacheFlags(EnumSet) * * @deprecated We add CacheFlags to the enum over time which will be disabled when using this method. * This introduces breaking changes due to the way the setter works. * You should use {@link #enableCache(Collection)} and {@link #disableCache(Collection)} instead, * to disable and enable cache flags without side-effects that may break in future versions. */ @Nonnull @Deprecated @ReplaceWith("enableCache(flags) and disableCache(flags)") @DeprecatedSince("4.2.0") public JDABuilder setEnabledCacheFlags(@Nullable EnumSet<CacheFlag> flags) { this.cacheFlags = flags == null ? EnumSet.noneOf(CacheFlag.class) : EnumSet.copyOf(flags); return this; }
Example #28
Source File: DefaultShardManagerBuilder.java From JDA with Apache License 2.0 | 3 votes |
/** * Disable specific cache flags. * <br>This will not enable any currently unset cache flags. * * @param flag * {@link CacheFlag} to disable * @param flags * Other flags to disable * * @throws IllegalArgumentException * If provided with null * * @return The DefaultShardManagerBuilder instance. Useful for chaining. * * @see #disableCache(Collection) * @see #enableCache(CacheFlag, CacheFlag...) */ @Nonnull public DefaultShardManagerBuilder disableCache(@Nonnull CacheFlag flag, @Nonnull CacheFlag... flags) { Checks.notNull(flag, "CacheFlag"); Checks.noneNull(flags, "CacheFlag"); return disableCache(EnumSet.of(flag, flags)); }
Example #29
Source File: DefaultShardManagerBuilder.java From JDA with Apache License 2.0 | 3 votes |
/** * Disable specific cache flags. * <br>This will not enable any currently unset cache flags. * * @param flags * The {@link CacheFlag CacheFlags} to disable * * @throws IllegalArgumentException * If provided with null * * @return The DefaultShardManagerBuilder instance. Useful for chaining. * * @see #disableCache(CacheFlag, CacheFlag...) * @see #enableCache(Collection) */ @Nonnull public DefaultShardManagerBuilder disableCache(@Nonnull Collection<CacheFlag> flags) { Checks.noneNull(flags, "CacheFlags"); automaticallyDisabled.removeAll(flags); cacheFlags.removeAll(flags); return this; }
Example #30
Source File: DefaultShardManagerBuilder.java From JDA with Apache License 2.0 | 3 votes |
/** * Flags used to disable parts of the JDA cache to reduce the runtime memory footprint. * <br>Shortcut for {@code setEnabledCacheFlags(EnumSet.complementOf(flags))} * * @param flags * EnumSet containing the flags for cache services that should be <b>disabled</b> * * @return The DefaultShardManagerBuilder instance. Useful for chaining. * * @deprecated We add CacheFlags to the enum over time which will be disabled when using this method. * This introduces breaking changes due to the way the setter works. * You should use {@link #enableCache(Collection)} and {@link #disableCache(Collection)} instead, * to disable and enable cache flags without side-effects that may break in future versions. */ @Nonnull @Deprecated @ReplaceWith("enableCache(flags) and disableCache(flags)") @DeprecatedSince("4.2.0") public DefaultShardManagerBuilder setDisabledCacheFlags(@Nullable EnumSet<CacheFlag> flags) { return setEnabledCacheFlags(flags == null ? EnumSet.allOf(CacheFlag.class) : EnumSet.complementOf(flags)); }