Chat Report changes + allow either mariadb or mysql

Chat report will now actually create a report, along with an export of chat messages from the last two minutes.
This commit is contained in:
Gxorge committed 2023-05-31 22:21:27 +01:00
1 parent 14db4ce417
commit 8e2f36b06b
7 files changed
+83 -12

No files matched your search

+1
View File
@@ -32,6 +32,7 @@ dependencies {
api 'org.jooq:jooq:3.18.4'
api 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0'
api 'org.mariadb.jdbc:mariadb-java-client:3.1.3'
api 'mysql:mysql-connector-java:8.0.32'
compileOnly 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT'
compileOnly "com.github.MilkBowl:VaultAPI:1.7"
compileOnly 'org.projectlombok:lombok:1.18.22'
@@ -15,6 +15,9 @@ public class StaffOGPlugin extends JavaPlugin {
@Getter private static Permission vaultPerms;
@Getter private static String reportWebAddress;
@Getter private static String appealWebAddress;
@Override
public void onEnable() {
Console.info("Setting up Staff-OG...");
@@ -29,6 +32,9 @@ public class StaffOGPlugin extends JavaPlugin {
getServer().getPluginManager().disablePlugin(this);
}
reportWebAddress = this.getConfig().getString("reportWebAddress");
appealWebAddress = this.getConfig().getString("appealWebAddress");
DatabaseManager databaseManager = new DatabaseManager(this);
PunishManager punishManager = new PunishManager(this);
SecurityManager securityManager = new SecurityManager(this);
@@ -13,6 +13,8 @@ import uk.hotten.staffog.security.SecurityManager;
import uk.hotten.staffog.security.data.StaffIPInfo;
import uk.hotten.staffog.utils.Message;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
public class ChatReportCommand implements CommandExecutor {
@@ -24,8 +26,8 @@ public class ChatReportCommand implements CommandExecutor {
return true;
}
if (args == null || args.length < 1) {
player.sendMessage(Message.format(ChatColor.RED + "Correct Usage: /chatreport <player>"));
if (args == null || args.length < 2) {
player.sendMessage(Message.format(ChatColor.RED + "Correct Usage: /chatreport <player> <reason>"));
return true;
}
@@ -37,13 +39,29 @@ public class ChatReportCommand implements CommandExecutor {
UUID reported = pm.getUUIDFromChatReport(args[0]);
String reportId = pm.exportChatReport(player.getUniqueId(), reported);
if (reportId == null) {
ArrayList<String> preReason = new ArrayList<>(Arrays.asList(args));
preReason.remove(0);
String reason = String.join(" ", preReason);
String chatReportId = pm.exportChatReport(player.getUniqueId(), reported);
if (chatReportId == null) {
player.sendMessage(Message.format(ChatColor.RED + "Failed to generate chat report. Please try again."));
return true;
}
player.sendMessage(Message.format(ChatColor.GREEN + "Chat report successfully created. Please quote the report ID " + ChatColor.WHITE + "#" + reportId + ChatColor.GREEN + " to staff when required."));
String staffReportId = pm.createReportFromCR(player.getUniqueId(), reported, Integer.parseInt(chatReportId), reason);
if (staffReportId == null) {
player.sendMessage(Message.format(ChatColor.RED + "Failed to create a report to staff, however a chat log was successfully exported with ID " +
ChatColor.WHITE + "#" + chatReportId + ChatColor.RED + ". Please create a manual report quoting this Chat Report ID on " +
ChatColor.WHITE + StaffOGPlugin.getReportWebAddress()));
} else {
player.sendMessage(Message.format(ChatColor.GREEN + "Chat report successfully created. Your staff report reference is " +
ChatColor.WHITE + "#" + staffReportId + ChatColor.GREEN + ". Your chat report ID is " +
ChatColor.WHITE + "#" + chatReportId + ChatColor.GREEN + " and has been included in your report to staff."));
player.sendMessage(Message.format(ChatColor.DARK_GREEN + "You can check the status of your report at " +
ChatColor.WHITE + StaffOGPlugin.getReportWebAddress()));
}
return true;
}
}
@@ -16,13 +16,32 @@ public class DatabaseManager {
@Getter private JavaPlugin plugin;
@Getter private static DatabaseManager instance;
private String host, username, password, database;
private String driver, driverUrl, host, username, password, database;
private int port;
public DatabaseManager(JavaPlugin plugin) {
this.plugin = plugin;
instance = this;
String sqlType = plugin.getConfig().getString("sqlType");
if (sqlType == null) {
Console.error("NO SQL TYPE SELECTED. DEFAULTING TO MYSQL.");
driver = "com.mysql.jdbc.Driver";
driverUrl = "mysql";
} else {
if (sqlType.equalsIgnoreCase("mysql")) {
driver = "com.mysql.jdbc.Driver";
driverUrl = "mysql";
} else if (sqlType.equals("mariadb")) {
driver = "org.mariadb.jdbc.Driver";
driverUrl = "mariadb";
} else {
Console.error("INVALID SQL TYPE, PLEASE USE EITHER MYSQL OR MARIADB. DEFAULTING TO MYSQL.");
driver = "com.mysql.jdbc.Driver";
driverUrl = "mysql";
}
}
host = plugin.getConfig().getString("sqlHost");
username = plugin.getConfig().getString("sqlUsername");
password = plugin.getConfig().getString("sqlPassword");
@@ -47,8 +66,8 @@ public class DatabaseManager {
public Connection createConnection() throws SQLException, ClassNotFoundException {
synchronized (this) {
Class.forName("org.mariadb.jdbc.Driver");
return DriverManager.getConnection("jdbc:mariadb://" + host + ":" + port + "/" + database + "?userSSL=false", username, password);
Class.forName(driver);
return DriverManager.getConnection("jdbc:" + driverUrl + "://" + host + ":" + port + "/" + database + "?userSSL=false", username, password);
}
}
@@ -11,6 +11,7 @@ import uk.hotten.staffog.data.DatabaseManager;
import uk.hotten.staffog.data.jooq.tables.records.StaffogBanRecord;
import uk.hotten.staffog.data.jooq.tables.records.StaffogChatreportRecord;
import uk.hotten.staffog.data.jooq.tables.records.StaffogMuteRecord;
import uk.hotten.staffog.data.jooq.tables.records.StaffogReportRecord;
import uk.hotten.staffog.punish.data.ChatReportEntry;
import uk.hotten.staffog.punish.data.KickPunishEntry;
import uk.hotten.staffog.punish.data.PunishEntry;
@@ -406,7 +407,7 @@ public class PunishManager {
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
DSLContext dsl = DSL.using(connection);
StaffogChatreportRecord result = dsl.insertInto(STAFFOG_CHATREPORT)
StaffogChatreportRecord record = dsl.insertInto(STAFFOG_CHATREPORT)
.set(STAFFOG_CHATREPORT.UUID, reported.toString())
.set(STAFFOG_CHATREPORT.BY_UUID, by.toString())
.set(STAFFOG_CHATREPORT.TIME, System.currentTimeMillis())
@@ -414,7 +415,29 @@ public class PunishManager {
.returning(STAFFOG_CHATREPORT.ID)
.fetchOne();
return "" + result.getId();
return "" + record.getId();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public String createReportFromCR(UUID by, UUID reported, int crid, String reason) {
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
DSLContext dsl = DSL.using(connection);
StaffogReportRecord record = dsl.insertInto(STAFFOG_REPORT)
.set(STAFFOG_REPORT.UUID, reported.toString())
.set(STAFFOG_REPORT.BY_UUID, by.toString())
.set(STAFFOG_REPORT.TIME, System.currentTimeMillis())
.set(STAFFOG_REPORT.TYPE, "CHAT")
.set(STAFFOG_REPORT.REASON, reason)
.set(STAFFOG_REPORT.CRID, crid)
.returning(STAFFOG_REPORT.ID)
.fetchOne();
return "" + record.getId();
} catch (Exception e) {
e.printStackTrace();
+4
View File
@@ -1,3 +1,7 @@
reportWebAddress: "https://report.trueog.net"
appealWebAddress: "https://appeal.trueog.net"
sqlType: mariadb # Options: mariadb or mysql
sqlHost: localhost
sqlUsername: username
sqlPassword: password
+2 -2
View File
@@ -13,8 +13,8 @@ commands:
usage: /<command>
chatreport:
description: Takes a snapshot of a player's messages, used for reporting chat offences.
usage: /<command> <player>
description: Report a player for a chat offence.
usage: /<command> <player> <reason>
permban:
description: Permanently ban a player.