Skip to content

Commit

Permalink
Optimize ServerMemberBanEventImpl#requestBan() to use ServerImpl#requ…
Browse files Browse the repository at this point in the history
…estBan()
  • Loading branch information
ayubun authored and Saladoc committed Mar 11, 2022
1 parent 34f9063 commit f858856
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public interface ServerMemberBanEvent extends ServerMemberEvent {
*
* @return The ban object.
*/
CompletableFuture<Optional<Ban>> requestBan();
CompletableFuture<Ban> requestBan();

/**
* Requests the reason of the ban.
*
* @return The reason of the ban.
*/
default CompletableFuture<Optional<String>> requestReason() {
return requestBan().thenApply(ban -> ban.flatMap(Ban::getReason));
return requestBan().thenApply(Ban::getReason);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.javacord.api.event.server.member.ServerMemberBanEvent;
import org.javacord.core.event.server.ServerEventImpl;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;

/**
Expand All @@ -28,11 +27,8 @@ public ServerMemberBanEventImpl(Server server, User user) {
}

@Override
public CompletableFuture<Optional<Ban>> requestBan() {
return getServer().getBans()
.thenApply(bans -> bans.stream()
.filter(ban -> ban.getUser().equals(getUser()))
.findAny());
public CompletableFuture<Ban> requestBan() {
return getServer().requestBan(getUser());
}

@Override
Expand Down

0 comments on commit f858856

Please sign in to comment.