commit df2838a6a2cc541ff9b2861a51dca8095810691f Author: FirephoenixX02 Date: Wed Apr 24 18:05:06 2024 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..744289d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Project exclude paths +/target/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..d17dfba --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..c561374 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/commons_io_2_10_0.xml b/.idea/libraries/commons_io_2_10_0.xml new file mode 100644 index 0000000..43ef4b7 --- /dev/null +++ b/.idea/libraries/commons_io_2_10_0.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/commons_io_2_10_0_javadoc.xml b/.idea/libraries/commons_io_2_10_0_javadoc.xml new file mode 100644 index 0000000..8ecb219 --- /dev/null +++ b/.idea/libraries/commons_io_2_10_0_javadoc.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/orgjson.xml b/.idea/libraries/orgjson.xml new file mode 100644 index 0000000..dd1bcd2 --- /dev/null +++ b/.idea/libraries/orgjson.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/vecmath_1_5_2.xml b/.idea/libraries/vecmath_1_5_2.xml new file mode 100644 index 0000000..2c50af3 --- /dev/null +++ b/.idea/libraries/vecmath_1_5_2.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..4b2dc37 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8c8a81b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7fffe1d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/RapidReport.iml b/RapidReport.iml new file mode 100644 index 0000000..a376b96 --- /dev/null +++ b/RapidReport.iml @@ -0,0 +1,13 @@ + + + + + + + ADVENTURE + + 1 + + + + \ No newline at end of file diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..a244543 --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,140 @@ + + + 4.0.0 + me.firephoenix + RapidReport + RapidReport + 1.0 + + + + true + ${project.basedir}/src/main/resources + + + + + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.codehaus.mojo + templating-maven-plugin + 1.0.0 + + + filter-src + + filter-sources + + + + + + maven-site-plugin + 3.9.1 + + + net.trajano.wagon + wagon-git + 2.0.4 + + + org.apache.maven.doxia + doxia-module-markdown + 1.9.1 + + + + + maven-release-plugin + 3.0.0-M1 + + true + @{project.version} + [RELEASE] + install deploy site-deploy + release + + + + maven-shade-plugin + 3.3.0 + + + package + + shade + + + true + RapidReport + + + com.zaxxer.hikari + me.firephoenix.hikari + + + + + + + + + + + release + + + + true + src/main/resources + + + + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + maven_central + Maven Central + https://repo.maven.apache.org/maven2/ + + + exceptionflug + https://mvn.exceptionflug.de/repository/exceptionflug-public/ + + + + + com.velocitypowered + velocity-api + 3.3.0-SNAPSHOT + provided + + + org.projectlombok + lombok + 1.18.30 + provided + + + dev.simplix + protocolize-api + 2.3.3 + provided + + + + 17 + UTF-8 + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3dc18d2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + me.firephoenix + RapidReport + 1.0 + jar + + RapidReport + + + 17 + UTF-8 + + + + + release + + + + + + src/main/resources + true + + + + + + + + + + ${project.basedir}/src/main/resources + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.codehaus.mojo + templating-maven-plugin + 1.0.0 + + + filter-src + + filter-sources + + + + + + org.apache.maven.plugins + maven-site-plugin + 3.9.1 + + + net.trajano.wagon + wagon-git + 2.0.4 + + + org.apache.maven.doxia + doxia-module-markdown + 1.9.1 + + + + + org.apache.maven.plugins + maven-release-plugin + 3.0.0-M1 + + true + @{project.version} + [RELEASE] + install deploy site-deploy + release + + + + org.apache.maven.plugins + maven-shade-plugin + 3.3.0 + + + package + + shade + + + true + RapidReport + + + com.zaxxer.hikari + me.firephoenix.hikari + + + + + + + + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + maven_central + Maven Central + https://repo.maven.apache.org/maven2/ + + + exceptionflug + https://mvn.exceptionflug.de/repository/exceptionflug-public/ + + + + + + com.velocitypowered + velocity-api + 3.3.0-SNAPSHOT + provided + + + org.projectlombok + lombok + 1.18.30 + provided + + + com.zaxxer + HikariCP + 5.1.0 + + + dev.simplix + protocolize-api + 2.3.3 + provided + + + diff --git a/src/main/java/me/firephoenix/rapidreport/RapidReport.java b/src/main/java/me/firephoenix/rapidreport/RapidReport.java new file mode 100644 index 0000000..4c2c9e8 --- /dev/null +++ b/src/main/java/me/firephoenix/rapidreport/RapidReport.java @@ -0,0 +1,108 @@ +package me.firephoenix.rapidreport; + +import com.google.inject.Inject; +import com.moandjiezana.toml.Toml; +import com.velocitypowered.api.command.CommandManager; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.plugin.Dependency; +import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.plugin.annotation.DataDirectory; +import com.velocitypowered.api.proxy.ProxyServer; +import lombok.Getter; +import me.firephoenix.rapidreport.commands.CloseReportCommand; +import me.firephoenix.rapidreport.commands.ListReportsCommand; +import me.firephoenix.rapidreport.commands.ReportCommand; +import me.firephoenix.rapidreport.commands.ReportGUICommand; +import me.firephoenix.rapidreport.utils.DataBaseManager; +import org.slf4j.Logger; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; + +@Plugin( + id = "rapidreport", + name = "RapidReport", + version = "1.0", + authors = {"NieGestorben"}, + dependencies = { + @Dependency(id = "protocolize") + } +) +public class RapidReport { + public static RapidReport INSTANCE; + @Getter + public Logger logger; + @Getter + public ProxyServer proxy; + @Getter + public Path dataFolderPath; + @Getter + public Toml config; + @Getter + public DataBaseManager dataBaseManager; + @Getter + public String chatPrefix = "[RapidReport] "; + + @Inject + public RapidReport(ProxyServer proxyServer, Logger logger, @DataDirectory final Path folder) { + this.proxy = proxyServer; + this.logger = logger; + this.dataFolderPath = folder; + } + + @Subscribe + public void onProxyInitialization(ProxyInitializeEvent event) { + CommandManager commandManager = proxy.getCommandManager(); + + setInstance(this); + + config = loadConfig(dataFolderPath); + + dataBaseManager = new DataBaseManager(); + + dataBaseManager.initDB(); + + commandManager.register(commandManager.metaBuilder("report").plugin(this).build(), new ReportCommand()); + commandManager.register(commandManager.metaBuilder("reports").plugin(this).build(), new ListReportsCommand()); + commandManager.register(commandManager.metaBuilder("closereport").plugin(this).build(), new CloseReportCommand()); + commandManager.register(commandManager.metaBuilder("reportgui").plugin(this).build(), new ReportGUICommand()); + } + + public void setInstance(RapidReport INSTANCE) { + RapidReport.INSTANCE = INSTANCE; + } + + public Toml loadConfig(Path path) { + File folder = path.toFile(); + File file = new File(folder, "config.toml"); + + if (!file.getParentFile().exists()) { + boolean created = file.getParentFile().mkdirs(); + if (!created) { + throw new RuntimeException("Failed to create directories for config file."); + } + } + + if (!file.exists()) { + try (InputStream inputStream = RapidReport.class.getResourceAsStream("/" + file.getName())) { + if (inputStream != null) { + Files.copy(inputStream, file.toPath()); + } else { + boolean created = file.createNewFile(); + if (!created) { + throw new RuntimeException("Failed to create config file."); + } + } + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Error while loading config file: " + e.getMessage()); + } + } + + return new Toml().read(file); + } +} diff --git a/src/main/java/me/firephoenix/rapidreport/commands/CloseReportCommand.java b/src/main/java/me/firephoenix/rapidreport/commands/CloseReportCommand.java new file mode 100644 index 0000000..a0aa6f3 --- /dev/null +++ b/src/main/java/me/firephoenix/rapidreport/commands/CloseReportCommand.java @@ -0,0 +1,37 @@ +package me.firephoenix.rapidreport.commands; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import me.firephoenix.rapidreport.RapidReport; + + +/** + * @author NieGestorben + * Copyright© (c) 2024, All Rights Reserved. + */ +public class CloseReportCommand implements SimpleCommand { + + @Override + public void execute(final Invocation invocation) { + CommandSource commandSource = invocation.source(); + + String[] args = invocation.arguments(); + + if (args.length != 1) { + commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "Please provide the ID of the report which should be closed."); + return; + } + + int id = Integer.parseInt(args[0]); + + RapidReport.INSTANCE.getDataBaseManager().runStatementAsync("UPDATE rapid_report_reports SET status = 'Resolved' WHERE id = " + id); + + commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "Closed Report with ID " + id); + } + + @Override + public boolean hasPermission(final Invocation invocation) { + return invocation.source().hasPermission("rapidreport.closereports"); + } + +} diff --git a/src/main/java/me/firephoenix/rapidreport/commands/ListReportsCommand.java b/src/main/java/me/firephoenix/rapidreport/commands/ListReportsCommand.java new file mode 100644 index 0000000..e4308ba --- /dev/null +++ b/src/main/java/me/firephoenix/rapidreport/commands/ListReportsCommand.java @@ -0,0 +1,65 @@ +package me.firephoenix.rapidreport.commands; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import me.firephoenix.rapidreport.RapidReport; + +import java.sql.ResultSet; +import java.util.concurrent.CompletableFuture; + +/** + * @author NieGestorben + * Copyright© (c) 2024, All Rights Reserved. + */ +public class ListReportsCommand implements SimpleCommand { + + @Override + public void execute(final Invocation invocation) { + CommandSource commandSource = invocation.source(); + + String[] args = invocation.arguments(); + + if (args.length == 0) { + commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "Fetching first 10 reports from database..."); + + CompletableFuture future = RapidReport.INSTANCE.getDataBaseManager().getSQLStatementResultAsync("SELECT * FROM rapid_report_reports WHERE status = 'Unresolved' LIMIT 10"); + + future.thenAccept(result -> { + try { + while (result.next()) { + commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "[" + result.getString("id") + "] Reported Player: " + result.getString("reportedName") + " Reason: " + result.getString("reason")); + } + result.close(); + } catch (Exception e) { + e.printStackTrace(); + } + }); + } else { + if (args.length != 1) { + commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "Please provide the name of the player you want to get reports for."); + return; + } + + commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "Fetching first 10 reports for player " + args[0] + " from database..."); + + CompletableFuture future = RapidReport.INSTANCE.getDataBaseManager().getSQLStatementResultAsync("SELECT * FROM rapid_report_reports WHERE reportedName = '" + args[0] + "' LIMIT 10"); + + future.thenAccept(result -> { + try { + while (result.next()) { + commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "[" + result.getString("id") + "] Reported Player: " + result.getString("reportedName") + " Reason: " + result.getString("reason")); + } + result.close(); + } catch (Exception e) { + e.printStackTrace(); + } + }); + } + } + + @Override + public boolean hasPermission(final Invocation invocation) { + return invocation.source().hasPermission("rapidreport.reports"); + } + +} diff --git a/src/main/java/me/firephoenix/rapidreport/commands/ReportCommand.java b/src/main/java/me/firephoenix/rapidreport/commands/ReportCommand.java new file mode 100644 index 0000000..ef872e0 --- /dev/null +++ b/src/main/java/me/firephoenix/rapidreport/commands/ReportCommand.java @@ -0,0 +1,62 @@ +package me.firephoenix.rapidreport.commands; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import com.velocitypowered.api.proxy.Player; +import me.firephoenix.rapidreport.RapidReport; +import me.firephoenix.rapidreport.utils.DataBaseManager; +import me.firephoenix.rapidreport.utils.Report; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +/** + * @author NieGestorben + * Copyright© (c) 2024, All Rights Reserved. + */ +public class ReportCommand implements SimpleCommand { + + @Override + public void execute(final Invocation invocation) { + CommandSource commandSource = invocation.source(); + + String reporterName = commandSource instanceof Player player ? player.getUsername() : "console"; + + String[] args = invocation.arguments(); + + if (args.length != 2) { + commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "Please enter in a player you want to report and a reason."); + return; + } + + if (RapidReport.INSTANCE.getProxy().getPlayer(args[0]).isEmpty()) { + commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "The player " + args[0] + " is not online!"); + return; + } + + Player reportedPlayer = RapidReport.INSTANCE.getProxy().getPlayer(args[0]).get(); + + UUID reportedPlayerUUID = reportedPlayer.getUniqueId(); + + Report report = new Report(reporterName, reportedPlayer.getUsername(), reportedPlayerUUID, args[1], "Unresolved"); + + RapidReport.INSTANCE.getDataBaseManager().submitNewReportToDB(report); + + commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "Player " + reportedPlayer.getUsername() + " for " + args[1]); + } + + @Override + public boolean hasPermission(final Invocation invocation) { + return invocation.source().hasPermission("rapidreport.report"); + } + + @Override + public CompletableFuture> suggestAsync(final Invocation invocation) { + List playerNames = new ArrayList<>(); + RapidReport.INSTANCE.getProxy().getAllPlayers().forEach(player -> playerNames.add(player.getUsername())); + return CompletableFuture.completedFuture(playerNames); + } +} diff --git a/src/main/java/me/firephoenix/rapidreport/commands/ReportGUICommand.java b/src/main/java/me/firephoenix/rapidreport/commands/ReportGUICommand.java new file mode 100644 index 0000000..f85dea3 --- /dev/null +++ b/src/main/java/me/firephoenix/rapidreport/commands/ReportGUICommand.java @@ -0,0 +1,46 @@ +package me.firephoenix.rapidreport.commands; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import com.velocitypowered.api.proxy.Player; +import dev.simplix.protocolize.api.Protocolize; +import dev.simplix.protocolize.api.chat.ChatElement; +import dev.simplix.protocolize.api.inventory.Inventory; +import dev.simplix.protocolize.api.player.ProtocolizePlayer; +import dev.simplix.protocolize.data.inventory.InventoryType; +import me.firephoenix.rapidreport.RapidReport; + + +/** + * @author NieGestorben + * Copyright© (c) 2024, All Rights Reserved. + */ +public class ReportGUICommand implements SimpleCommand { + + @Override + public void execute(final Invocation invocation) { + CommandSource commandSource = invocation.source(); + + String[] args = invocation.arguments(); + + if (!(commandSource instanceof Player)) { + commandSource.sendRichMessage(RapidReport.INSTANCE.getChatPrefix() + "This command can only be executed by a player."); + return; + } + + + + Inventory inventory = new Inventory(InventoryType.GENERIC_9X4); + inventory.title(ChatElement.ofLegacyText("§9Inventory")); + + ProtocolizePlayer protocolizePlayer = Protocolize.playerProvider().player(((Player) commandSource).getUniqueId()); + + protocolizePlayer.openInventory(inventory); + } + + @Override + public boolean hasPermission(final Invocation invocation) { + return invocation.source().hasPermission("rapidreport.gui"); + } + +} diff --git a/src/main/java/me/firephoenix/rapidreport/utils/DataBaseManager.java b/src/main/java/me/firephoenix/rapidreport/utils/DataBaseManager.java new file mode 100644 index 0000000..3b14ca7 --- /dev/null +++ b/src/main/java/me/firephoenix/rapidreport/utils/DataBaseManager.java @@ -0,0 +1,132 @@ +package me.firephoenix.rapidreport.utils; + + +import com.zaxxer.hikari.HikariDataSource; +import lombok.Getter; +import me.firephoenix.rapidreport.RapidReport; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +/** + * @author NieGestorben + * Copyright© (c) 2023, All Rights Reserved. + */ +@Getter +public class DataBaseManager { + + private final HikariDataSource hikariCP; + + public DataBaseManager() { + this.hikariCP = new HikariDataSource(); + try { + String host = RapidReport.INSTANCE.getConfig().getString("mysql.host"); + int port = Integer.parseInt(RapidReport.INSTANCE.getConfig().getString("mysql.port")); + String username = RapidReport.INSTANCE.getConfig().getString("mysql.user"); + String password = RapidReport.INSTANCE.getConfig().getString("mysql.password"); + String database = RapidReport.INSTANCE.getConfig().getString("mysql.db"); + + getHikariCP().setMaximumPoolSize(25); + getHikariCP().setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + database + "?characterEncoding=utf8"); + getHikariCP().addDataSourceProperty("port", port); + getHikariCP().addDataSourceProperty("password", password); + getHikariCP().addDataSourceProperty("databaseName", database); + getHikariCP().addDataSourceProperty("user", username); + getHikariCP().addDataSourceProperty("cachePrepStmts", true); + getHikariCP().addDataSourceProperty("prepStmtCacheSize", 250); + getHikariCP().addDataSourceProperty("prepStmtCacheSqlLimit", 2048); + getHikariCP().addDataSourceProperty("useServerPrepStmts", true); + getHikariCP().addDataSourceProperty("useLocalSessionState", true); + getHikariCP().addDataSourceProperty("rewriteBatchedStatements", true); + getHikariCP().addDataSourceProperty("cacheResultSetMetadata", true); + getHikariCP().addDataSourceProperty("cacheServerConfiguration", true); + getHikariCP().addDataSourceProperty("elideSetAutoCommits", true); + getHikariCP().addDataSourceProperty("maintainTimeStats", false); + getHikariCP().addDataSourceProperty("alwaysSendSetIsolation", false); + getHikariCP().addDataSourceProperty("cacheCallableStmts", true); + + getHikariCP().setUsername(username); + getHikariCP().setPassword(password); + + this.hikariCP.getConnection(); + RapidReport.INSTANCE.logger.info("Successfully connected to database!"); + } catch (SQLException e) { + RapidReport.INSTANCE.logger.info("There was an error connecting to the database! Error: {}", e.getMessage()); + } + } + + public void runStatementAsync(String statement) { + RapidReport.INSTANCE.proxy.getScheduler().buildTask(RapidReport.INSTANCE, () -> { + try { + Connection connection = hikariCP.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement(statement); + preparedStatement.execute(); + preparedStatement.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }).schedule(); + } + + public CompletableFuture getSQLStatementResultAsync(String statement) { + CompletableFuture future = new CompletableFuture<>(); + + RapidReport.INSTANCE.proxy.getScheduler().buildTask(RapidReport.INSTANCE, () -> { + try (Connection connection = hikariCP.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement(statement)) { + ResultSet resultSet = preparedStatement.executeQuery(); + future.complete(resultSet); + } catch (SQLException e) { + future.completeExceptionally(e); + } + }).schedule(); + + return future; + } + + public void submitNewReportToDB(Report report) { + runStatementAsync("INSERT INTO rapid_report_reports (reporterName, reportedName, reportedUUID, reason, status) VALUES ('" + report.reporterPlayerName + "', '" + report.reportedPlayerName + "', '" + report.reportedPlayerUUID.toString() + "', '" + report.reason + "', '" + report.status + "')"); + } + + public void initDB() { + // first lets read our setup file. + // This file contains statements to create our inital tables. + // it is located in the resources. + String setup; + try (InputStream in = getClass().getClassLoader().getResourceAsStream("dbsetup.sql")) { + // Java 9+ way + // Legacy way + assert in != null; + setup = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n")); + // Mariadb can only handle a single query per statement. We need to split at ;. + String[] queries = setup.split(";"); + // execute each query to the database. + for (String query : queries) { + // If you use the legacy way you have to check for empty queries here. + if (query.isEmpty()) continue; + try (Connection conn = hikariCP.getConnection(); + PreparedStatement stmt = conn.prepareStatement(query)) { + stmt.execute(); + } catch (SQLException e) { + RapidReport.INSTANCE.logger.info("Error executing database setup!", e); + } + } + } catch (IOException e) { + RapidReport.INSTANCE.logger.info("Could not read db setup file.", e); + } + } + + public void close() { + hikariCP.close(); + } +} + diff --git a/src/main/java/me/firephoenix/rapidreport/utils/Report.java b/src/main/java/me/firephoenix/rapidreport/utils/Report.java new file mode 100644 index 0000000..f4faaae --- /dev/null +++ b/src/main/java/me/firephoenix/rapidreport/utils/Report.java @@ -0,0 +1,26 @@ +package me.firephoenix.rapidreport.utils; + +import me.firephoenix.rapidreport.commands.ReportCommand; + +import java.util.UUID; + +/** + * @author NieGestorben + * Copyright© (c) 2024, All Rights Reserved. + */ +public class Report { + public final String reporterPlayerName; + public final String reportedPlayerName; + public final UUID reportedPlayerUUID; + public final String reason; + public final String status; + + public Report(final String reporterPlayerName, final String reportedPlayerName, final UUID reportedPlayerUUID, final String reason, final String status) { + this.reporterPlayerName = reporterPlayerName; + this.reportedPlayerName = reportedPlayerName; + this.reportedPlayerUUID = reportedPlayerUUID; + this.reason = reason; + this.status = status; + } + +} diff --git a/src/main/resources/config.toml b/src/main/resources/config.toml new file mode 100644 index 0000000..a979b0c --- /dev/null +++ b/src/main/resources/config.toml @@ -0,0 +1,6 @@ +[mysql] +host = "localhost" +port = "3306" +user = "user" +password = "changeme" +db = "your-database" \ No newline at end of file diff --git a/src/main/resources/dbsetup.sql b/src/main/resources/dbsetup.sql new file mode 100644 index 0000000..fb21ea0 --- /dev/null +++ b/src/main/resources/dbsetup.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS rapid_report_reports ( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + reporterName VARCHAR(255) NOT NULL, + reportedName VARCHAR(255) NOT NULL, + reportedUUID VARCHAR(255) NOT NULL, + reason VARCHAR(255) NOT NULL, + status VARCHAR(255) NOT NULL +); \ No newline at end of file