everything works

This commit is contained in:
Telesphoreo 2024-05-26 16:40:29 -05:00
parent 0c6de52df8
commit a60338e316
5 changed files with 34 additions and 33 deletions

View File

@ -4,6 +4,7 @@ import dev.plex.medina.command.MedinaCommand;
import dev.plex.medina.command.annotation.CommandParameters; import dev.plex.medina.command.annotation.CommandParameters;
import dev.plex.medina.command.source.RequiredCommandSource; import dev.plex.medina.command.source.RequiredCommandSource;
import dev.plex.medina.data.Report; import dev.plex.medina.data.Report;
import dev.plex.medina.util.MedinaLog;
import dev.plex.medina.util.MedinaUtils; import dev.plex.medina.util.MedinaUtils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -43,6 +44,7 @@ public class ReportCommand extends MedinaCommand
false); false);
plugin.getSqlReports().addReport(report); plugin.getSqlReports().addReport(report);
MedinaUtils.broadcastToAdmins(messageComponent("notifyReport", sender.getName(), player.getName(), reason), "medina.notify");
return messageComponent("reportSubmitted", player.getName()); return messageComponent("reportSubmitted", player.getName());
} }

View File

@ -4,7 +4,6 @@ import dev.plex.medina.command.MedinaCommand;
import dev.plex.medina.command.annotation.CommandParameters; import dev.plex.medina.command.annotation.CommandParameters;
import dev.plex.medina.command.source.RequiredCommandSource; import dev.plex.medina.command.source.RequiredCommandSource;
import dev.plex.medina.data.Report; import dev.plex.medina.data.Report;
import dev.plex.medina.util.MedinaLog;
import dev.plex.medina.util.MedinaUtils; import dev.plex.medina.util.MedinaUtils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -14,7 +13,6 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.time.ZoneId;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -86,6 +84,10 @@ public class ReportsCommand extends MedinaCommand
AtomicReference<Component> reportList = new AtomicReference<>(messageComponent("reportHeader", player.getName())); AtomicReference<Component> reportList = new AtomicReference<>(messageComponent("reportHeader", player.getName()));
for (Report report : reports) for (Report report : reports)
{ {
if (report.isDeleted())
{
continue;
}
Component reportLine = messageComponent("reportPrefix", report.getReportId(), player.getName(), MedinaUtils.useTimezone(report.getTimestamp())); Component reportLine = messageComponent("reportPrefix", report.getReportId(), player.getName(), MedinaUtils.useTimezone(report.getTimestamp()));
reportLine = reportLine.append(messageComponent("reportLine", report.getReason())); reportLine = reportLine.append(messageComponent("reportLine", report.getReason()));
reportList.set(reportList.get().append(Component.newline())); reportList.set(reportList.get().append(Component.newline()));

View File

@ -24,60 +24,49 @@ public class SQLReports implements MedinaBase
public CompletableFuture<Report> getReports(int reportedId) public CompletableFuture<Report> getReports(int reportedId)
{ {
MedinaLog.log("getting reports for: " + reportedId);
return CompletableFuture.supplyAsync(() -> return CompletableFuture.supplyAsync(() ->
{ {
Report report; Report report;
MedinaLog.log("initialized List<Report>");
try (Connection con = plugin.getSqlConnection().getCon()) try (Connection con = plugin.getSqlConnection().getCon())
{ {
MedinaLog.log("opened connection");
PreparedStatement statement = con.prepareStatement(SELECT_ID); PreparedStatement statement = con.prepareStatement(SELECT_ID);
MedinaLog.log("prepared select statement");
statement.setInt(1, reportedId); statement.setInt(1, reportedId);
MedinaLog.log("set reportedUUID to " + reportedId);
ResultSet set = statement.executeQuery(); ResultSet set = statement.executeQuery();
MedinaLog.log("executing query"); if (set.next())
MedinaLog.log("adding a report..."); {
report = new Report( report = new Report(
reportedId, reportedId,
UUID.fromString(set.getString("reporterUUID")), UUID.fromString(set.getString("reporterUUID")),
set.getString("reporterName"), set.getString("reporterName"),
UUID.fromString(set.getString("reportedUUID")), UUID.fromString(set.getString("reportedUUID")),
set.getString("reportedName"), set.getString("reportedName"),
ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("timestamp")), ZoneId.systemDefault()), ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("timestamp")), ZoneId.systemDefault()),
set.getString("reason"), set.getString("reason"),
set.getBoolean("deleted")); set.getBoolean("deleted"));
MedinaLog.log("added a report, id is " + report.getReportId()); return report;
return report; }
} }
catch (Throwable e) catch (Throwable e)
{ {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
return null;
}); });
} }
public CompletableFuture<List<Report>> getReports(UUID reportedUUID) public CompletableFuture<List<Report>> getReports(UUID reportedUUID)
{ {
MedinaLog.log("getting reports for: " + reportedUUID);
return CompletableFuture.supplyAsync(() -> return CompletableFuture.supplyAsync(() ->
{ {
List<Report> reports = Lists.newArrayList(); List<Report> reports = Lists.newArrayList();
MedinaLog.log("initialized List<Report>");
try (Connection con = plugin.getSqlConnection().getCon()) try (Connection con = plugin.getSqlConnection().getCon())
{ {
MedinaLog.log("opened connection");
PreparedStatement statement = con.prepareStatement(SELECT); PreparedStatement statement = con.prepareStatement(SELECT);
MedinaLog.log("prepared select statement");
statement.setString(1, reportedUUID.toString()); statement.setString(1, reportedUUID.toString());
MedinaLog.log("set reportedUUID to " + reportedUUID);
ResultSet set = statement.executeQuery(); ResultSet set = statement.executeQuery();
MedinaLog.log("executing query");
while (set.next()) while (set.next())
{ {
MedinaLog.log("adding a report...");
Report report = new Report( Report report = new Report(
set.getInt("reportId"), set.getInt("reportId"),
UUID.fromString(set.getString("reporterUUID")), UUID.fromString(set.getString("reporterUUID")),
@ -88,7 +77,6 @@ public class SQLReports implements MedinaBase
set.getString("reason"), set.getString("reason"),
set.getBoolean("deleted")); set.getBoolean("deleted"));
reports.add(report); reports.add(report);
MedinaLog.log("added a report, id is " + report.getReportId());
} }
} }
catch (Throwable e) catch (Throwable e)
@ -102,18 +90,14 @@ public class SQLReports implements MedinaBase
public CompletableFuture<Void> deleteReport(int reportId, UUID reportedUUID) public CompletableFuture<Void> deleteReport(int reportId, UUID reportedUUID)
{ {
MedinaLog.log("deleting report");
return CompletableFuture.runAsync(() -> return CompletableFuture.runAsync(() ->
{ {
MedinaLog.log("running async");
try (Connection con = plugin.getSqlConnection().getCon()) try (Connection con = plugin.getSqlConnection().getCon())
{ {
MedinaLog.log("established connection");
PreparedStatement statement = con.prepareStatement(DELETE); PreparedStatement statement = con.prepareStatement(DELETE);
statement.setInt(1, reportId); statement.setInt(1, reportId);
statement.setString(2, reportedUUID.toString()); statement.setString(2, reportedUUID.toString());
statement.execute(); statement.execute();
MedinaLog.log("deleted report");
} }
catch (Throwable e) catch (Throwable e)
{ {

View File

@ -67,6 +67,14 @@ public class MedinaUtils implements MedinaBase
return f; return f;
} }
public static void broadcastToAdmins(Component component, String permission)
{
Bukkit.getOnlinePlayers().stream().filter(pl -> pl.hasPermission(permission)).forEach(pl ->
{
pl.sendMessage(component);
});
}
public static List<String> getPlayerNameList() public static List<String> getPlayerNameList()
{ {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());

View File

@ -37,4 +37,9 @@ reportLine: "<newline><yellow># {0}"
# 0 - the Report ID # 0 - the Report ID
deletedReport: "<green>Report ID: {0} deleted" deletedReport: "<green>Report ID: {0} deleted"
reportDoesntExist: "<red>There is no report with this ID belonging to that player." reportDoesntExist: "<red>There is no report with this ID belonging to that player."
# 0 - The person who initiated the report
# 1 - The person being reported
# 2 - The reason for the report
notifyReport: "<dark_gray>[<yellow>REPORT<dark_gray>] <gold>{0} reported {1} for {2}"