From d31ad2e9fc9877308898fd77b5430407ccebf386 Mon Sep 17 00:00:00 2001 From: Jerom van der Sar Date: Sat, 26 Apr 2014 13:55:24 +0200 Subject: [PATCH] [Bleeding] Remove player online check through PlayerNotFoundException getPlayer(String) now returns null when the player could not be found --- buildnumber.properties | 4 +-- .../Commands/Command_adminworld.java | 13 +++---- .../Commands/Command_blockcmd.java | 12 +++---- .../Commands/Command_cage.java | 12 +++---- .../Commands/Command_cartsit.java | 12 +++---- .../Commands/Command_creative.java | 11 +++--- .../Commands/Command_doom.java | 13 +++---- .../Commands/Command_findip.java | 12 +++---- .../TotalFreedomMod/Commands/Command_fr.java | 11 +++--- .../Commands/Command_gcmd.java | 13 +++---- .../Commands/Command_glist.java | 25 ++++++++------ .../Commands/Command_gtfo.java | 13 +++---- .../Commands/Command_halt.java | 13 +++---- .../Commands/Command_lastcmd.java | 22 ++++++------ .../Commands/Command_lockup.java | 23 +++++-------- .../TotalFreedomMod/Commands/Command_nf.java | 29 +++++----------- .../Commands/Command_orbit.java | 12 +++---- .../Commands/Command_potion.java | 21 +++++------- .../Commands/Command_premium.java | 15 ++++---- .../Commands/Command_rank.java | 15 ++++---- .../TotalFreedomMod/Commands/Command_ro.java | 10 +++--- .../Commands/Command_rollback.java | 13 +++---- .../Commands/Command_saconfig.java | 34 +++++++++---------- .../Commands/Command_smite.java | 12 +++---- .../Commands/Command_stfu.java | 11 +++--- .../Commands/Command_survival.java | 11 +++--- .../TotalFreedomMod/Commands/Command_tag.java | 11 +++--- .../Commands/Command_tban.java | 12 +++---- .../Commands/Command_tempban.java | 14 +++----- .../Commands/Command_whitelist.java | 18 ++++------ .../Commands/PlayerNotFoundException.java | 19 ----------- .../TotalFreedomMod/Commands/TFM_Command.java | 6 ++-- .../TotalFreedomMod/TFM_PermbanList.java | 2 -- .../TotalFreedomMod/TotalFreedomMod.java | 5 +-- 34 files changed, 189 insertions(+), 290 deletions(-) delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/PlayerNotFoundException.java diff --git a/buildnumber.properties b/buildnumber.properties index f3315bd4..b689de9b 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Sat Apr 26 13:10:03 CEST 2014 -build.number=804 +#Sat Apr 26 13:54:24 CEST 2014 +build.number=805 diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java index 92ab37b4..615a921d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java @@ -113,18 +113,15 @@ public class Command_adminworld extends TFM_Command if ("add".equalsIgnoreCase(args[1])) { - Player player; - try + final Player player = getPlayer(args[2]); + + if (player == null) { - player = getPlayer(args[2]); - } - catch (PlayerNotFoundException ex) - { - sender.sendMessage(ex.getMessage()); + sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND); 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); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_blockcmd.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_blockcmd.java index ee4c2b63..a23f8d65 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_blockcmd.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_blockcmd.java @@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -36,14 +37,11 @@ public class Command_blockcmd extends TFM_Command return true; } - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage()); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cage.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cage.java index 7fc8090f..f1095a42 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cage.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cage.java @@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -47,14 +48,11 @@ public class Command_cage extends TFM_Command return true; } - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - sender.sendMessage(ex.getMessage()); + sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java index b5125a44..031584ee 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_AdminList; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Minecart; @@ -17,13 +18,12 @@ public class Command_cartsit extends TFM_Command if (args.length == 1) { - try + + targetPlayer = getPlayer(args[0]); + + if (targetPlayer == null) { - targetPlayer = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - sender.sendMessage(ex.getMessage()); + sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_creative.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_creative.java index 34902458..866b5565 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_creative.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_creative.java @@ -54,13 +54,12 @@ public class Command_creative extends TFM_Command return true; } - try + + player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - sender.sendMessage(ex.getMessage()); + sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java index fa0b23c1..69eb30ba 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java @@ -1,10 +1,10 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_Ban; import me.StevenLawson.TotalFreedomMod.TFM_BanManager; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.command.Command; @@ -25,14 +25,11 @@ public class Command_doom extends TFM_Command return false; } - final Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - sender.sendMessage(ex.getMessage()); + sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_findip.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_findip.java index 4913299a..06aa5915 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_findip.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_findip.java @@ -19,14 +19,12 @@ public class Command_findip extends TFM_Command return false; } - final Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage()); + + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fr.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fr.java index 63cedf09..f9a46cdc 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fr.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fr.java @@ -81,14 +81,11 @@ public class Command_fr extends TFM_Command } else { - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java index 37b91096..edc9172f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java @@ -1,8 +1,8 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import net.minecraft.util.org.apache.commons.lang3.StringUtils; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -19,14 +19,11 @@ public class Command_gcmd extends TFM_Command return false; } - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - sender.sendMessage(ex.getMessage()); + sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java index bc1e0b31..e688e24f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java @@ -52,13 +52,11 @@ public class Command_glist extends TFM_Command String username; final List ips = new ArrayList(); - try - { - final Player player = getPlayer(args[1]); - username = player.getName(); - ips.add(player.getAddress().getAddress().getHostAddress()); - } - catch (PlayerNotFoundException ex) + + + final Player player = getPlayer(args[1]); + + if (player == null) { final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(args[1]); @@ -71,17 +69,22 @@ public class Command_glist extends TFM_Command username = entry.getLastJoinName(); ips.addAll(entry.getIps()); } + else + { + username = player.getName(); + ips.add(player.getAddress().getAddress().getHostAddress()); + } String mode = args[0].toLowerCase(); if (mode.equalsIgnoreCase("ban")) { TFM_Util.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ","), true); - Player player = server.getPlayerExact(username); - if (player != null) + Player target = server.getPlayerExact(username); + if (target != null) { - TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.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"); + TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(target.getUniqueId(), target.getName())); + 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 { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java index 3012e152..75925289 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java @@ -4,8 +4,8 @@ import me.StevenLawson.TotalFreedomMod.Bridge.TFM_WorldEditBridge; import me.StevenLawson.TotalFreedomMod.TFM_Ban; import me.StevenLawson.TotalFreedomMod.TFM_BanManager; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager; -import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; 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.StringUtils; import org.bukkit.ChatColor; @@ -27,14 +27,11 @@ public class Command_gtfo extends TFM_Command return false; } - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java index 86514ec5..e29c5e48 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java @@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -76,18 +77,14 @@ public class Command_halt extends TFM_Command return true; } - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - sender.sendMessage(ex.getMessage()); + sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); if (!playerdata.isHalted()) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lastcmd.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lastcmd.java index bf99141c..34fa6180 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lastcmd.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lastcmd.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -18,27 +19,24 @@ public class Command_lastcmd extends TFM_Command return false; } - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); + final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); if (playerdata != null) { - String last_command = playerdata.getLastCommand(); - if (last_command.isEmpty()) + String lastCommand = playerdata.getLastCommand(); + 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; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java index 904b982e..507375f1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java @@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -46,14 +47,11 @@ public class Command_lockup extends TFM_Command { if (args[1].equalsIgnoreCase("on")) { - final Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - sender.sendMessage(ex.getMessage()); + sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } @@ -63,14 +61,11 @@ public class Command_lockup extends TFM_Command } else if (TFM_Util.isStopCommand(args[1])) { - final Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - sender.sendMessage(ex.getMessage()); + sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nf.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nf.java index 98bb921c..04b4a04a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nf.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nf.java @@ -34,20 +34,14 @@ public class Command_nf extends TFM_Command if (matcher.find()) { String displayName = matcher.group(1); - try - { - player = getPlayerByDisplayName(displayName); - } - catch (PlayerNotFoundException ex) - { - } + + player = getPlayerByDisplayName(displayName); + if (player == null) { - try - { - player = getPlayerByDisplayNameAlt(displayName); - } - catch (PlayerNotFoundException ex) + player = getPlayerByDisplayNameAlt(displayName); + + if (player == null) { sender.sendMessage(ChatColor.GRAY + "Can't find player by nickname: " + displayName); return true; @@ -80,7 +74,7 @@ public class Command_nf extends TFM_Command return true; } - private static Player getPlayerByDisplayName(String needle) throws PlayerNotFoundException + private static Player getPlayerByDisplayName(String needle) { 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(); @@ -115,11 +109,6 @@ public class Command_nf extends TFM_Command } } - if (minEditMatch == null) - { - throw new PlayerNotFoundException(); - } - return minEditMatch; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_orbit.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_orbit.java index 5e580803..9fb950d3 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_orbit.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_orbit.java @@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.command.Command; @@ -21,14 +22,11 @@ public class Command_orbit extends TFM_Command return false; } - Player player; - try + Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java index ddddec62..9a7e9e48 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java @@ -58,13 +58,11 @@ public class Command_potion extends TFM_Command if (args.length == 2) { - try + target = getPlayer(args[1]); + + if (target == null) { - target = getPlayer(args[1]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED); return true; } } @@ -103,13 +101,12 @@ public class Command_potion extends TFM_Command if (args.length == 5) { - try + + target = getPlayer(args[4]); + + if (target == null) { - target = getPlayer(args[4]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED); return true; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_premium.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_premium.java index 5c3594b1..c3aadf02 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_premium.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_premium.java @@ -23,17 +23,18 @@ public class Command_premium extends TFM_Command return false; } - String name; - try + final Player player = getPlayer(args[0]); + final String name; + + if (player != null) { - name = getPlayer(args[0]).getName(); + name = player.getName(); } - catch (PlayerNotFoundException ex) + else { name = args[0]; } - final String playername = name; new BukkitRunnable() { @Override @@ -41,7 +42,7 @@ public class Command_premium extends TFM_Command { 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(); // Read the response final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); @@ -53,7 +54,7 @@ public class Command_premium extends TFM_Command @Override public void run() { - playerMsg("Player " + playername + " is premium: " + message); + playerMsg("Player " + name + " is premium: " + message); } }.runTask(plugin); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rank.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rank.java index b20c448c..edbd70a1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rank.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rank.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -33,17 +34,15 @@ public class Command_rank extends TFM_Command return true; } - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - sender.sendMessage(ex.getMessage()); + sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } - + + playerMsg(player.getName() + " is " + TFM_PlayerRank.fromSender(player).getLoginMessage(), ChatColor.AQUA); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java index 5e621471..52f7b84f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java @@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.ArrayList; import java.util.List; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import net.minecraft.util.org.apache.commons.lang3.StringUtils; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -67,13 +68,10 @@ public class Command_ro extends TFM_Command final Player targetPlayer; if (args.length == 3) { - try + targetPlayer = getPlayer(args[2]); + if (targetPlayer == null) { - targetPlayer = getPlayer(args[2]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java index cf39373f..50e0898d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java @@ -85,16 +85,11 @@ public class Command_rollback extends TFM_Command { String playerName = null; - try - { - Player player = getPlayer(playerNameInput); - if (player != null) - { - playerName = player.getName(); - } - } - catch (PlayerNotFoundException ex) + + final Player player = getPlayer(playerNameInput); + if (player != null) { + playerName = player.getName(); } if (playerName == null) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java index b3039250..0a08bc25 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java @@ -64,12 +64,12 @@ public class Command_saconfig extends TFM_Command if (superadmin == null) { - try - { - superadmin = TFM_AdminList.getEntry(getPlayer(args[1]).getName().toLowerCase()); - } - catch (PlayerNotFoundException ex) + + final Player player = getPlayer(args[1]); + + if (player != null) { + superadmin = TFM_AdminList.getEntry(player.getName().toLowerCase()); } } @@ -95,17 +95,16 @@ public class Command_saconfig extends TFM_Command { OfflinePlayer player; - try - { - player = getPlayer(args[1]); - } - catch (PlayerNotFoundException ex) + + player = getPlayer(args[1]); + + if (player == null) { final TFM_Admin superadmin = TFM_AdminList.getEntry(args[1]); if (superadmin == null) { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } @@ -128,14 +127,13 @@ public class Command_saconfig extends TFM_Command String targetName = args[1]; - try - { - targetName = getPlayer(targetName).getName(); - } - catch (PlayerNotFoundException ex) - { - } + final Player player = getPlayer(targetName); + + if (player != null) { + targetName = player.getName(); + } + if (!TFM_AdminList.getLowerSuperNames().contains(targetName.toLowerCase())) { playerMsg("Superadmin not found: " + targetName); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java index 567f2899..0d011e52 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; @@ -21,14 +22,11 @@ public class Command_smite extends TFM_Command return false; } - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java index 9b72fa55..237c871b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java @@ -98,14 +98,11 @@ public class Command_stfu extends TFM_Command } else { - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - sender.sendMessage(ex.getMessage()); + sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_survival.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_survival.java index 8823c035..a75294b0 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_survival.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_survival.java @@ -3,7 +3,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; -import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -52,13 +51,11 @@ public class Command_survival extends TFM_Command if (senderIsConsole || TFM_AdminList.isSuperAdmin(sender)) { - try + player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java index 603e536e..d2ea0a03 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java @@ -104,14 +104,11 @@ public class Command_tag extends TFM_Command return true; } - final Player player; - try + final Player player = getPlayer(args[1]); + + if (player == null) { - player = getPlayer(args[1]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage()); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tban.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tban.java index 04de27dc..a448e141 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tban.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tban.java @@ -4,6 +4,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_Ban; import me.StevenLawson.TotalFreedomMod.TFM_BanManager; import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.Command; @@ -22,14 +23,11 @@ public class Command_tban extends TFM_Command return false; } - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND, ChatColor.RED); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java index 85970292..1287af56 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java @@ -4,11 +4,10 @@ import java.text.SimpleDateFormat; import java.util.Date; import me.StevenLawson.TotalFreedomMod.TFM_Ban; import me.StevenLawson.TotalFreedomMod.TFM_BanManager; -import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; 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.StringUtils; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -28,14 +27,11 @@ public class Command_tempban extends TFM_Command return false; } - Player player; - try + final Player player = getPlayer(args[0]); + + if (player == null) { - player = getPlayer(args[0]); - } - catch (PlayerNotFoundException ex) - { - playerMsg(ex.getMessage(), ChatColor.RED); + playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java index 39102d8f..3a96a6a4 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java @@ -88,12 +88,9 @@ public class Command_whitelist extends TFM_Command String search_name = args[1].trim().toLowerCase(); - OfflinePlayer player; - try - { - player = getPlayer(search_name); - } - catch (PlayerNotFoundException ex) + OfflinePlayer player = getPlayer(search_name); + + if (player == null) { player = server.getOfflinePlayer(search_name); } @@ -113,12 +110,9 @@ public class Command_whitelist extends TFM_Command String search_name = args[1].trim().toLowerCase(); - OfflinePlayer player; - try - { - player = getPlayer(search_name); - } - catch (PlayerNotFoundException ex) + OfflinePlayer player = getPlayer(search_name); + + if (player == null) { player = server.getOfflinePlayer(search_name); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/PlayerNotFoundException.java b/src/me/StevenLawson/TotalFreedomMod/Commands/PlayerNotFoundException.java deleted file mode 100644 index 913b34cd..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/PlayerNotFoundException.java +++ /dev/null @@ -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); - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java index 0ad089cd..e61ac82a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java @@ -28,7 +28,7 @@ public abstract class TFM_Command public void setup(final TotalFreedomMod plugin, final CommandSender commandSender, final Class commandClass) { this.plugin = plugin; - this.server = this.plugin.getServer(); + this.server = plugin.getServer(); this.commandSender = commandSender; this.commandClass = commandClass; } @@ -134,7 +134,7 @@ public abstract class TFM_Command return true; } - public Player getPlayer(final String partialname) throws PlayerNotFoundException + public Player getPlayer(final String partialname) { List matches = server.matchPlayer(partialname); if (matches.isEmpty()) @@ -146,7 +146,7 @@ public abstract class TFM_Command return player; } } - throw new PlayerNotFoundException(partialname); + return null; } else { diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_PermbanList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_PermbanList.java index a1619315..febd26a2 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_PermbanList.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_PermbanList.java @@ -5,8 +5,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import me.StevenLawson.TotalFreedomMod.Config.TFM_Config; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.util.FileUtil; public class TFM_PermbanList diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index 0c225af4..09cac012 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -8,10 +8,8 @@ import java.io.File; import java.io.FileFilter; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; import java.util.Date; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Properties; import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader; @@ -22,8 +20,6 @@ import org.bukkit.Server; import org.bukkit.World; import org.bukkit.command.Command; 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.plugin.PluginManager; 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 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 PLAYER_NOT_FOUND = ChatColor.GRAY + "Player not found!"; // public static String buildNumber = "1"; public static String buildDate = TotalFreedomMod.buildDate = TFM_Util.dateToString(new Date());