Skip to content
This repository has been archived by the owner on Nov 25, 2019. It is now read-only.

Make reports no longer show reports with offline reportees #78

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void broadcast(ModelUpdate<Report> message) {
if(localServer._id().equals(message.document().server_id()) ||
(config.crossServer() && config.families().contains(message.document().family()))) {

final List<? extends BaseComponent> formatted = reportFormatter.format(message.document(), true, false);
final List<? extends BaseComponent> formatted = reportFormatter.format(message.document(), true, false, false);
adminChannel.viewers()
.filter(viewer -> viewer.hasPermission(ReportPermissions.RECEIVE))
.forEach(viewer -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ private void assertEnabled() throws CommandException {
}
}

private void displayReports(Audience audience, Report report, boolean showServer, boolean showTime, boolean displayOffline) {
audience.sendMessages(reportFormatter.format(report, showServer, showTime, displayOffline));
}

@Command(
aliases = { "report" },
usage = "<player> <reason>",
Expand Down Expand Up @@ -145,7 +149,7 @@ public void report(final CommandContext args, final CommandSender sender) throws
@Command(
aliases = { "reports", "reps" },
usage = "[-a] [-p page] [player]",
flags = "ap:",
flags = "aop:",
desc = "List recent reports on this server, or all servers, optionally filtering by player.",
min = 0,
max = 1
Expand All @@ -159,6 +163,7 @@ public void reports(final CommandContext args, final CommandSender sender) throw
CommandFutureCallback.onSuccess(sender, args, userResult -> {
final int page = args.getFlagInteger('p', 1);
final boolean crossServer = args.hasFlag('a');
final boolean showOffline = args.hasFlag('o');

ReportSearchRequest request = ReportSearchRequest.create(page, PER_PAGE);
request = crossServer ? request.forFamilies(reportConfiguration.families())
Expand All @@ -184,7 +189,7 @@ public void reports(final CommandContext args, final CommandSender sender) throw
audience.sendMessage(new HeaderComponent(title));
for(Report report : reportResult.documents()) {
if(report.reported() != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check if the player is offline here instead of in ReportFormatter. That would avoid calling audience.sendmessage() for a bunch of empty collections.

audience.sendMessages(reportFormatter.format(report, crossServer, true));
displayReports(audience, report, crossServer, true, showOffline);
}
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package tc.oc.commons.bukkit.report;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your changes in reportformatter don’t seem to do anything. They can probably just be discarded.


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;

import com.google.common.collect.ImmutableList;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import tc.oc.api.bukkit.users.OnlinePlayers;
import tc.oc.api.docs.Report;
import tc.oc.api.servers.ServerStore;
import tc.oc.commons.bukkit.chat.NameStyle;
Expand All @@ -22,15 +24,21 @@ public class ReportFormatter {

private final IdentityProvider identityProvider;
private final ServerStore servers;
private final OnlinePlayers onlinePlayers;

@Inject ReportFormatter(IdentityProvider identityProvider, ServerStore servers) {
@Inject ReportFormatter(IdentityProvider identityProvider, ServerStore servers, OnlinePlayers onlinePlayers) {
this.identityProvider = identityProvider;
this.servers = servers;
this.onlinePlayers = onlinePlayers;
}

public List<? extends BaseComponent> format(Report report, boolean showServer, boolean showTime) {
public List<? extends BaseComponent> format(Report report, boolean showServer, boolean showTime, boolean displayOffline) {
final List<BaseComponent> parts = new ArrayList<>();

if(!displayOffline && onlinePlayers.find(report.reported()).onlinePlayer() == null) {
return Collections.emptyList();
}

parts.add(new Component(
new Component("["),
new Component("Rep", ChatColor.GOLD),
Expand Down