diff --git a/CHANGELOG.md b/CHANGELOG.md
index c61b10b..57a5611 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
# Plugin Changelog
+# 3.0.4 - Logging Is A Feature
+
+- Added a lot of logging when in debug mode.
+
+This logging was meant to help find an issue... then the issue fixed itself. The logging could still be helpful in finding future issues, though.
+
# 3.0.3 - Small Patches
- Fixed bug with messages on `/nickother`.
diff --git a/pom.xml b/pom.xml
index 943252e..bdfce38 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
dev.majek
hexnicks
- 3.0.3
+ 3.0.4
jar
HexNicks
@@ -50,7 +50,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.4.0
+ 3.4.1
attach-javadocs
@@ -186,7 +186,7 @@
net.essentialsx
EssentialsX
- 2.19.4
+ 2.19.6
provided
diff --git a/src/main/java/dev/majek/hexnicks/HexNicks.java b/src/main/java/dev/majek/hexnicks/HexNicks.java
index 1aabdb2..cbd8d3f 100644
--- a/src/main/java/dev/majek/hexnicks/HexNicks.java
+++ b/src/main/java/dev/majek/hexnicks/HexNicks.java
@@ -366,6 +366,7 @@ public void setNick(@NotNull Player player, @NotNull Component nick) {
* @param player the player whose nickname to remove
*/
public void removeNick(@NotNull Player player) {
+ logging.debug("Removing " + player.getName() + "'s nickname.");
this.nickMap.remove(player.getUniqueId());
player.displayName(Component.text(player.getName()));
if (config.TAB_NICKS) {
diff --git a/src/main/java/dev/majek/hexnicks/event/PlayerJoin.java b/src/main/java/dev/majek/hexnicks/event/PlayerJoin.java
index c880a9e..d848ede 100644
--- a/src/main/java/dev/majek/hexnicks/event/PlayerJoin.java
+++ b/src/main/java/dev/majek/hexnicks/event/PlayerJoin.java
@@ -45,9 +45,12 @@ public void onPlayerJoin(PlayerJoinEvent event) {
// Set the joining player's nickname to their stored nickname if they have one
HexNicks.storage().hasNick(player.getUniqueId()).whenCompleteAsync((aBoolean, throwable) -> {
if (aBoolean) {
+ HexNicks.logging().debug("Player " + player.getName() + " joined and has nickname, setting...");
HexNicks.storage().getNick(player.getUniqueId()).whenCompleteAsync((component, throwable1) ->
HexNicks.core().setNick(player, component)
);
+ } else {
+ HexNicks.logging().debug("Player " + player.getName() + " joined and has no nickname.");
}
});
diff --git a/src/main/java/dev/majek/hexnicks/storage/SqlManager.java b/src/main/java/dev/majek/hexnicks/storage/SqlManager.java
index e15e8f3..5e83b85 100755
--- a/src/main/java/dev/majek/hexnicks/storage/SqlManager.java
+++ b/src/main/java/dev/majek/hexnicks/storage/SqlManager.java
@@ -64,6 +64,7 @@ public void connect() throws SQLException {
if (!isConnected()) {
connection = DriverManager.getConnection("jdbc:mysql://" +
host + ":" + port + "/" + database + "?useSSL=" + useSSL + "&autoReconnect=" + autoReconnect, username, password);
+ HexNicks.logging().debug("Connecting to sql database '" + database + "'...");
}
Bukkit.getScheduler().scheduleSyncRepeatingTask(HexNicks.core(), () -> HexNicks.storage().updateNicks(), 200L, updateInterval * 20L);
}
@@ -74,6 +75,7 @@ public void connect() throws SQLException {
public void disconnect() {
if (isConnected()) {
try {
+ HexNicks.logging().debug("Disconnecting from sql database...");
connection.close();
} catch (SQLException e) {
e.printStackTrace();
@@ -94,12 +96,14 @@ public Connection getConnection() {
* Create the MySQL table if it doesn't already exist.
*/
public void createTable() {
+ HexNicks.logging().debug("Creating sql database table...");
PreparedStatement ps;
try {
ps = HexNicks.sql().getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS " +
"nicknameTable (uniqueId VARCHAR(100),nickname VARCHAR(10000),PRIMARY KEY (uniqueId))");
ps.executeUpdate();
} catch (SQLException ex) {
+ HexNicks.logging().error("Error creating table in database", ex);
ex.printStackTrace();
}
}
diff --git a/src/main/java/dev/majek/hexnicks/storage/SqlStorage.java b/src/main/java/dev/majek/hexnicks/storage/SqlStorage.java
index 63e393f..7b4a8fd 100644
--- a/src/main/java/dev/majek/hexnicks/storage/SqlStorage.java
+++ b/src/main/java/dev/majek/hexnicks/storage/SqlStorage.java
@@ -30,7 +30,6 @@
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
-
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
@@ -46,6 +45,7 @@ public class SqlStorage implements StorageMethod {
@Override
public CompletableFuture hasNick(@NotNull UUID uuid) {
+ HexNicks.logging().debug("Firing SqlStorage#hasNick for uuid: " + uuid);
return CompletableFuture.supplyAsync(() -> {
try {
PreparedStatement ps = HexNicks.sql().getConnection()
@@ -57,9 +57,11 @@ public CompletableFuture hasNick(@NotNull UUID uuid) {
nickname = resultSet.getString("nickname");
return nickname != null;
} else {
+ HexNicks.logging().debug("No nickname found in database for uuid: " + uuid);
return false;
}
} catch (SQLException ex) {
+ HexNicks.logging().error("Error with SqlStorage#hasNick", ex);
ex.printStackTrace();
return false;
}
@@ -69,6 +71,7 @@ public CompletableFuture hasNick(@NotNull UUID uuid) {
@Override
@SuppressWarnings("ConstantConditions")
public CompletableFuture getNick(@NotNull UUID uuid) {
+ HexNicks.logging().debug("Firing SqlStorage#getNick for uuid: " + uuid);
return CompletableFuture.supplyAsync(() -> {
try {
PreparedStatement ps = HexNicks.sql().getConnection()
@@ -78,17 +81,23 @@ public CompletableFuture getNick(@NotNull UUID uuid) {
String nickname;
if (resultSet.next()) {
nickname = resultSet.getString("nickname");
+ HexNicks.logging().debug("Nickname found for uuid: " + uuid);
return GsonComponentSerializer.gson().deserialize(nickname);
+ } else {
+ HexNicks.logging().debug("No nickname found in database for uuid: " + uuid);
}
} catch (SQLException ex) {
+ HexNicks.logging().error("Error with SqlStorage#getNick", ex);
ex.printStackTrace();
}
+ HexNicks.logging().debug("Returning player's username as nickname");
return Component.text(Bukkit.getOfflinePlayer(uuid).getName());
});
}
@Override
public void removeNick(@NotNull UUID uuid) {
+ HexNicks.logging().debug("Firing SqlStorage#removeNick...");
Bukkit.getScheduler().runTaskAsynchronously(HexNicks.core(), () -> {
try {
PreparedStatement ps = HexNicks.sql().getConnection()
@@ -96,6 +105,7 @@ public void removeNick(@NotNull UUID uuid) {
ps.setString(1, uuid.toString());
ps.executeUpdate();
} catch (SQLException ex) {
+ HexNicks.logging().error("Error with SqlStorage#removeNick", ex);
ex.printStackTrace();
}
});
@@ -103,16 +113,19 @@ public void removeNick(@NotNull UUID uuid) {
@Override
public void saveNick(@NotNull Player player, @NotNull Component nickname) {
+ HexNicks.logging().debug("Firing SqlStorage#saveNick...");
Bukkit.getScheduler().runTaskAsynchronously(HexNicks.core(), () ->
hasNick(player.getUniqueId()).whenCompleteAsync((hasNick, throwable) -> {
try {
PreparedStatement update;
if (hasNick) {
+ HexNicks.logging().debug("Has nick already, updating table...");
update = HexNicks.sql().getConnection()
.prepareStatement("UPDATE nicknameTable SET nickname=? WHERE uniqueId=?");
update.setString(1, GsonComponentSerializer.gson().serialize(nickname));
update.setString(2, player.getUniqueId().toString());
} else {
+ HexNicks.logging().debug("No nick found, inserting into table...");
update = HexNicks.sql().getConnection()
.prepareStatement("INSERT INTO `nicknameTable` (`uniqueId`, `nickname`) VALUES (?, ?);");
update.setString(1, player.getUniqueId().toString());
@@ -120,6 +133,7 @@ public void saveNick(@NotNull Player player, @NotNull Component nickname) {
}
update.executeUpdate();
} catch (SQLException ex) {
+ HexNicks.logging().error("Error with SqlStorage#saveNick", ex);
ex.printStackTrace();
}
})
@@ -128,6 +142,7 @@ public void saveNick(@NotNull Player player, @NotNull Component nickname) {
@Override
public CompletableFuture nicknameExists(@NotNull Component nickname, boolean strict, @NotNull Player player) {
+ HexNicks.logging().debug("Firing SqlStorage#nicknameExists...");
return CompletableFuture.supplyAsync(() -> {
try {
// Add all player names except the player setting the nickname
diff --git a/src/main/java/dev/majek/hexnicks/storage/StorageMethod.java b/src/main/java/dev/majek/hexnicks/storage/StorageMethod.java
index efb8670..9fbfffe 100644
--- a/src/main/java/dev/majek/hexnicks/storage/StorageMethod.java
+++ b/src/main/java/dev/majek/hexnicks/storage/StorageMethod.java
@@ -71,6 +71,7 @@ public interface StorageMethod {
* Update the nickname of all online players from storage.
*/
default void updateNicks() {
+ HexNicks.logging().debug("Firing StorageMethod#updateNicks...");
for (Player player : Bukkit.getOnlinePlayers()) {
hasNick(player.getUniqueId()).whenCompleteAsync((aBoolean, throwable) -> {
if (aBoolean) {