[Bleeding] Remove player online check through PlayerNotFoundException

getPlayer(String) now returns null when the player could not be found
This commit is contained in:
Jerom van der Sar 2014-04-26 13:55:24 +02:00
parent 8a9dfca6d3
commit d31ad2e9fc
34 changed files with 189 additions and 290 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Sat Apr 26 13:10:03 CEST 2014 #Sat Apr 26 13:54:24 CEST 2014
build.number=804 build.number=805

View File

@ -113,18 +113,15 @@ public class Command_adminworld extends TFM_Command
if ("add".equalsIgnoreCase(args[1])) if ("add".equalsIgnoreCase(args[1]))
{ {
Player player; final Player player = getPlayer(args[2]);
try
if (player == null)
{ {
player = getPlayer(args[2]); sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true; return true;
} }
if (player != null && TFM_AdminWorld.getInstance().addGuest(player, sender_p)) if (TFM_AdminWorld.getInstance().addGuest(player, sender_p))
{ {
TFM_Util.adminAction(sender.getName(), "AdminWorld guest added: " + player.getName(), false); TFM_Util.adminAction(sender.getName(), "AdminWorld guest added: " + player.getName(), false);
} }

View File

@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -36,14 +37,11 @@ public class Command_blockcmd extends TFM_Command
return true; return true;
} }
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
playerMsg(ex.getMessage());
return true; return true;
} }

View File

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -47,14 +48,11 @@ public class Command_cage extends TFM_Command
return true; return true;
} }
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true; return true;
} }

View File

@ -1,6 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Minecart; import org.bukkit.entity.Minecart;
@ -17,13 +18,12 @@ public class Command_cartsit extends TFM_Command
if (args.length == 1) if (args.length == 1)
{ {
try
{
targetPlayer = getPlayer(args[0]); targetPlayer = getPlayer(args[0]);
}
catch (PlayerNotFoundException ex) if (targetPlayer == null)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
return true; return true;
} }
} }

View File

@ -54,13 +54,12 @@ public class Command_creative extends TFM_Command
return true; return true;
} }
try
{
player = getPlayer(args[0]); player = getPlayer(args[0]);
}
catch (PlayerNotFoundException ex) if (player == null)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
return true; return true;
} }

View File

@ -1,10 +1,10 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Ban; import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager; import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -25,14 +25,11 @@ public class Command_doom extends TFM_Command
return false; return false;
} }
final Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true; return true;
} }

View File

@ -19,14 +19,12 @@ public class Command_findip extends TFM_Command
return false; return false;
} }
final Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]);
} playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND);
catch (PlayerNotFoundException ex)
{
playerMsg(ex.getMessage());
return true; return true;
} }

View File

@ -81,14 +81,11 @@ public class Command_fr extends TFM_Command
} }
else else
{ {
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED);
}
catch (PlayerNotFoundException ex)
{
playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;
} }

View File

@ -1,8 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker; import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -19,14 +19,11 @@ public class Command_gcmd extends TFM_Command
return false; return false;
} }
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true; return true;
} }

View File

@ -52,13 +52,11 @@ public class Command_glist extends TFM_Command
String username; String username;
final List<String> ips = new ArrayList<String>(); final List<String> ips = new ArrayList<String>();
try
{
final Player player = getPlayer(args[1]); final Player player = getPlayer(args[1]);
username = player.getName();
ips.add(player.getAddress().getAddress().getHostAddress()); if (player == null)
}
catch (PlayerNotFoundException ex)
{ {
final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(args[1]); final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(args[1]);
@ -71,17 +69,22 @@ public class Command_glist extends TFM_Command
username = entry.getLastJoinName(); username = entry.getLastJoinName();
ips.addAll(entry.getIps()); ips.addAll(entry.getIps());
} }
else
{
username = player.getName();
ips.add(player.getAddress().getAddress().getHostAddress());
}
String mode = args[0].toLowerCase(); String mode = args[0].toLowerCase();
if (mode.equalsIgnoreCase("ban")) if (mode.equalsIgnoreCase("ban"))
{ {
TFM_Util.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ","), true); TFM_Util.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ","), true);
Player player = server.getPlayerExact(username); Player target = server.getPlayerExact(username);
if (player != null) if (target != null)
{ {
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName())); TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(target.getUniqueId(), target.getName()));
player.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: http://www.totalfreedom.boards.net"); target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: http://www.totalfreedom.boards.net");
} }
else else
{ {

View File

@ -4,8 +4,8 @@ import me.StevenLawson.TotalFreedomMod.Bridge.TFM_WorldEditBridge;
import me.StevenLawson.TotalFreedomMod.TFM_Ban; import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager; import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils; import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -27,14 +27,11 @@ public class Command_gtfo extends TFM_Command
return false; return false;
} }
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED);
}
catch (PlayerNotFoundException ex)
{
playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;
} }

