From 3b634b14f669dccd6051660c80e36caf62123713 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Sat, 18 Feb 2012 14:06:21 +0000 Subject: [PATCH] Fixed NPE when running a custom build of CraftBukkit. This fixes issue #BUKKIT-765 --- src/main/java/org/bukkit/craftbukkit/CraftServer.java | 2 +- .../org/bukkit/craftbukkit/updater/AutoUpdater.java | 4 ++-- .../craftbukkit/updater/BukkitDLUpdaterService.java | 10 +++------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 763d26aaa0..8634c865df 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1024,7 +1024,7 @@ public final class CraftServer implements Server { } public void onPlayerJoin(Player player) { - if ((updater.isEnabled()) && (player.hasPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE))) { + if ((updater.isEnabled()) && (updater.getCurrent() != null) && (player.hasPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE))) { if ((updater.getCurrent().isBroken()) && (updater.getOnBroken().contains(updater.WARN_OPERATORS))) { player.sendMessage(ChatColor.DARK_RED + "The version of CraftBukkit that this server is running is known to be broken. Please consider updating to the latest version at dl.bukkit.org."); } else if ((updater.isUpdateAvailable()) && (updater.getOnUpdate().contains(updater.WARN_OPERATORS))) { diff --git a/src/main/java/org/bukkit/craftbukkit/updater/AutoUpdater.java b/src/main/java/org/bukkit/craftbukkit/updater/AutoUpdater.java index ede432e610..52869645c5 100644 --- a/src/main/java/org/bukkit/craftbukkit/updater/AutoUpdater.java +++ b/src/main/java/org/bukkit/craftbukkit/updater/AutoUpdater.java @@ -65,8 +65,8 @@ public class AutoUpdater { new Thread() { @Override public void run() { - current = service.getArtifact(currentSlug); - latest = service.getArtifact("latest-" + channel); + current = service.getArtifact(currentSlug, "current artifact information; perhaps you are running a custom version?"); + latest = service.getArtifact("latest-" + channel, "latest artifact information"); if (isUpdateAvailable()) { if ((current.isBroken()) && (onBroken.contains(WARN_CONSOLE))) { diff --git a/src/main/java/org/bukkit/craftbukkit/updater/BukkitDLUpdaterService.java b/src/main/java/org/bukkit/craftbukkit/updater/BukkitDLUpdaterService.java index fdc6db57e0..3d94268da7 100644 --- a/src/main/java/org/bukkit/craftbukkit/updater/BukkitDLUpdaterService.java +++ b/src/main/java/org/bukkit/craftbukkit/updater/BukkitDLUpdaterService.java @@ -1,15 +1,11 @@ package org.bukkit.craftbukkit.updater; import com.google.gson.*; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; -import java.net.MalformedURLException; import java.net.URL; -import java.net.URLEncoder; -import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -25,13 +21,13 @@ public class BukkitDLUpdaterService { this.host = host; } - public ArtifactDetails getArtifact(String slug) { + public ArtifactDetails getArtifact(String slug, String name) { try { return fetchArtifact(slug); } catch (UnsupportedEncodingException ex) { - Logger.getLogger(BukkitDLUpdaterService.class.getName()).log(Level.WARNING, "Could not get Artifact details for the auto-updater: " + ex.getClass().getSimpleName()); + Logger.getLogger(BukkitDLUpdaterService.class.getName()).log(Level.WARNING, "Could not get " + name + ": " + ex.getClass().getSimpleName()); } catch (IOException ex) { - Logger.getLogger(BukkitDLUpdaterService.class.getName()).log(Level.WARNING, "Could not get Artifact details for the auto-updater: " + ex.getClass().getSimpleName()); + Logger.getLogger(BukkitDLUpdaterService.class.getName()).log(Level.WARNING, "Could not get " + name + ": " + ex.getClass().getSimpleName()); } return null;