From 12b262b6b4ff847db521a25dd9c2cac7990e7955 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Wed, 22 Jan 2020 18:59:02 +0100 Subject: [PATCH] Fixed some Exception issues - Fixed IllegalArgumentException when generating TranslatableWords files - Fixed NPE when the quest section not found - Fixing version check (from https://github.com/Zrips/Residence/commit/70bc47773ed346dcb594273dd3d1168e978b282e) --- .../com/gamingmesh/jobs/CMILib/VersionChecker.java | 10 +++------- .../com/gamingmesh/jobs/config/ConfigManager.java | 4 +++- .../gamingmesh/jobs/config/NameTranslatorManager.java | 11 +++++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java b/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java index be2cd1b3..3906553f 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java @@ -2,8 +2,8 @@ package com.gamingmesh.jobs.CMILib; import java.io.BufferedReader; import java.io.InputStreamReader; -import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLConnection; import java.util.Arrays; import java.util.List; @@ -150,7 +150,6 @@ public class VersionChecker { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { String currentVersion = plugin.getDescription().getVersion(); String newVersion = getNewVersion(); - if (newVersion == null || newVersion.equalsIgnoreCase(currentVersion)) return; @@ -169,12 +168,9 @@ public class VersionChecker { public String getNewVersion() { try { - HttpURLConnection con = (HttpURLConnection) new URL("https://www.spigotmc.org/api/general.php").openConnection(); - con.setDoOutput(true); - con.setRequestMethod("POST"); - con.getOutputStream().write(("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=" + resource).getBytes("UTF-8")); + URLConnection con = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + resource).openConnection(); String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine(); - if (version.length() <= 7) + if (version.length() <= 8) return version; } catch (Throwable t) { Jobs.consoleMsg("&cFailed to check for " + plugin.getDescription().getName() + " update on spigot web page."); diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index b7a3bb10..6487ed14 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -1017,8 +1017,10 @@ public class ConfigManager { for (String one : qsection.getKeys(false)) { try { - ConfigurationSection sqsection = qsection.getConfigurationSection(one); + if (sqsection == null) { + continue; + } String name = sqsection.getString("Name", one); Quest quest = new Quest(name, job); diff --git a/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java b/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java index ae309c31..e0fff192 100644 --- a/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java @@ -112,9 +112,11 @@ public class NameTranslatorManager { } public void readFile() { - - YmlMaker ItemFile = new YmlMaker(Jobs.getInstance(), "TranslatableWords" + File.separator + "Words_" + Jobs.getGCManager().localeString + ".yml"); - ItemFile.saveDefaultConfig(); + YmlMaker ItemFile = new YmlMaker(Jobs.getInstance(), "TranslatableWords" + File.separator + "Words_" + + Jobs.getGCManager().localeString + ".yml"); + if (!ItemFile.getConfigFile().getName().equalsIgnoreCase("en")) { + ItemFile.saveDefaultConfig(); + } if (ItemFile.getConfig().isConfigurationSection("ItemList")) { ConfigurationSection section = ItemFile.getConfig().getConfigurationSection("ItemList"); @@ -193,7 +195,8 @@ public class NameTranslatorManager { Jobs.consoleMsg("&c[Jobs] The ColorList section not found in " + ItemFile.fileName + " file."); } - synchronized void load() { + @SuppressWarnings("deprecation") + synchronized void load() { String ls = Jobs.getGCManager().localeString; if (ls.isEmpty()) return;