From 49fa5fa407bfac2e00dcc890a0e80beaec28aba2 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 14 Oct 2016 22:29:12 +0200 Subject: [PATCH] Added #13 --- .../bucket/core/TBMCCoreAPI.java | 26 +++++++++++++------ .../buttondevteam/bucket/core/TBMCPlayer.java | 2 -- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/buttondevteam/bucket/core/TBMCCoreAPI.java b/src/main/java/buttondevteam/bucket/core/TBMCCoreAPI.java index b36dab4..bf244a8 100644 --- a/src/main/java/buttondevteam/bucket/core/TBMCCoreAPI.java +++ b/src/main/java/buttondevteam/bucket/core/TBMCCoreAPI.java @@ -12,8 +12,6 @@ import java.util.List; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.json.simple.JSONObject; - import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -30,19 +28,31 @@ public final class TBMCCoreAPI { * @return Error message or empty string */ public static String UpdatePlugin(String name) { - MainPlugin.Instance.getLogger().info("Updating TBMC plugin: " + name); + List plugins = GetPluginNames(); + String correctname = null; + for (String plugin : plugins) { + if (plugin.equalsIgnoreCase(name)) { + correctname = plugin; // Fixes capitalization + break; + } + } + if (correctname == null) { + MainPlugin.Instance.getLogger().warning("There was an error while updating TBMC plugin: " + name); + return "Can't find plugin: " + name; + } + MainPlugin.Instance.getLogger().info("Updating TBMC plugin: " + correctname); String ret = ""; URL url; try { url = new URL("https://jitpack.io/com/github/TBMCPlugins/" - + (name.equalsIgnoreCase("ButtonCore") ? "ButtonCore/ButtonCore" : name) + "/master-SNAPSHOT/" - + name + "-master-SNAPSHOT.jar"); // ButtonCore exception required since it hosts Towny as well - FileUtils.copyURLToFile(url, new File("plugins/" + name + ".jar")); + + (correctname.equals("ButtonCore") ? "ButtonCore/ButtonCore" : correctname) + "/master-SNAPSHOT/" + + correctname + "-master-SNAPSHOT.jar"); // ButtonCore exception required since it hosts Towny as well + FileUtils.copyURLToFile(url, new File("plugins/" + correctname + ".jar")); } catch (FileNotFoundException e) { ret = "Can't find JAR, the build probably failed. Build log (scroll to bottom):\nhttps://jitpack.io/com/github/TBMCPlugins/" - + name + "/master-SNAPSHOT/build.log"; + + correctname + "/master-SNAPSHOT/build.log"; } catch (IOException e) { - ret = "IO error - Did you spell the plugin's name correctly?\n" + e.getMessage(); + ret = "IO error!\n" + e.getMessage(); } catch (Exception e) { MainPlugin.Instance.getLogger().warning("Error!\n" + e); ret = e.toString(); diff --git a/src/main/java/buttondevteam/bucket/core/TBMCPlayer.java b/src/main/java/buttondevteam/bucket/core/TBMCPlayer.java index a5e7c74..192b051 100644 --- a/src/main/java/buttondevteam/bucket/core/TBMCPlayer.java +++ b/src/main/java/buttondevteam/bucket/core/TBMCPlayer.java @@ -8,8 +8,6 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.TownyUniverse;