Updates logging and message generation to use modern methods.

This commit is contained in:
Tom Hicks
2025-07-14 07:59:33 -07:00
parent b91b28691d
commit 19de3c8097
3 changed files with 32 additions and 22 deletions

10
TODO.md
View File

@@ -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.

View File

@@ -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
}

View File

@@ -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,9 +40,10 @@ public class MobScoresPlugin extends JavaPlugin {
private Map<String, Integer> _scoreTable = new HashMap<String, Integer>();
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() {
@@ -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<String, Integer> getDefaultScoreTable() {
@@ -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<String> keys = _scoreTable.keySet();
String str = null;
for(Iterator<String> 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);
}
}