From 976eccf33c1eb94ee59b9411a420c5f730dfc80b Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sun, 2 Apr 2017 11:21:13 +0200 Subject: [PATCH] Updated plugin.yml --- .gitignore | 4 + .../CSCoreLibSetup/CSCoreLibLoader.java | 78 +++++++++++++------ .../ExoticGarden/ExoticGarden.java | 26 +++---- src/plugin.yml | 7 +- 4 files changed, 74 insertions(+), 41 deletions(-) create mode 100644 .gitignore rename src/me/mrCookieSlime/{ => ExoticGarden}/CSCoreLibSetup/CSCoreLibLoader.java (52%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..527411fc --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/bin/ +/.settings/ +.classpath +.project \ No newline at end of file diff --git a/src/me/mrCookieSlime/CSCoreLibSetup/CSCoreLibLoader.java b/src/me/mrCookieSlime/ExoticGarden/CSCoreLibSetup/CSCoreLibLoader.java similarity index 52% rename from src/me/mrCookieSlime/CSCoreLibSetup/CSCoreLibLoader.java rename to src/me/mrCookieSlime/ExoticGarden/CSCoreLibSetup/CSCoreLibLoader.java index 925dbcb3..ed725867 100644 --- a/src/me/mrCookieSlime/CSCoreLibSetup/CSCoreLibLoader.java +++ b/src/me/mrCookieSlime/ExoticGarden/CSCoreLibSetup/CSCoreLibLoader.java @@ -1,4 +1,4 @@ -package me.mrCookieSlime.CSCoreLibSetup; +package me.mrCookieSlime.ExoticGarden.CSCoreLibSetup; import java.io.BufferedInputStream; import java.io.BufferedReader; @@ -6,6 +6,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -33,27 +34,26 @@ public CSCoreLibLoader(Plugin plugin) { public boolean load() { if (plugin.getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) return true; else { + System.err.println(" "); + System.err.println("#################### - INFO - ####################"); + System.err.println(" "); + System.err.println(plugin.getName() + " could not be loaded."); + System.err.println("It appears that you have not installed CS-CoreLib"); + System.err.println("Your Server will now try to download and install"); + System.err.println("CS-CoreLib for you."); + System.err.println("You will be asked to restart your Server when it's finished."); + System.err.println("If this somehow fails, please download and install CS-CoreLib manually:"); + System.err.println("https://dev.bukkit.org/projects/cs-corelib"); + System.err.println(" "); + System.err.println("#################### - INFO - ####################"); + System.err.println(" "); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); - System.err.println(" "); - System.err.println(plugin.getName() + " could not be properly installed!"); - System.err.println("It appears that you have not installed CS-CoreLib"); - System.err.println("And because of that, CS-CoreLib is now going to be"); - System.err.println("downloaded and installed."); - System.err.println("But for the time being " + plugin.getName() + " will remain disabled"); - System.err.println("After the installation process has finished,"); - System.out.println("you will be asked to restart your Server."); - System.err.println("- mrCookieSlime"); - System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); - System.err.println(" "); if (connect()) install(); } - }, 0L); + }, 10L); return false; } } @@ -67,22 +67,48 @@ private boolean connect() { final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); final JSONArray array = (JSONArray) JSONValue.parse(reader.readLine()); - download = new URL((String) ((JSONObject) array.get(array.size() - 1)).get("downloadUrl")); + download = traceURL(((String) ((JSONObject) array.get(array.size() - 1)).get("downloadUrl")).replace("https:", "http:")); file = new File("plugins/" + (String) ((JSONObject) array.get(array.size() - 1)).get("name") + ".jar"); return true; } catch (IOException e) { System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); + System.err.println("#################### - WARNING - ####################"); System.err.println(" "); - System.err.println("Could not connect to BukkitDev, is it down?"); + System.err.println("Could not connect to BukkitDev."); + System.err.println("Please download & install CS-CoreLib manually:"); + System.err.println("https://dev.bukkit.org/projects/cs-corelib"); System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); + System.err.println("#################### - WARNING - ####################"); System.err.println(" "); return false; } } + private URL traceURL(String location) throws IOException { + HttpURLConnection connection = null; + + while (true) { + URL url = new URL(location); + connection = (HttpURLConnection) url.openConnection(); + + connection.setInstanceFollowRedirects(false); + connection.setConnectTimeout(5000); + connection.addRequestProperty("User-Agent", "Auto Updater (by mrCookieSlime)"); + + switch (connection.getResponseCode()) { + case HttpURLConnection.HTTP_MOVED_PERM: + case HttpURLConnection.HTTP_MOVED_TEMP: + String loc = connection.getHeaderField("Location"); + location = new URL(new URL(location), loc).toExternalForm(); + continue; + } + break; + } + + return new URL(connection.getURL().toString().replaceAll(" ", "%20")); + } + private void install() { BufferedInputStream input = null; FileOutputStream output = null; @@ -97,23 +123,25 @@ private void install() { } } catch (Exception ex) { System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); + System.err.println("#################### - WARNING - ####################"); System.err.println(" "); - System.err.println("Could not download CS-CoreLib"); + System.err.println("Failed to download CS-CoreLib"); + System.err.println("Please download & install CS-CoreLib manually:"); + System.err.println("https://dev.bukkit.org/projects/cs-corelib"); System.err.println(" "); - System.err.println("#################### - FATAL ERROR - ####################"); + System.err.println("#################### - WARNING - ####################"); System.err.println(" "); } finally { try { if (input != null) input.close(); if (output != null) output.close(); System.err.println(" "); - System.err.println("#################### - WARNING - ####################"); + System.err.println("#################### - INFO - ####################"); System.err.println(" "); System.err.println("Please restart your Server to finish the Installation"); System.err.println("of " + plugin.getName() + " and CS-CoreLib"); System.err.println(" "); - System.err.println("#################### - WARNING - ####################"); + System.err.println("#################### - INFO - ####################"); System.err.println(" "); } catch (IOException e) { e.printStackTrace(); diff --git a/src/me/mrCookieSlime/ExoticGarden/ExoticGarden.java b/src/me/mrCookieSlime/ExoticGarden/ExoticGarden.java index 1c8f2cd3..5b06e46c 100644 --- a/src/me/mrCookieSlime/ExoticGarden/ExoticGarden.java +++ b/src/me/mrCookieSlime/ExoticGarden/ExoticGarden.java @@ -11,6 +11,18 @@ import java.util.List; import java.util.Map; +import org.bukkit.Effect; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.material.MaterialData; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; import me.mrCookieSlime.CSCoreLibPlugin.PluginUtils; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; @@ -20,7 +32,7 @@ import me.mrCookieSlime.CSCoreLibPlugin.general.Player.PlayerInventory; import me.mrCookieSlime.CSCoreLibPlugin.general.String.StringUtils; import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; -import me.mrCookieSlime.CSCoreLibSetup.CSCoreLibLoader; +import me.mrCookieSlime.ExoticGarden.CSCoreLibSetup.CSCoreLibLoader; import me.mrCookieSlime.Slimefun.Lists.Categories; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; @@ -33,18 +45,6 @@ import me.mrCookieSlime.Slimefun.Setup.SlimefunManager; import me.mrCookieSlime.Slimefun.api.BlockStorage; -import org.bukkit.Effect; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.material.MaterialData; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - public class ExoticGarden extends JavaPlugin { static List berries = new ArrayList(); diff --git a/src/plugin.yml b/src/plugin.yml index 110d7e10..64e48fda 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,7 +1,8 @@ name: ExoticGarden -version: 1.6.1 -author: mrCookieSlime -website: http://dev.bukkit.org/profiles/mrCookieSlime/bukkit-plugins/ +version: 1.6.2 +authors: [mrCookieSlime, Goldentoenail] +description: A Slimefun Addon that adds new Plants and dishes to the game +website: http://TheBusyBiscuit.github.io/ main: me.mrCookieSlime.ExoticGarden.ExoticGarden