From ee39e890938e949b11883c2b42177fdb5a45a29a Mon Sep 17 00:00:00 2001 From: Jerome van der Sar Date: Sun, 1 Dec 2013 15:18:05 +0100 Subject: [PATCH] Fixed possible NPE in getPrefix() --- buildnumber.properties | 4 +- .../Commands/Command_list.java | 4 +- .../TotalFreedomMod/TFM_Util.java | 64 ++++++++++--------- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/buildnumber.properties b/buildnumber.properties index a3a029d6..90cb15b2 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Sun Dec 01 13:41:29 CET 2013 -build.number=646 +#Sun Dec 01 15:18:04 CET 2013 +build.number=647 diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java index b5a5d7ae..2db37fce 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java @@ -54,7 +54,7 @@ public class Command_list extends TFM_Command final List names = new ArrayList(); for (Player player : server.getOnlinePlayers()) { - boolean userSuperadmin = TFM_SuperadminList.isUserSuperadmin(player); + final boolean userSuperadmin = TFM_SuperadminList.isUserSuperadmin(player); if (listFilter == ListFilter.ADMINS && !userSuperadmin) { @@ -66,7 +66,7 @@ public class Command_list extends TFM_Command if (userSuperadmin) { final TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(player.getName()); - if (entry == null) + if (entry == null || !entry.isActivated()) { prefix = ChatColor.GOLD + "[SA]"; } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index 883774c4..55675463 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -421,38 +421,34 @@ public class TFM_Util return "an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "impostor" + ChatColor.RESET + ChatColor.AQUA + "!"; } - TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(sender.getName()); + final TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(sender.getName()); - if (entry != null) + if (entry != null && entry.isActivated()) { - if (entry.isActivated()) + String loginMessage = entry.getCustomLoginMessage(); + + if (loginMessage != null) { - String loginMessage = entry.getCustomLoginMessage(); - - if (loginMessage != null) + if (!loginMessage.isEmpty()) { - if (!loginMessage.isEmpty()) - { - return ChatColor.translateAlternateColorCodes('&', loginMessage); - } - } - - if (!entry.isSeniorAdmin() && entry.isTelnetAdmin()) - { - return "a " + ChatColor.DARK_GREEN + "Super Telnet Admin" + ChatColor.AQUA + "."; - } - - if (entry.isSeniorAdmin()) - { - return "a " + ChatColor.LIGHT_PURPLE + "Senior Admin" + ChatColor.AQUA + "."; - } - else - { - return "a " + ChatColor.GOLD + "Super Admin" + ChatColor.AQUA + "."; + return ChatColor.translateAlternateColorCodes('&', loginMessage); } } - } + if (entry.isSeniorAdmin()) + { + return "a " + ChatColor.LIGHT_PURPLE + "Senior Admin" + ChatColor.AQUA + "."; + } + else if (entry.isTelnetAdmin()) + { + return "a " + ChatColor.DARK_GREEN + "Super Telnet Admin" + ChatColor.AQUA + "."; + } + else + { + return "a " + ChatColor.GOLD + "Super Admin" + ChatColor.AQUA + "."; + } + } + if (sender.isOp()) { return "an " + ChatColor.DARK_GREEN + "OP" + ChatColor.AQUA + "."; @@ -759,7 +755,7 @@ public class TFM_Util public static void downloadFile(String url, File output, boolean verbose) throws java.lang.Exception { - URL website = new URL(url); + final URL website = new URL(url); ReadableByteChannel rbc = Channels.newChannel(website.openStream()); FileOutputStream fos = new FileOutputStream(output); fos.getChannel().transferFrom(rbc, 0, 1 << 24); @@ -794,19 +790,25 @@ public class TFM_Util } else { - TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(sender.getName()); - if (!entry.isSeniorAdmin() && entry.isTelnetAdmin()) - { - prefix = ChatColor.DARK_GREEN + "(STA)"; + final TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(sender.getName()); + + if (entry == null) { + return ""; } - else if (TFM_SuperadminList.isSeniorAdmin(sender)) + + if (entry.isSeniorAdmin()) { prefix = ChatColor.LIGHT_PURPLE + "(SrA)"; } + else if (entry.isTelnetAdmin()) + { + prefix = ChatColor.DARK_GREEN + "(STA)"; + } else { prefix = ChatColor.GOLD + "(SA)"; } + if (DEVELOPERS.contains(sender.getName())) { prefix = ChatColor.DARK_PURPLE + "(Dev)";