From 19de3c8097de88965f51dbe2c30fdff4572a9719 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Mon, 14 Jul 2025 07:59:33 -0700 Subject: [PATCH] Updates logging and message generation to use modern methods. --- TODO.md | 10 ++--- build.gradle | 4 +- .../plugins/mobscores/MobScoresPlugin.java | 40 +++++++++++-------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/TODO.md b/TODO.md index fe0772c..b9131ab 100644 --- a/TODO.md +++ b/TODO.md @@ -7,8 +7,8 @@ - [x] Remove Maven-specific files (pom.xml, .mvn/ directory, Maven wrapper scripts) and Eclipse-specific files (.classpath, .project, .settings/) if present. - [x] Update .gitignore to add Gradle-specific ignores and remove Maven/Eclipse-specific ignores. - [x] Ensure plugin.yml is present in src/main/resources and update for PaperMC compatibility (api-version, commands, required fields). -- [ ] Refactor all logger usage to use getLogger() from JavaPlugin. -- [ ] Refactor all event listeners to use the modern event system (Listener interface, @EventHandler, registerEvents). +- [x] Refactor all logger usage to use getLogger() from JavaPlugin. +- [x] Refactor all event listeners to use the modern event system (Listener interface, @EventHandler, registerEvents). - [x] Replace use of org.bukkit.util.config.Configuration with the modern configuration API (getConfig(), saveConfig(), etc.). - [ ] Update score table to use Bukkit entity types or enums instead of CraftBukkit class names. - [ ] If storing player scores, refactor to use UUID as the key instead of Player or String. @@ -16,9 +16,9 @@ - [ ] Address any bugs or incompatibilities found during testing on a modern server. _(Depends on: build and test)_ - [ ] Update README.md and CONTRIBUTING.md with new build, usage, and development instructions. _(Depends on: bugfixes)_ - [ ] (Optional) Add new features, quality-of-life improvements, automated tests, or CI configuration. _(Depends on: docs update)_ -- [ ] Update MobScores to depend on the latest version of the ScoreKeeper plugin (update dependency in build.gradle and plugin.yml as needed). +- [x] Update MobScores to depend on the latest version of the ScoreKeeper plugin (update dependency in build.gradle and plugin.yml as needed). - [ ] Test MobScores with the latest ScoreKeeper to ensure score tracking, awarding, and all integration points work as expected (including with players who have changed names). - [x] Refactor MobDeathListener and PlayerConnectListener to implement Listener interface and use @EventHandler annotations instead of extending EntityListener/PlayerListener. - [x] Update event registration in MobScoresPlugin to use getServer().getPluginManager().registerEvents(...). -- [ ] Replace all usage of org.bukkit.util.config.Configuration with the modern Bukkit configuration API (getConfig(), saveConfig(), reloadConfig(), etc.). -- [ ] Remove or refactor any code using deprecated or removed Bukkit/Spigot/Paper APIs that are not available in the modern Paper API. +- [x] Replace all usage of org.bukkit.util.config.Configuration with the modern Bukkit configuration API (getConfig(), saveConfig(), reloadConfig(), etc.). +- [x] Remove or refactor any code using deprecated or removed Bukkit/Spigot/Paper APIs that are not available in the modern Paper API. diff --git a/build.gradle b/build.gradle index 803179a..31a184d 100644 --- a/build.gradle +++ b/build.gradle @@ -16,8 +16,10 @@ repositories { } dependencies { - compileOnly 'io.papermc.paper:paper-api:1.21.7-R0.1-SNAPSHOT' compileOnly 'com.majinnaibu.minecraft.plugins:ScoreKeeper:0.2.1-SNAPSHOT' + compileOnly 'io.papermc.paper:paper-api:1.21.7-R0.1-SNAPSHOT' + compileOnly 'net.kyori:adventure-api:4.14.0' + testImplementation libs.junit.junit } diff --git a/src/main/java/com/majinnaibu/minecraft/plugins/mobscores/MobScoresPlugin.java b/src/main/java/com/majinnaibu/minecraft/plugins/mobscores/MobScoresPlugin.java index 9541302..1ecde28 100644 --- a/src/main/java/com/majinnaibu/minecraft/plugins/mobscores/MobScoresPlugin.java +++ b/src/main/java/com/majinnaibu/minecraft/plugins/mobscores/MobScoresPlugin.java @@ -21,13 +21,13 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; -import java.util.logging.Logger; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Zombie; -import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -40,10 +40,11 @@ public class MobScoresPlugin extends JavaPlugin { private Map _scoreTable = new HashMap(); private ScoreKeeperPlugin _scoreKeeper = null; - private final String _logStart = "[" + ChatColor.AQUA + "MobScores" + ChatColor.WHITE + "] "; - - public final Logger log = Logger.getLogger("Minecraft"); - + private final String _logPrefix = "[MobScores] "; + private final Component _messagePrefix = Component.text("[") + .append(Component.text("MobScores").color(NamedTextColor.AQUA)) + .append(Component.text("] ").color(NamedTextColor.WHITE)); + @Override public void onDisable() { getConfig().set("ScoreTable", _scoreTable); @@ -80,8 +81,7 @@ public class MobScoresPlugin extends JavaPlugin { pm.registerEvents(new MobDeathListener(this), this); pm.registerEvents(new PlayerConnectListener(this), this); - PluginDescriptionFile pdFile = this.getDescription(); - log.info(pdFile.getName() + " version " + pdFile.getVersion() + " is enabled!"); + logInfo(getPluginMeta().getName() + " version " + getPluginMeta().getVersion() + " is enabled!"); } private HashMap getDefaultScoreTable() { @@ -115,7 +115,7 @@ public class MobScoresPlugin extends JavaPlugin { } public void awardScore(Entity entity) { - + if(_claimedMobs.containsKey(entity)){ Class scoreClass = entity.getClass(); String className = scoreClass.getName(); @@ -125,11 +125,11 @@ public class MobScoresPlugin extends JavaPlugin { _scoreKeeper.addScore(player, score); }else{ - log.warning("[MobScores] Unable to award score for {" + className + "}"); + logWarning("Unable to award score for {" + className + "}"); Set keys = _scoreTable.keySet(); String str = null; for(Iterator i = keys.iterator(); i.hasNext(); str = i.next()){ - log.info("{" + str + "}"); + logInfo("{" + str + "}"); } } } @@ -142,15 +142,23 @@ public class MobScoresPlugin extends JavaPlugin { if(pair.getValue() != 0){ String key = pair.getKey(); if(key.startsWith("org.bukkit.craftbukkit.entity.Craft")){ - player.sendMessage(_logStart + key.substring(35) + " = " + pair.getValue().toString()); + sendPlayerMessage(player, key.substring(35) + " = " + pair.getValue().toString()); }else{ - player.sendMessage(_logStart + key + " = " + pair.getValue().toString()); + sendPlayerMessage(player, key + " = " + pair.getValue().toString()); } } } } - public void logInfo(String string) { - log.info(_logStart + string); + public void sendPlayerMessage(Player player, String message) { + player.sendMessage(_messagePrefix.append(Component.text(message))); + } + + public void logInfo(String messag) { + getLogger().info(_logPrefix + messag); + } + + public void logWarning(String message) { + getLogger().warning(_logPrefix + message); } }