diff --git a/TODO.md b/TODO.md index 6b6c286..9c4c25e 100644 --- a/TODO.md +++ b/TODO.md @@ -13,7 +13,7 @@ | MS-09 | Done | Refactor all event listeners to use the modern event system (Listener interface, @EventHandler, registerEvents). | MS-10 | Done | Replace use of org.bukkit.util.config.Configuration with the modern configuration API (getConfig(), saveConfig(), etc.). | MS-11 | Done | Update score table to use Bukkit entity types or enums instead of CraftBukkit class names. -| MS-12 | Ready | If storing player scores, refactor to use UUID as the key instead of Player or String. +| MS-12 | Done | If storing player scores, refactor to use UUID as the key instead of Player or String. | MS-13 | Done | Build the plugin with Gradle (./gradlew build) and test on a modern Paper server using the provided bash scripts. | MS-14 | Done | Address any bugs or incompatibilities found during testing on a modern server. | MS-15 | Ready | Update README.md and CONTRIBUTING.md with new build, usage, and development instructions. _(Depends on: bugfixes)_ 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 354e2a0..47bff12 100644 --- a/src/main/java/com/majinnaibu/minecraft/plugins/mobscores/MobScoresPlugin.java +++ b/src/main/java/com/majinnaibu/minecraft/plugins/mobscores/MobScoresPlugin.java @@ -20,6 +20,7 @@ package com.majinnaibu.minecraft.plugins.mobscores; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.UUID; import java.util.logging.Level; import net.kyori.adventure.text.Component; @@ -37,7 +38,7 @@ import com.majinnaibu.minecraft.plugins.mobscores.listeners.PlayerConnectListene import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin; public class MobScoresPlugin extends JavaPlugin { - private Map _claimedMobs = new HashMap(); + private Map _claimedMobs = new HashMap(); private Map _scoreTable = new HashMap(); private ScoreKeeperPlugin _scoreKeeper = null; @@ -113,16 +114,20 @@ public class MobScoresPlugin extends JavaPlugin { public void claimMob(Entity entity, Player damager) { if(entity instanceof Zombie){ - _claimedMobs.put((Zombie)entity, damager); + _claimedMobs.put(entity.getUniqueId(), damager.getUniqueId()); } } public void awardScore(Entity entity) { - - if(_claimedMobs.containsKey(entity)){ + UUID playerId = _claimedMobs.remove(entity.getUniqueId()); + if(playerId != null){ EntityType type = entity.getType(); if (_scoreTable.containsKey(type)) { - Player player = _claimedMobs.get(entity); + Player player = getServer().getPlayer(playerId); + if (player == null) { + logWarning("Unable to award score because the credited player is offline."); + return; + } int score = _scoreTable.get(type); _scoreKeeper.addScore(player, score); } else {