Skip to content

Commit

Permalink
Updated to 0.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon Dawson-Couper committed Dec 3, 2023
1 parent 8fe9ae2 commit 9213641
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 230 deletions.
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.leon.bugreport</groupId>
<artifactId>BugReports</artifactId>
<version>0.7.1</version>
<version>0.7.2</version>
<build>
<plugins>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.leon.bugreport</groupId>
<artifactId>BugReports</artifactId>
<version>0.7.1</version>
<version>0.7.2</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/leon/bugreport/API/DataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,12 @@ public static void cleanOutdatedCache() {
JsonObject jsonResponse = JsonParser.parseString(response).getAsJsonObject();
String uuidString = jsonResponse.get("id").getAsString();
return UUID.fromString(
uuidString.substring(0, 8) + "-" +
uuidString.substring(8, 12) + "-" +
uuidString.substring(12, 16) + "-" +
uuidString.substring(16, 20) + "-" +
uuidString.substring(20, 32));
uuidString.substring(0, 8) + "-" +
uuidString.substring(8, 12) + "-" +
uuidString.substring(12, 16) + "-" +
uuidString.substring(16, 20) + "-" +
uuidString.substring(20, 32)
);
}

public static @NotNull ItemStack getPlayerHead(String playerName) {
Expand Down Expand Up @@ -200,7 +201,6 @@ private static boolean checkIfPlayerHeadIsCached(String playerName, @NotNull Map

private static @NotNull ItemStack getCachedPlayerHead(String playerName, @NotNull Map<String, CacheEntry> cache) {
CacheEntry mainEntry = cache.get(playerName);
String uuidString = mainEntry.data;
String base64 = null;
if ("00000000-0000-0000-0000-000000000000".equals(mainEntry.data)) {
return new ItemStack(Material.PLAYER_HEAD);
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/com/leon/bugreport/BugListArchivedCommand.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.leon.bugreport;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import static com.leon.bugreport.BugReportManager.pluginColor;
import static com.leon.bugreport.BugReportManager.pluginTitle;
Expand All @@ -26,29 +23,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

if (player.hasPermission("bugreport.admin")) {
BugReportManager.setCurrentPage(player, 1);

Inventory bugReportGUI = BugReportManager.getArchivedBugReportsGUI(player);

ItemStack backButton = null;
ItemStack forwardButton;

if (BugReportManager.getCurrentPage(player) == 1) {
bugReportGUI.setItem(36, new ItemStack(Material.AIR));
} else {
backButton = new ItemStack(Material.ARROW);
ItemMeta backMeta = backButton.getItemMeta();
backMeta.setDisplayName(ChatColor.GREEN + BugReportLanguage.getTitleFromLanguage("back"));
backButton.setItemMeta(backMeta);
}

forwardButton = new ItemStack(Material.ARROW);
ItemMeta forwardMeta = forwardButton.getItemMeta();
forwardMeta.setDisplayName(ChatColor.GREEN + BugReportLanguage.getTitleFromLanguage("forward"));
forwardButton.setItemMeta(forwardMeta);

bugReportGUI.setItem(36, backButton);
bugReportGUI.setItem(44, forwardButton);

player.openInventory(bugReportGUI);
} else {
player.sendMessage(pluginColor + pluginTitle + " " + ChatColor.RED + "You don't have permission to use this command.");
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/com/leon/bugreport/BugListCommand.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.leon.bugreport;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import static com.leon.bugreport.BugReportManager.pluginColor;
import static com.leon.bugreport.BugReportManager.pluginTitle;
Expand All @@ -23,32 +20,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage(pluginColor + pluginTitle + " " + "This command can only be run by a player.");
return true;
}

if (player.hasPermission("bugreport.admin")) {
BugReportManager.setCurrentPage(player, 1);

Inventory bugReportGUI = BugReportManager.getBugReportGUI(player);

ItemStack backButton = null;
ItemStack forwardButton;

if (BugReportManager.getCurrentPage(player) == 1) {
bugReportGUI.setItem(36, new ItemStack(Material.AIR));
} else {
backButton = new ItemStack(Material.ARROW);
ItemMeta backMeta = backButton.getItemMeta();
backMeta.setDisplayName(ChatColor.GREEN + BugReportLanguage.getTitleFromLanguage("back"));
backButton.setItemMeta(backMeta);
}

forwardButton = new ItemStack(Material.ARROW);
ItemMeta forwardMeta = forwardButton.getItemMeta();
forwardMeta.setDisplayName(ChatColor.GREEN + BugReportLanguage.getTitleFromLanguage("forward"));
forwardButton.setItemMeta(forwardMeta);

bugReportGUI.setItem(36, backButton);
bugReportGUI.setItem(44, forwardButton);

player.openInventory(bugReportGUI);
} else {
player.sendMessage(pluginColor + pluginTitle + " " + ChatColor.RED + "You don't have permission to use this command.");
Expand Down
84 changes: 30 additions & 54 deletions src/main/java/com/leon/bugreport/BugReportDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ public BugReportDatabase() {

private static void addTimestampColumn() {
try (Connection connection = dataSource.getConnection()) {
try (ResultSet archivedResultSet = connection.getMetaData().getColumns(null, null, "player_data",
"last_login_timestamp")) {
try (ResultSet archivedResultSet = connection.getMetaData().getColumns(null, null, "player_data", "last_login_timestamp")) {
if (!archivedResultSet.next()) {
connection.createStatement()
.execute("ALTER TABLE player_data ADD COLUMN last_login_timestamp BIGINT DEFAULT 0");
connection.createStatement().execute("ALTER TABLE player_data ADD COLUMN last_login_timestamp BIGINT DEFAULT 0");
}
}
try (ResultSet archivedResultSet = connection.getMetaData().getColumns(null, null, "bug_reports",
"timestamp")) {
try (ResultSet archivedResultSet = connection.getMetaData().getColumns(null, null, "bug_reports", "timestamp")) {
if (!archivedResultSet.next()) {
connection.createStatement()
.execute("ALTER TABLE bug_reports ADD COLUMN timestamp BIGINT");
connection.createStatement().execute("ALTER TABLE bug_reports ADD COLUMN timestamp BIGINT");
}
}
} catch (Exception e) {
Expand Down Expand Up @@ -86,25 +82,19 @@ public static long getPlayerLastLoginTimestamp(UUID playerId) {

private void addMissingTables() {
try (Connection connection = dataSource.getConnection()) {
try (ResultSet archivedResultSet = connection.getMetaData().getColumns(null, null, "player_data",
"player_id")) {
try (ResultSet archivedResultSet = connection.getMetaData().getColumns(null, null, "player_data", "player_id")) {
if (!archivedResultSet.next()) {
connection.createStatement()
.execute("CREATE TABLE IF NOT EXISTS player_data(player_id TEXT, last_login_timestamp BIGINT DEFAULT 0)");
connection.createStatement().execute("CREATE TABLE IF NOT EXISTS player_data(player_id TEXT, last_login_timestamp BIGINT DEFAULT 0)");
}
}
try (ResultSet archivedResultSet = connection.getMetaData().getColumns(null, null, "bug_reports",
"archived")) {
try (ResultSet archivedResultSet = connection.getMetaData().getColumns(null, null, "bug_reports", "archived")) {
if (!archivedResultSet.next()) {
connection.createStatement()
.execute("ALTER TABLE bug_reports ADD COLUMN archived INTEGER DEFAULT 0");
connection.createStatement().execute("ALTER TABLE bug_reports ADD COLUMN archived INTEGER DEFAULT 0");
}
}
try (ResultSet reportIdResultSet = connection.getMetaData().getColumns(null, null, "bug_reports",
"report_id")) {
try (ResultSet reportIdResultSet = connection.getMetaData().getColumns(null, null, "bug_reports", "report_id")) {
if (!reportIdResultSet.next()) {
connection.createStatement()
.execute("ALTER TABLE bug_reports ADD COLUMN report_id INT AUTO_INCREMENT PRIMARY KEY");
connection.createStatement().execute("ALTER TABLE bug_reports ADD COLUMN report_id INT AUTO_INCREMENT PRIMARY KEY");
}
}
} catch (Exception e) {
Expand All @@ -129,8 +119,7 @@ private void makeAllHeadersEqualReport_ID() {
}
newHeader.append("\n");
}
PreparedStatement statement = connection
.prepareStatement("UPDATE bug_reports SET header = ? WHERE report_id = ?");
PreparedStatement statement = connection.prepareStatement("UPDATE bug_reports SET header = ? WHERE report_id = ?");
statement.setString(1, newHeader.toString().trim());
statement.setInt(2, report_id);
statement.executeUpdate();
Expand All @@ -144,14 +133,12 @@ private void makeAllHeadersEqualReport_ID() {

private void fixReportID() {
try (Connection connection = dataSource.getConnection()) {
ResultSet resultSet = connection.createStatement()
.executeQuery("SELECT * FROM bug_reports WHERE report_id IS NULL OR report_id = 0");
ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM bug_reports WHERE report_id IS NULL OR report_id = 0");
while (resultSet.next()) {
int report_id = resultSet.getInt("report_id");
int rowNumber = resultSet.getRow();
if (report_id != rowNumber) {
PreparedStatement statement = connection
.prepareStatement("UPDATE bug_reports SET report_id = ? WHERE report_id = ?");
PreparedStatement statement = connection.prepareStatement("UPDATE bug_reports SET report_id = ? WHERE report_id = ?");
statement.setInt(1, rowNumber);
statement.setInt(2, report_id);
statement.executeUpdate();
Expand All @@ -165,7 +152,7 @@ private void fixReportID() {

}

private static void createConnection() {
public static void createConnection() {
loadConfig();
String databaseType = Objects.requireNonNull(config.getString("databaseType"));
ConfigurationSection databaseSection = Objects.requireNonNull(config.getConfigurationSection("database"));
Expand All @@ -190,11 +177,9 @@ private static void createConnection() {

public void addBugReport(String username, @NotNull UUID playerId, String world, String header, String fullMessage) {
try (Connection connection = dataSource.getConnection()) {
PreparedStatement statement = connection.prepareStatement(
"INSERT INTO bug_reports(player_id, header, message, username, world, archived, report_id, timestamp) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
PreparedStatement statement = connection.prepareStatement("INSERT INTO bug_reports(player_id, header, message, username, world, archived, report_id, timestamp) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
int report_id = 1;
ResultSet resultSet = connection.createStatement()
.executeQuery("SELECT report_id FROM bug_reports ORDER BY report_id DESC LIMIT 1");
ResultSet resultSet = connection.createStatement().executeQuery("SELECT report_id FROM bug_reports ORDER BY report_id DESC LIMIT 1");
if (resultSet.next()) {
report_id = resultSet.getInt("report_id") + 1;
}
Expand All @@ -218,8 +203,7 @@ public void addBugReport(String username, @NotNull UUID playerId, String world,
Map<UUID, List<String>> bugReports = new HashMap<>();

try (Connection connection = dataSource.getConnection()) {
PreparedStatement statement = connection
.prepareStatement("SELECT * FROM bug_reports ORDER BY report_id ASC");
PreparedStatement statement = connection.prepareStatement("SELECT * FROM bug_reports ORDER BY report_id ASC");
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
UUID playerId = UUID.fromString(resultSet.getString("player_id"));
Expand All @@ -232,14 +216,14 @@ public void addBugReport(String username, @NotNull UUID playerId, String world,
long timestamp = resultSet.getLong("timestamp");
List<String> reports = bugReports.getOrDefault(getStaticUUID(), new ArrayList<>(Collections.singletonList("DUMMY")));
reports.add(
"Username: " + username + "\n" +
"UUID: " + playerId + "\n" +
"World: " + world + "\n" +
"Full Message: " + fullMessage + "\n" +
"Header: " + header + "\n" +
"Archived: " + archived + "\n" +
"Report ID: " + report_id + "\n" +
"Timestamp: " + timestamp
"Username: " + username + "\n" +
"UUID: " + playerId + "\n" +
"World: " + world + "\n" +
"Full Message: " + fullMessage + "\n" +
"Header: " + header + "\n" +
"Archived: " + archived + "\n" +
"Report ID: " + report_id + "\n" +
"Timestamp: " + timestamp
);
bugReports.put(getStaticUUID(), reports);
}
Expand All @@ -253,7 +237,7 @@ public void addBugReport(String username, @NotNull UUID playerId, String world,
return bugReports;
}

static @NotNull UUID getStaticUUID() {
public static @NotNull UUID getStaticUUID() {
return UUID.fromString("00000000-0000-0000-0000-000000000000");
}

Expand Down Expand Up @@ -290,8 +274,7 @@ private static void connectLocal() {

private static void createTables() {
try (Connection connection = dataSource.getConnection()) {
connection.createStatement().execute(
"CREATE TABLE IF NOT EXISTS bug_reports(rowid INTEGER, player_id TEXT, header TEXT, message TEXT, username TEXT, world TEXT, archived INTEGER DEFAULT 0, report_id INTEGER, timestamp BIGINT)");
connection.createStatement().execute("CREATE TABLE IF NOT EXISTS bug_reports(rowid INTEGER, player_id TEXT, header TEXT, message TEXT, username TEXT, world TEXT, archived INTEGER DEFAULT 0, report_id INTEGER, timestamp BIGINT)");
} catch (Exception e) {
plugin.getLogger().severe("Failed to create tables.");
plugin.getLogger().severe(e.getMessage());
Expand All @@ -300,21 +283,14 @@ private static void createTables() {

public void updateBugReportHeader(UUID playerId, int reportIndex) {
try (Connection connection = dataSource.getConnection()) {
PreparedStatement statement = connection
.prepareStatement("UPDATE bug_reports SET header = ? WHERE report_id = ?");
PreparedStatement statement = connection.prepareStatement("UPDATE bug_reports SET header = ? WHERE report_id = ?");
String existingHeader = bugReports.get(playerId).get(reportIndex);

String[] lines = existingHeader.split("\n");
StringBuilder newHeader = new StringBuilder();
for (String line : lines) {
if (line.startsWith("hasBeenRead:")) {
newHeader.append("hasBeenRead: 1");
} else {
newHeader.append(line);
}
newHeader.append("\n");
}

newHeader.append(line.startsWith("hasBeenRead:") ? "hasBeenRead: 1" : line).append("\n");
}
statement.setString(1, newHeader.toString().trim());
statement.setInt(2, reportIndex);
statement.executeUpdate();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/leon/bugreport/BugReportLanguage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Arrays;
Expand All @@ -17,7 +18,7 @@ public BugReportLanguage(Plugin plugin, String languageFilePath) {
loadLanguageTexts(plugin, languageFilePath);
}

static void loadLanguageTexts(Plugin plugin, String languageFilePath) {
static void loadLanguageTexts(@NotNull Plugin plugin, String languageFilePath) {
File languageFile = new File(plugin.getDataFolder(), languageFilePath);
if (!languageFile.exists()) {
plugin.saveResource(languageFilePath, false);
Expand All @@ -41,7 +42,7 @@ public static String getEnglishVersionFromLanguage(String displayName) {
"Enable Discord Webhook", "Enable Bug Report Notifications", "Enable Category Selection",
"Set Max Reports Per Player", "Set Language",
"On", "Off", "Language",
"Cancelled", "Cancel", "Archive", "Delete", "Other Settings",
"Cancelled", "Cancel", "Archive", "Unarchive", "Delete", "Other Settings",
"Enable Title Message", "Enable Player Heads"
};

Expand Down
Loading

0 comments on commit 9213641

Please sign in to comment.