View File

@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -76,18 +77,14 @@ public class Command_halt extends TFM_Command
return true; return true;
} }
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true; return true;
} }
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
if (!playerdata.isHalted()) if (!playerdata.isHalted())
{ {

View File

@ -1,6 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -18,27 +19,24 @@ public class Command_lastcmd extends TFM_Command
return false; return false;
} }
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;
} }
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
if (playerdata != null) if (playerdata != null)
{ {
String last_command = playerdata.getLastCommand(); String lastCommand = playerdata.getLastCommand();
if (last_command.isEmpty()) if (lastCommand.isEmpty())
{ {
last_command = "(none)"; lastCommand = "(none)";
} }
playerMsg(player.getName() + " - Last Command: " + last_command, ChatColor.GRAY); playerMsg(player.getName() + " - Last Command: " + lastCommand, ChatColor.GRAY);
} }
return true; return true;

View File

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -46,14 +47,11 @@ public class Command_lockup extends TFM_Command
{ {
if (args[1].equalsIgnoreCase("on")) if (args[1].equalsIgnoreCase("on"))
{ {
final Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true; return true;
} }
@ -63,14 +61,11 @@ public class Command_lockup extends TFM_Command
} }
else if (TFM_Util.isStopCommand(args[1])) else if (TFM_Util.isStopCommand(args[1]))
{ {
final Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true; return true;
} }

View File

@ -34,20 +34,14 @@ public class Command_nf extends TFM_Command
if (matcher.find()) if (matcher.find())
{ {
String displayName = matcher.group(1); String displayName = matcher.group(1);
try
{
player = getPlayerByDisplayName(displayName); player = getPlayerByDisplayName(displayName);
}
catch (PlayerNotFoundException ex)
{
}
if (player == null) if (player == null)
{
try
{ {
player = getPlayerByDisplayNameAlt(displayName); player = getPlayerByDisplayNameAlt(displayName);
}
catch (PlayerNotFoundException ex) if (player == null)
{ {
sender.sendMessage(ChatColor.GRAY + "Can't find player by nickname: " + displayName); sender.sendMessage(ChatColor.GRAY + "Can't find player by nickname: " + displayName);
return true; return true;
@ -80,7 +74,7 @@ public class Command_nf extends TFM_Command
return true; return true;
} }
private static Player getPlayerByDisplayName(String needle) throws PlayerNotFoundException private static Player getPlayerByDisplayName(String needle)
{ {
needle = needle.toLowerCase().trim(); needle = needle.toLowerCase().trim();
@ -93,10 +87,10 @@ public class Command_nf extends TFM_Command
} }
} }
throw new PlayerNotFoundException(); return null;
} }
private static Player getPlayerByDisplayNameAlt(String needle) throws PlayerNotFoundException private static Player getPlayerByDisplayNameAlt(String needle)
{ {
needle = needle.toLowerCase().trim(); needle = needle.toLowerCase().trim();
@ -115,11 +109,6 @@ public class Command_nf extends TFM_Command
} }
} }
if (minEditMatch == null)
{
throw new PlayerNotFoundException();
}
return minEditMatch; return minEditMatch;
} }
} }

View File

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -21,14 +22,11 @@ public class Command_orbit extends TFM_Command
return false; return false;
} }
Player player; Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED);
}
catch (PlayerNotFoundException ex)
{
playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;
} }

View File

@ -57,14 +57,12 @@ public class Command_potion extends TFM_Command
Player target = sender_p; Player target = sender_p;
if (args.length == 2) if (args.length == 2)
{
try
{ {
target = getPlayer(args[1]); target = getPlayer(args[1]);
}
catch (PlayerNotFoundException ex) if (target == null)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED);
return true; return true;
} }
} }
@ -103,13 +101,12 @@ public class Command_potion extends TFM_Command
if (args.length == 5) if (args.length == 5)
{ {
try
{
target = getPlayer(args[4]); target = getPlayer(args[4]);
}
catch (PlayerNotFoundException ex) if (target == null)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED);
return true; return true;
} }
} }

View File

