Resolve player names exactly in commands

This commit is contained in:
2026-09-26 22:46:45 -07:00
parent 81b34862b4
commit c127e45f8d
5 changed files with 31 additions and 7 deletions

View File

@@ -15,7 +15,7 @@
| MET-011 | Done | Refactor event listeners and registration to use Listener, @EventHandler, and the modern plugin manager API. | | 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-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-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-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-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. | | 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. |

View File

@@ -1090,11 +1090,29 @@ public class MetropolisPlugin extends JavaPlugin {
} }
public Player getPlayer(String name) { 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){ 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) { public String teleportPlayerToPlot(Player player, Plot plot) {

View File

@@ -28,7 +28,7 @@ public class MetropolisHomeEvictCommand implements CommandExecutor {
playerName = args[0]; playerName = args[0];
} }
OfflinePlayer player = _plugin.getServer().getOfflinePlayer(playerName); OfflinePlayer player = _plugin.getOfflinePlayer(playerName);
if(player == null){ if(player == null){
sender.sendMessage(String.format("The requested player {%s}does not appear to exist.", playerName)); sender.sendMessage(String.format("The requested player {%s}does not appear to exist.", playerName));
return false; return false;

View File

@@ -3,6 +3,7 @@ package com.majinnaibu.bukkitplugins.metropolis.commands;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.OfflinePlayer;
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin; import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
@@ -20,7 +21,12 @@ public class MetropolisHomeGenerateCommand implements CommandExecutor {
return false; 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]); sender.sendMessage("[Metropolis] Home generated for " + args[0]);

View File

@@ -24,7 +24,7 @@ public class MetropolisHomeGoCommand implements CommandExecutor {
if(args.length >= 1){ if(args.length >= 1){
if(player.hasPermission("")){ if(player.hasPermission("")){
player = _plugin.getServer().getPlayer(args[0]); player = _plugin.getPlayer(args[0]);
if(player == null){ if(player == null){
sender.sendMessage(String.format("Unable to find player %s", args[0])); sender.sendMessage(String.format("Unable to find player %s", args[0]));
@@ -37,7 +37,7 @@ public class MetropolisHomeGoCommand implements CommandExecutor {
} }
}else{ }else{
if(args.length >= 1){ if(args.length >= 1){
player = _plugin.getServer().getPlayer(args[0]); player = _plugin.getPlayer(args[0]);
if(player == null){ if(player == null){
sender.sendMessage(String.format("Unable to find player %s", args[0])); sender.sendMessage(String.format("Unable to find player %s", args[0]));