Resolve player names exactly in commands
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
@@ -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]));
|
||||
|
||||
Reference in New Issue
Block a user