@ -23,17 +23,18 @@ public class Command_premium extends TFM_Command
return false; return false;
} }
String name; final Player player = getPlayer(args[0]);
try final String name;
if (player != null)
{ {
name = getPlayer(args[0]).getName(); name = player.getName();
} }
catch (PlayerNotFoundException ex) else
{ {
name = args[0]; name = args[0];
} }
final String playername = name;
new BukkitRunnable() new BukkitRunnable()
{ {
@Override @Override
@ -41,7 +42,7 @@ public class Command_premium extends TFM_Command
{ {
try try
{ {
final URL getUrl = new URL("https://minecraft.net/haspaid.jsp?user=" + playername); final URL getUrl = new URL("https://minecraft.net/haspaid.jsp?user=" + name);
final URLConnection urlConnection = getUrl.openConnection(); final URLConnection urlConnection = getUrl.openConnection();
// Read the response // Read the response
final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
@ -53,7 +54,7 @@ public class Command_premium extends TFM_Command
@Override @Override
public void run() public void run()
{ {
playerMsg("Player " + playername + " is premium: " + message); playerMsg("Player " + name + " is premium: " + message);
} }
}.runTask(plugin); }.runTask(plugin);

View File

@ -1,6 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank; import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -33,17 +34,15 @@ public class Command_rank extends TFM_Command
return true; return true;
} }
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true; return true;
} }
playerMsg(player.getName() + " is " + TFM_PlayerRank.fromSender(player).getLoginMessage(), ChatColor.AQUA); playerMsg(player.getName() + " is " + TFM_PlayerRank.fromSender(player).getLoginMessage(), ChatColor.AQUA);
return true; return true;

View File

@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -66,14 +67,11 @@ public class Command_ro extends TFM_Command
final Player targetPlayer; final Player targetPlayer;
if (args.length == 3) if (args.length == 3)
{
try
{ {
targetPlayer = getPlayer(args[2]); targetPlayer = getPlayer(args[2]);
} if (targetPlayer == null)
catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND);
return true; return true;
} }
} }

View File

@ -85,17 +85,12 @@ public class Command_rollback extends TFM_Command
{ {
String playerName = null; String playerName = null;
try
{ final Player player = getPlayer(playerNameInput);
Player player = getPlayer(playerNameInput);
if (player != null) if (player != null)
{ {
playerName = player.getName(); playerName = player.getName();
} }
}
catch (PlayerNotFoundException ex)
{
}
if (playerName == null) if (playerName == null)
{ {

View File

@ -64,12 +64,12 @@ public class Command_saconfig extends TFM_Command
if (superadmin == null) if (superadmin == null)
{ {
try
{ final Player player = getPlayer(args[1]);
superadmin = TFM_AdminList.getEntry(getPlayer(args[1]).getName().toLowerCase());
} if (player != null)
catch (PlayerNotFoundException ex)
{ {
superadmin = TFM_AdminList.getEntry(player.getName().toLowerCase());
} }
} }
@ -95,17 +95,16 @@ public class Command_saconfig extends TFM_Command
{ {
OfflinePlayer player; OfflinePlayer player;
try
{
player = getPlayer(args[1]); player = getPlayer(args[1]);
}
catch (PlayerNotFoundException ex) if (player == null)
{ {
final TFM_Admin superadmin = TFM_AdminList.getEntry(args[1]); final TFM_Admin superadmin = TFM_AdminList.getEntry(args[1]);
if (superadmin == null) if (superadmin == null)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND);
return true; return true;
} }
@ -128,12 +127,11 @@ public class Command_saconfig extends TFM_Command
String targetName = args[1]; String targetName = args[1];
try
{ final Player player = getPlayer(targetName);
targetName = getPlayer(targetName).getName();
} if (player != null) {
catch (PlayerNotFoundException ex) targetName = player.getName();
{
} }
if (!TFM_AdminList.getLowerSuperNames().contains(targetName.toLowerCase())) if (!TFM_AdminList.getLowerSuperNames().contains(targetName.toLowerCase()))

View File

@ -1,6 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
@ -21,14 +22,11 @@ public class Command_smite extends TFM_Command
return false; return false;
} }
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;
} }

View File

@ -98,14 +98,11 @@ public class Command_stfu extends TFM_Command
} }
else else
{ {
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true; return true;
} }

View File

@ -3,7 +3,6 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -51,14 +50,12 @@ public class Command_survival extends TFM_Command
} }
if (senderIsConsole || TFM_AdminList.isSuperAdmin(sender)) if (senderIsConsole || TFM_AdminList.isSuperAdmin(sender))
{
try
{ {
player = getPlayer(args[0]); player = getPlayer(args[0]);
}
catch (PlayerNotFoundException ex) if (player == null)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND);
return true; return true;
} }
} }

