From c127e45f8d4259067aaacb8f429edb882b25d09f Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Sat, 26 Sep 2026 22:46:45 -0700 Subject: [PATCH] Resolve player names exactly in commands --- TODO.md | 2 +- .../metropolis/MetropolisPlugin.java | 22 +++++++++++++++++-- .../commands/MetropolisHomeEvictCommand.java | 2 +- .../MetropolisHomeGenerateCommand.java | 8 ++++++- .../commands/MetropolisHomeGoCommand.java | 4 ++-- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/TODO.md b/TODO.md index f7fb203..b35ed42 100644 --- a/TODO.md +++ b/TODO.md @@ -15,7 +15,7 @@ | MET-011 | Done | Refactor event listeners and registration to use Listener, @EventHandler, and the modern plugin manager API. | | MET-012 | Done | Replace deprecated configuration APIs with the modern Bukkit/Paper configuration API, including load, save, and reload behavior. | | MET-013 | Done | Replace Player-keyed storage with UUID-based storage wherever player identity is persisted or tracked. | -| MET-014 | Ready | Review player lookup logic and use exact or otherwise explicit name-matching behavior where appropriate. | +| MET-014 | Done | Review player lookup logic and use exact or otherwise explicit name-matching behavior where appropriate. | | MET-015 | Ready | Refactor remaining code that uses deprecated or removed Bukkit, Spigot, or Paper APIs so it is compatible with the target Paper API. | | MET-016 | Ready | Add fast unit tests for plot and home allocation, reservation validation, player lookup and UUID-based ownership, configuration persistence, command validation, and event behavior. Keep domain rules independent of a running Minecraft server and mock external plugin boundaries as needed. | | MET-017 | Ready | Add a separate Gradle `integrationTest` source set/task for tests requiring an actual Paper server and compatible WorldGuard/WorldEdit plugins. Verify plugin loading, command registration and dispatch, region-backed reservations and home allocation, and persistence across a server restart. Run it only when explicitly requested; keep it out of the normal `test` and `build` tasks. | diff --git a/src/main/java/com/majinnaibu/bukkitplugins/metropolis/MetropolisPlugin.java b/src/main/java/com/majinnaibu/bukkitplugins/metropolis/MetropolisPlugin.java index 5b8b543..763dd61 100644 --- a/src/main/java/com/majinnaibu/bukkitplugins/metropolis/MetropolisPlugin.java +++ b/src/main/java/com/majinnaibu/bukkitplugins/metropolis/MetropolisPlugin.java @@ -1090,11 +1090,29 @@ public class MetropolisPlugin extends JavaPlugin { } public Player getPlayer(String name) { - return getServer().getPlayer(name); + Player player = getServer().getPlayerExact(name); + if (player != null) { + return player; + } + for (Player onlinePlayer : getServer().getOnlinePlayers()) { + if (onlinePlayer.getName().equalsIgnoreCase(name)) { + return onlinePlayer; + } + } + return null; } public OfflinePlayer getOfflinePlayer(String name){ - return getServer().getOfflinePlayer(name); + Player onlinePlayer = getPlayer(name); + if (onlinePlayer != null) { + return onlinePlayer; + } + for (OfflinePlayer offlinePlayer : getServer().getOfflinePlayers()) { + if (name.equalsIgnoreCase(offlinePlayer.getName())) { + return offlinePlayer; + } + } + return null; } public String teleportPlayerToPlot(Player player, Plot plot) { diff --git a/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeEvictCommand.java b/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeEvictCommand.java index 1b73687..6f2b35b 100644 --- a/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeEvictCommand.java +++ b/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeEvictCommand.java @@ -28,7 +28,7 @@ public class MetropolisHomeEvictCommand implements CommandExecutor { playerName = args[0]; } - OfflinePlayer player = _plugin.getServer().getOfflinePlayer(playerName); + OfflinePlayer player = _plugin.getOfflinePlayer(playerName); if(player == null){ sender.sendMessage(String.format("The requested player {%s}does not appear to exist.", playerName)); return false; diff --git a/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeGenerateCommand.java b/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeGenerateCommand.java index 8ba27c4..892601a 100644 --- a/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeGenerateCommand.java +++ b/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeGenerateCommand.java @@ -3,6 +3,7 @@ package com.majinnaibu.bukkitplugins.metropolis.commands; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.OfflinePlayer; import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin; @@ -20,7 +21,12 @@ public class MetropolisHomeGenerateCommand implements CommandExecutor { return false; } - _plugin.generateHome(args[0]); + OfflinePlayer player = _plugin.getOfflinePlayer(args[0]); + if (player == null) { + sender.sendMessage("Unable to find player " + args[0]); + return false; + } + _plugin.generateHome(player); sender.sendMessage("[Metropolis] Home generated for " + args[0]); diff --git a/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeGoCommand.java b/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeGoCommand.java index 3c12f4b..44a32e2 100644 --- a/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeGoCommand.java +++ b/src/main/java/com/majinnaibu/bukkitplugins/metropolis/commands/MetropolisHomeGoCommand.java @@ -24,7 +24,7 @@ public class MetropolisHomeGoCommand implements CommandExecutor { if(args.length >= 1){ if(player.hasPermission("")){ - player = _plugin.getServer().getPlayer(args[0]); + player = _plugin.getPlayer(args[0]); if(player == null){ sender.sendMessage(String.format("Unable to find player %s", args[0])); @@ -37,7 +37,7 @@ public class MetropolisHomeGoCommand implements CommandExecutor { } }else{ if(args.length >= 1){ - player = _plugin.getServer().getPlayer(args[0]); + player = _plugin.getPlayer(args[0]); if(player == null){ sender.sendMessage(String.format("Unable to find player %s", args[0]));