Tracks player scores by player UUID instead of name.

This commit is contained in:
Tom Hicks
2025-07-14 01:11:37 -07:00
parent 114f935522
commit 69686d18fd
2 changed files with 11 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
# Migration TODOs for Paper Modernization
- [ ] Switch all player score storage to use UUID instead of Player as the key
- [x] Switch all player score storage to use UUID instead of Player as the key
- [ ] Update logger usage to use getLogger() from JavaPlugin
- [ ] Remove or modernize any old/deprecated event registration (use @EventHandler and registerEvents)
- [ ] Review and update player lookup logic to use getPlayerExact or handle case sensitivity

View File

@@ -2,6 +2,7 @@ package com.majinnaibu.minecraft.plugins.scorekeeper;
import java.util.HashMap;
import java.util.logging.Logger;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
@@ -14,7 +15,7 @@ import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreResetCommand;
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreSubtractCommand;
public class ScoreKeeperPlugin extends JavaPlugin {
private final HashMap<Player, Integer> _playerScores = new HashMap<Player, Integer>();
private final HashMap<UUID, Integer> _playerScores = new HashMap<UUID, Integer>();
public final Logger log = Logger.getLogger("Minecraft");
@@ -41,21 +42,24 @@ public class ScoreKeeperPlugin extends JavaPlugin {
}
public int getPlayerScore(Player player) {
if(!_playerScores.containsKey(player)){
_playerScores.put(player, 0);
UUID uuid = player.getUniqueId();
if(!_playerScores.containsKey(uuid)){
_playerScores.put(uuid, 0);
}
return _playerScores.get(player);
return _playerScores.get(uuid);
}
public void addScore(Player player, int amount) {
UUID uuid = player.getUniqueId();
int score = getPlayerScore(player);
_playerScores.put(player, score + amount);
_playerScores.put(uuid, score + amount);
}
public void subtractScore(Player player, int amount) {
UUID uuid = player.getUniqueId();
int score = getPlayerScore(player);
_playerScores.put(player, score - amount);
_playerScores.put(uuid, score - amount);
}
public void resetPlayerScore(Player targetPlayer) {