diff --git a/src/me/zombie_striker/pixelprinter/GithubUpdater.java b/src/me/zombie_striker/pixelprinter/GithubUpdater.java index 5849f80..694353f 100644 --- a/src/me/zombie_striker/pixelprinter/GithubUpdater.java +++ b/src/me/zombie_striker/pixelprinter/GithubUpdater.java @@ -40,7 +40,7 @@ public class GithubUpdater { * e.printStackTrace(); } } */ - public static boolean autoUpdate(Plugin main, String author, String githubProject, String jarname) { + public static boolean autoUpdate(final Plugin main, String author, String githubProject, String jarname) { try { String version = main.getDescription().getVersion(); String parseVersion = version.replace(".", ""); @@ -62,7 +62,7 @@ public static boolean autoUpdate(Plugin main, String author, String githubProjec + tagname + "/" + jarname); if (latestVersion > Integer.parseInt(parseVersion)) { - Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Found a new version " + ChatColor.WHITE + Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Found a new version of "+ChatColor.GOLD+main.getDescription().getName()+": " + ChatColor.WHITE + tagname + ChatColor.LIGHT_PURPLE + " downloading now!!"); new BukkitRunnable() { @@ -72,6 +72,7 @@ public void run() { try { InputStream in = download.openStream(); + File pluginFile = null; @@ -87,12 +88,23 @@ public void run() { // if (!temp.exists()) { // temp.mkdir(); // } + + File tempInCaseSomethingGoesWrong = new File(main.getName()+"-backup.jar"); + copy(new FileInputStream(pluginFile),new FileOutputStream(tempInCaseSomethingGoesWrong)); // Path path = new File("plugins/update" + File.separator + "COD.jar").toPath(); pluginFile.setWritable(true, false); pluginFile.delete(); //Files.copy(in, pluginFile.toPath(), StandardCopyOption.REPLACE_EXISTING); copy(in, new FileOutputStream(pluginFile)); + + if(pluginFile.length()<1000) { + //Plugin is too small. Keep old version in case new one is incomplete/nonexistant + copy(new FileInputStream(tempInCaseSomethingGoesWrong),new FileOutputStream(pluginFile)); + }else { + //Plugin is valid, and we can delete the temp + tempInCaseSomethingGoesWrong.delete(); + } } catch (IOException e) { e.printStackTrace(); diff --git a/src/me/zombie_striker/pixelprinter/util/SkinCreator.java b/src/me/zombie_striker/pixelprinter/util/SkinCreator.java index 1976ce2..3424a39 100644 --- a/src/me/zombie_striker/pixelprinter/util/SkinCreator.java +++ b/src/me/zombie_striker/pixelprinter/util/SkinCreator.java @@ -16,6 +16,7 @@ public class SkinCreator { public static BufferedImage[] getSkin(String uuid) throws NullPointerException, IOException { + int linecode = 19; try { StringBuilder code = new StringBuilder(); InputStreamReader is = new InputStreamReader(new URL( @@ -25,21 +26,26 @@ public static BufferedImage[] getSkin(String uuid) while ((charI = is.read()) != -1) { code.append(((char) charI)); } + linecode = 29; String[] aaaa = code.toString().split("\"value\":\""); if (aaaa.length == 1) { - System.out.println("The user does not exist- Error-Ln31."); + System.out.println("The user does not exist- AAAA does not contain value."); throw new NullPointerException(); } String decode = new String( DatatypeConverter.parseBase64Binary(aaaa[1] .split("\"}],\"legacy\"")[0])); + linecode =38; System.out.println(decode); - String url = decode.split("url\":\"")[1].split("\"}")[0]; + String url = decode.split("url\":\"")[1].split("\"}")[0].split("\",\"")[0]; + linecode = 41; System.out.println(url); BufferedImage[] images = new BufferedImage[2]; images[0] = ImageIO.read(new URL(url)); + linecode = 45; if (decode.contains("CAPE")) { String urlcape = decode.split("url\":\"")[2].split("\"}")[0]; + linecode = 48; images[1] = ImageIO.read(new URL(urlcape)); } return images; @@ -48,7 +54,7 @@ public static BufferedImage[] getSkin(String uuid) .println("The Mojang servers denied the request. Wait a minute or so until you are allowed to get the texture again."); throw new NullPointerException(); } catch (IOException e2) { - System.out.println("The user does not exist- Error-Ln46."); + System.out.println("The user does not exist- ErrorLineCode="+linecode+"."); throw new IOException(); } }