Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/main/java/net/dv8tion/jda/api/utils/cache/CacheView.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public interface CacheView<T> extends Iterable<T>
*
* @return {@link ClosableIterator} holding a read-lock on the data structure.
*
* @since 4.0.0
* @since 4.0.0
*/
@Nonnull
ClosableIterator<T> lockedIterator();
Expand All @@ -110,7 +110,7 @@ public interface CacheView<T> extends Iterable<T>
* @throws NullPointerException
* If provided with null
*
* @since 4.0.0
* @since 4.0.0
*/
default void forEachUnordered(@Nonnull final Consumer<? super T> action)
{
Expand Down Expand Up @@ -140,7 +140,7 @@ default void forEachUnordered(@Nonnull final Consumer<? super T> action)
*
* @return The resulting value after the action was performed
*
* @since 4.0.0
* @since 4.0.0
*
* @see #acceptStream(Consumer)
*/
Expand Down Expand Up @@ -174,7 +174,7 @@ default <R> R applyStream(@Nonnull Function<? super Stream<T>, ? extends R> acti
* @throws IllegalArgumentException
* If the action is null
*
* @since 4.0.0
* @since 4.0.0
*
* @see #applyStream(Function)
*/
Expand Down Expand Up @@ -449,9 +449,9 @@ static UnifiedMemberCacheView allMembers(@Nonnull Supplier<? extends Stream<? ex
*/
class SimpleCacheView<T> extends AbstractCacheView<T>
{
public SimpleCacheView(@Nonnull Class<T> type, @Nullable Function<T, String> nameMapper)
public SimpleCacheView(@Nonnull Class<T> type, @Nonnull T[] emptyArray, @Nullable Function<T, String> nameMapper)
{
super(type, nameMapper);
super(type, emptyArray, nameMapper);
}
}
}
74 changes: 40 additions & 34 deletions src/main/java/net/dv8tion/jda/internal/JDAImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ public class JDAImpl implements JDA
{
public static final Logger LOG = JDALogger.getLog(JDA.class);

protected final SnowflakeCacheViewImpl<User> userCache = new SnowflakeCacheViewImpl<>(User.class, User::getName);
protected final SnowflakeCacheViewImpl<Guild> guildCache = new SnowflakeCacheViewImpl<>(Guild.class, Guild::getName);
protected final SnowflakeCacheViewImpl<User> userCache = new SnowflakeCacheViewImpl<>(User.class, new User[0], User::getName);
protected final SnowflakeCacheViewImpl<Guild> guildCache = new SnowflakeCacheViewImpl<>(Guild.class, new Guild[0], Guild::getName);
protected final ChannelCacheViewImpl<Channel> channelCache = new ChannelCacheViewImpl<>(Channel.class);
protected final ArrayDeque<Long> privateChannelLRU = new ArrayDeque<>();

protected final AbstractCacheView<AudioManager> audioManagers = new CacheView.SimpleCacheView<>(AudioManager.class, m -> m.getGuild().getName());
protected final AbstractCacheView<AudioManager> audioManagers = new CacheView.SimpleCacheView<>(AudioManager.class, new AudioManager[0], m -> m.getGuild().getName());

protected final PresenceImpl presence;
protected final Thread shutdownHook;
Expand Down Expand Up @@ -139,7 +139,7 @@ public class JDAImpl implements JDA
protected String gatewayUrl;
protected ChunkingFilter chunkingFilter;

protected String clientId = null, requiredScopes = "bot";
protected String clientId = null, requiredScopes = "bot";
protected ShardManager shardManager = null;
protected MemberCachePolicy memberCachePolicy = MemberCachePolicy.ALL;

Expand Down Expand Up @@ -230,7 +230,7 @@ public boolean cacheMember(Member member)
try
{
return member.getUser().equals(getSelfUser()) // always cache self
|| memberCachePolicy.cacheMember(member); // ask policy, should we cache?
|| memberCachePolicy.cacheMember(member); // ask policy, should we cache?
}
catch (Exception e)
{
Expand Down Expand Up @@ -374,7 +374,8 @@ public void setToken(String token)

public void setStatus(Status status)
{
StatusChangeEvent event = MiscUtil.locked(statusLock, () -> {
StatusChangeEvent event = MiscUtil.locked(statusLock, () ->
{
Status oldStatus = this.status.getAndSet(status);
this.statusCondition.signalAll();

Expand Down Expand Up @@ -517,7 +518,7 @@ public JDA awaitStatus(@Nonnull Status status, @Nonnull Status... failOn) throws
EnumSet<Status> endCondition = EnumSet.of(status, failOn);
Status current = getStatus();
while (!current.isInit() // In case of disconnects during startup
|| current.ordinal() < status.ordinal()) // If we missed the status (e.g. LOGGING_IN -> CONNECTED happened while waiting for lock)
|| current.ordinal() < status.ordinal()) // If we missed the status (e.g. LOGGING_IN -> CONNECTED happened while waiting for lock)
{
if (current == Status.SHUTDOWN)
throw new IllegalStateException("Was shutdown trying to await status.\nReason: " + shutdownReason);
Expand Down Expand Up @@ -616,7 +617,7 @@ public List<Guild> getMutualGuilds(@Nonnull UserSnowflake... users)
public List<Guild> getMutualGuilds(@Nonnull Collection<? extends UserSnowflake> users)
{
Checks.notNull(users, "users");
for(UserSnowflake u : users)
for (UserSnowflake u : users)
Checks.notNull(u, "All users");
return getGuilds().stream()
.filter(guild -> users.stream().allMatch(guild::isMember))
Expand All @@ -629,7 +630,8 @@ public CacheRestAction<User> retrieveUserById(long id)
{
return new DeferredRestAction<>(this, User.class,
() -> isIntent(GatewayIntent.GUILD_MEMBERS) || isIntent(GatewayIntent.GUILD_PRESENCES) ? getUserById(id) : null,
() -> {
() ->
{
if (id == getSelfUser().getIdLong())
return new CompletedRestAction<>(this, getSelfUser());
Route.CompiledRoute route = Route.Users.GET_USER.compile(Long.toUnsignedString(id));
Expand Down Expand Up @@ -757,7 +759,7 @@ public RestAction<StickerUnion> retrieveSticker(@Nonnull StickerSnowflake sticke
Checks.notNull(sticker, "Sticker");
Route.CompiledRoute route = Route.Stickers.GET_STICKER.compile(sticker.getId());
return new RestActionImpl<>(this, route,
(response, request) -> entityBuilder.createRichSticker(response.getObject())
(response, request) -> entityBuilder.createRichSticker(response.getObject())
);
}

Expand Down Expand Up @@ -905,16 +907,18 @@ public CacheRestAction<PrivateChannel> openPrivateChannelById(long userId)
{
if (selfUser != null && userId == selfUser.getIdLong())
throw new UnsupportedOperationException("Cannot open private channel with yourself!");
return new DeferredRestAction<>(this, PrivateChannel.class, () -> {
return new DeferredRestAction<>(this, PrivateChannel.class, () ->
{
User user = getUserById(userId);
if (user instanceof UserImpl)
return ((UserImpl) user).getPrivateChannel();
return null;
}, () -> {
}, () ->
{
Route.CompiledRoute route = Route.Self.CREATE_PRIVATE_CHANNEL.compile();
DataObject body = DataObject.empty().put("recipient_id", userId);
return new RestActionImpl<>(this, route, body,
(response, request) -> getEntityBuilder().createPrivateChannel(response.getObject()));
(response, request) -> getEntityBuilder().createPrivateChannel(response.getObject()));
});
}

Expand Down Expand Up @@ -986,7 +990,9 @@ public void shutdownInternals(ShutdownEvent event)
{
Runtime.getRuntime().removeShutdownHook(shutdownHook);
}
catch (Exception ignored) {}
catch (Exception ignored)
{
}
}

// If the requester has been shutdown too, we can fire the shutdown event
Expand Down Expand Up @@ -1015,9 +1021,9 @@ private void signalShutdown()
private void closeAudioConnections()
{
getAudioManagerCache()
.stream()
.map(AudioManagerImpl.class::cast)
.forEach(m -> m.closeAudioConnection(ConnectionStatus.SHUTTING_DOWN));
.stream()
.map(AudioManagerImpl.class::cast)
.forEach(m -> m.closeAudioConnection(ConnectionStatus.SHUTTING_DOWN));
}

@Override
Expand Down Expand Up @@ -1064,7 +1070,7 @@ public void addEventListener(@Nonnull Object... listeners)
{
Checks.noneNull(listeners, "listeners");

for (Object listener: listeners)
for (Object listener : listeners)
eventManager.register(listener);
}

Expand All @@ -1073,7 +1079,7 @@ public void removeEventListener(@Nonnull Object... listeners)
{
Checks.noneNull(listeners, "listeners");

for (Object listener: listeners)
for (Object listener : listeners)
eventManager.unregister(listener);
}

Expand All @@ -1100,11 +1106,11 @@ public RestAction<List<Command>> retrieveCommands(boolean withLocalizations)
.withQueryParams("with_localizations", String.valueOf(withLocalizations));

return new RestActionImpl<>(this, route,
(response, request) ->
response.getArray()
.stream(DataArray::getObject)
.map(json -> new CommandImpl(this, null, json))
.collect(Collectors.toList()));
(response, request) ->
response.getArray()
.stream(DataArray::getObject)
.map(json -> new CommandImpl(this, null, json))
.collect(Collectors.toList()));
}

@Nonnull
Expand Down Expand Up @@ -1157,11 +1163,11 @@ public RestAction<List<RoleConnectionMetadata>> retrieveRoleConnectionMetadata()
{
Route.CompiledRoute route = Route.Applications.GET_ROLE_CONNECTION_METADATA.compile(getSelfUser().getApplicationId());
return new RestActionImpl<>(this, route,
(response, request) ->
response.getArray()
.stream(DataArray::getObject)
.map(RoleConnectionMetadata::fromData)
.collect(Helpers.toUnmodifiableList()));
(response, request) ->
response.getArray()
.stream(DataArray::getObject)
.map(RoleConnectionMetadata::fromData)
.collect(Helpers.toUnmodifiableList()));
}

@Nonnull
Expand All @@ -1177,11 +1183,11 @@ public RestAction<List<RoleConnectionMetadata>> updateRoleConnectionMetadata(@No
RequestBody body = RequestBody.create(array.toJson(), Requester.MEDIA_TYPE_JSON);

return new RestActionImpl<>(this, route, body,
(response, request) ->
response.getArray()
.stream(DataArray::getObject)
.map(RoleConnectionMetadata::fromData)
.collect(Helpers.toUnmodifiableList()));
(response, request) ->
response.getArray()
.stream(DataArray::getObject)
.map(RoleConnectionMetadata::fromData)
.collect(Helpers.toUnmodifiableList()));
}

@Nonnull
Expand Down
Loading