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 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
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 @@ -20,6 +20,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerQuitEvent;
import tc.oc.api.bukkit.users.BukkitUserStore;
import tc.oc.api.bukkit.users.OnlinePlayers;
import tc.oc.api.docs.Report;
import tc.oc.api.docs.Server;
import tc.oc.minecraft.scheduler.SyncExecutor;
Expand Down Expand Up @@ -55,6 +56,7 @@ public class ReportCommands implements Commands, Listener {
private final BukkitUserStore userStore;
private final Audiences audiences;
private final IdentityProvider identities;
private final OnlinePlayers onlinePlayers;

private final Map<CommandSender, Instant> senderLastReport = new WeakHashMap<>();

Expand All @@ -67,7 +69,8 @@ public class ReportCommands implements Commands, Listener {
Server localServer,
BukkitUserStore userStore,
Audiences audiences,
IdentityProvider identities) {
IdentityProvider identities,
OnlinePlayers onlinePlayers) {
this.reportFormatter = reportFormatter;
this.reportService = reportService;
this.reportCreator = reportCreator;
Expand All @@ -78,6 +81,7 @@ public class ReportCommands implements Commands, Listener {
this.userStore = userStore;
this.audiences = audiences;
this.identities = identities;
this.onlinePlayers = onlinePlayers;
}

@EventHandler
Expand All @@ -91,6 +95,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 +153,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 +167,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 @@ -183,8 +192,8 @@ public void reports(final CommandContext args, final CommandSender sender) throw
final Audience audience = audiences.get(sender);
audience.sendMessage(new HeaderComponent(title));
for(Report report : reportResult.documents()) {
if(report.reported() != null) {
audience.sendMessages(reportFormatter.format(report, crossServer, true));
if(report.reported() != null && onlinePlayers.find(report.reported()).isOnline()) {
Copy link
Member

Choose a reason for hiding this comment

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

report.reported() != null && (showOffline || onlinePlayers.find(report.reported()).isOnline())

Copy link
Member

Choose a reason for hiding this comment

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

You need to figure out how to get this to work with the a flag

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,13 +24,15 @@ 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<>();

parts.add(new Component(
Expand Down