Key mob claimant tracking by UUID

This commit is contained in:
2026-09-26 18:41:01 -07:00
parent af81796866
commit d95c4cf418
2 changed files with 11 additions and 6 deletions

View File

@@ -13,7 +13,7 @@
| MS-09 | Done | Refactor all event listeners to use the modern event system (Listener interface, @EventHandler, registerEvents). | 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-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-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-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-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)_ | MS-15 | Ready | Update README.md and CONTRIBUTING.md with new build, usage, and development instructions. _(Depends on: bugfixes)_

View File

@@ -20,6 +20,7 @@ package com.majinnaibu.minecraft.plugins.mobscores;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import net.kyori.adventure.text.Component; 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; import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
public class MobScoresPlugin extends JavaPlugin { public class MobScoresPlugin extends JavaPlugin {
private Map<Entity, Player> _claimedMobs = new HashMap<Entity, Player>(); private Map<UUID, UUID> _claimedMobs = new HashMap<UUID, UUID>();
private Map<EntityType, Integer> _scoreTable = new HashMap<EntityType, Integer>(); private Map<EntityType, Integer> _scoreTable = new HashMap<EntityType, Integer>();
private ScoreKeeperPlugin _scoreKeeper = null; private ScoreKeeperPlugin _scoreKeeper = null;
@@ -113,16 +114,20 @@ public class MobScoresPlugin extends JavaPlugin {
public void claimMob(Entity entity, Player damager) { public void claimMob(Entity entity, Player damager) {
if(entity instanceof Zombie){ if(entity instanceof Zombie){
_claimedMobs.put((Zombie)entity, damager); _claimedMobs.put(entity.getUniqueId(), damager.getUniqueId());
} }
} }
public void awardScore(Entity entity) { public void awardScore(Entity entity) {
UUID playerId = _claimedMobs.remove(entity.getUniqueId());
if(_claimedMobs.containsKey(entity)){ if(playerId != null){
EntityType type = entity.getType(); EntityType type = entity.getType();
if (_scoreTable.containsKey(type)) { 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); int score = _scoreTable.get(type);
_scoreKeeper.addScore(player, score); _scoreKeeper.addScore(player, score);
} else { } else {