View File

@ -104,14 +104,11 @@ public class Command_tag extends TFM_Command
return true; return true;
} }
final Player player; final Player player = getPlayer(args[1]);
try
if (player == null)
{ {
player = getPlayer(args[1]); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
playerMsg(ex.getMessage());
return true; return true;
} }

View File

@ -4,6 +4,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager; import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -22,14 +23,11 @@ public class Command_tban extends TFM_Command
return false; return false;
} }
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED);
}
catch (PlayerNotFoundException ex)
{
playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;
} }

View File

@ -4,11 +4,10 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import me.StevenLawson.TotalFreedomMod.TFM_Ban; import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager; import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils; import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -28,14 +27,11 @@ public class Command_tempban extends TFM_Command
return false; return false;
} }
Player player; final Player player = getPlayer(args[0]);
try
if (player == null)
{ {
player = getPlayer(args[0]); playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND);
}
catch (PlayerNotFoundException ex)
{
playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;
} }

View File

@ -88,12 +88,9 @@ public class Command_whitelist extends TFM_Command
String search_name = args[1].trim().toLowerCase(); String search_name = args[1].trim().toLowerCase();
OfflinePlayer player; OfflinePlayer player = getPlayer(search_name);
try
{ if (player == null)
player = getPlayer(search_name);
}
catch (PlayerNotFoundException ex)
{ {
player = server.getOfflinePlayer(search_name); player = server.getOfflinePlayer(search_name);
} }
@ -113,12 +110,9 @@ public class Command_whitelist extends TFM_Command
String search_name = args[1].trim().toLowerCase(); String search_name = args[1].trim().toLowerCase();
OfflinePlayer player; OfflinePlayer player = getPlayer(search_name);
try
{ if (player == null)
player = getPlayer(search_name);
}
catch (PlayerNotFoundException ex)
{ {
player = server.getOfflinePlayer(search_name); player = server.getOfflinePlayer(search_name);
} }

View File

@ -1,19 +0,0 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import org.bukkit.ChatColor;
public class PlayerNotFoundException extends Exception
{
// apparently, java needs this
private static final long serialVersionUID = 1L;
public PlayerNotFoundException()
{
super(ChatColor.GRAY + "Can't find player.");
}
public PlayerNotFoundException(String msg)
{
super(ChatColor.GRAY + "Can't find player: " + msg);
}
}

View File

@ -28,7 +28,7 @@ public abstract class TFM_Command
public void setup(final TotalFreedomMod plugin, final CommandSender commandSender, final Class<?> commandClass) public void setup(final TotalFreedomMod plugin, final CommandSender commandSender, final Class<?> commandClass)
{ {
this.plugin = plugin; this.plugin = plugin;
this.server = this.plugin.getServer(); this.server = plugin.getServer();
this.commandSender = commandSender; this.commandSender = commandSender;
this.commandClass = commandClass; this.commandClass = commandClass;
} }
@ -134,7 +134,7 @@ public abstract class TFM_Command
return true; return true;
} }
public Player getPlayer(final String partialname) throws PlayerNotFoundException public Player getPlayer(final String partialname)
{ {
List<Player> matches = server.matchPlayer(partialname); List<Player> matches = server.matchPlayer(partialname);
if (matches.isEmpty()) if (matches.isEmpty())
@ -146,7 +146,7 @@ public abstract class TFM_Command
return player; return player;
} }
} }
throw new PlayerNotFoundException(partialname); return null;
} }
else else
{ {

View File

@ -5,8 +5,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config; import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.util.FileUtil; import org.bukkit.util.FileUtil;
public class TFM_PermbanList public class TFM_PermbanList

View File

@ -8,10 +8,8 @@ import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader; import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
@ -22,8 +20,6 @@ import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -46,6 +42,7 @@ public class TotalFreedomMod extends JavaPlugin
public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!"; public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!";
public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake."; public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.";
public static final String NOT_FROM_CONSOLE = "This command may not be used from the console."; public static final String NOT_FROM_CONSOLE = "This command may not be used from the console.";
public static final String PLAYER_NOT_FOUND = ChatColor.GRAY + "Player not found!";
// //
public static String buildNumber = "1"; public static String buildNumber = "1";
public static String buildDate = TotalFreedomMod.buildDate = TFM_Util.dateToString(new Date()); public static String buildDate = TotalFreedomMod.buildDate = TFM_Util.dateToString(new Date());