From 120f556db62793b672412d4c02a4b6fcf223a93c Mon Sep 17 00:00:00 2001 From: j502647092 Date: Wed, 29 Apr 2015 12:37:01 +0800 Subject: [PATCH] move src directory... Signed-off-by: j502647092 --- pom.xml | 18 +- .../com/me/tft_02/soulbound/Soulbound.java | 25 - .../com/me/tft_02/soulbound/api/ItemAPI.java | 0 .../soulbound/commands/BindCommand.java | 0 .../commands/BindOnEquipCommand.java | 0 .../commands/BindOnPickupCommand.java | 0 .../soulbound/commands/BindOnUseCommand.java | 0 .../soulbound/commands/SoulboundCommand.java | 0 .../soulbound/commands/UnbindCommand.java | 0 .../config/AutoUpdateConfigLoader.java | 0 .../me/tft_02/soulbound/config/Config.java | 0 .../tft_02/soulbound/config/ConfigLoader.java | 0 .../tft_02/soulbound/config/ItemsConfig.java | 0 .../soulbound/datatypes/ActionType.java | 0 .../soulbound/datatypes/SoulbindItem.java | 0 .../soulbound/events/SoulbindItemEvent.java | 0 .../hooks/EpicBossRecodedListener.java | 0 .../soulbound/listeners/BlockListener.java | 0 .../soulbound/listeners/EntityListener.java | 0 .../listeners/InventoryListener.java | 0 .../soulbound/listeners/PlayerListener.java | 0 .../soulbound/listeners/SelfListener.java | 0 .../runnables/SoulbindInventoryTask.java | 0 .../soulbound/runnables/UpdateArmorTask.java | 0 .../runnables/UpdateInventoryTask.java | 0 .../tft_02/soulbound/util/CommandUtils.java | 0 .../soulbound/util/DurabilityUtils.java | 0 .../me/tft_02/soulbound/util/ItemUtils.java | 0 .../me/tft_02/soulbound/util/LogFilter.java | 0 .../com/me/tft_02/soulbound/util/Misc.java | 0 .../me/tft_02/soulbound/util/Permissions.java | 0 .../me/tft_02/soulbound/util/PlayerData.java | 0 .../me/tft_02/soulbound/util/StringUtils.java | 0 src/{main/java => }/config.yml | 0 src/{main/java => }/items.yml | 0 src/main/assembly/package.xml | 14 - .../updater/soulbound/Updater.java | 558 ------------------ src/{main/java => }/plugin.yml | 0 38 files changed, 1 insertion(+), 614 deletions(-) rename src/{main/java => }/com/me/tft_02/soulbound/Soulbound.java (80%) rename src/{main/java => }/com/me/tft_02/soulbound/api/ItemAPI.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/commands/BindCommand.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/commands/BindOnEquipCommand.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/commands/BindOnPickupCommand.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/commands/BindOnUseCommand.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/commands/SoulboundCommand.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/commands/UnbindCommand.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/config/AutoUpdateConfigLoader.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/config/Config.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/config/ConfigLoader.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/config/ItemsConfig.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/datatypes/ActionType.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/datatypes/SoulbindItem.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/events/SoulbindItemEvent.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/hooks/EpicBossRecodedListener.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/listeners/BlockListener.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/listeners/EntityListener.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/listeners/InventoryListener.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/listeners/PlayerListener.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/listeners/SelfListener.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/runnables/SoulbindInventoryTask.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/runnables/UpdateArmorTask.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/runnables/UpdateInventoryTask.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/util/CommandUtils.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/util/DurabilityUtils.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/util/ItemUtils.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/util/LogFilter.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/util/Misc.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/util/Permissions.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/util/PlayerData.java (100%) rename src/{main/java => }/com/me/tft_02/soulbound/util/StringUtils.java (100%) rename src/{main/java => }/config.yml (100%) rename src/{main/java => }/items.yml (100%) delete mode 100644 src/main/assembly/package.xml delete mode 100644 src/main/java/net/gravitydevelopment/updater/soulbound/Updater.java rename src/{main/java => }/plugin.yml (100%) diff --git a/pom.xml b/pom.xml index a3c069e..c95a573 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ src - src/main/java + src **/*.java @@ -37,7 +37,6 @@ org.mcstats.bukkit:metrics - org.nunnerycode.bukkit:mythicdropsapi-lib @@ -45,10 +44,6 @@ org.mcstats.bukkit com.me.tft_02.soulbound.util - - org.nunnerycode.bukkit - com.me.tft_02.soulbound.util - @@ -71,10 +66,6 @@ Plugin Metrics http://repo.mcstats.org/content/repositories/public - - mythicdrops-repo - http://repository-topplethenun.forge.cloudbees.com/snapshot/ - @@ -90,13 +81,6 @@ R7 compile - - org.nunnerycode.bukkit - mythicdropsapi-lib - 1.0.0-SNAPSHOT - jar - compile - UTF-8 diff --git a/src/main/java/com/me/tft_02/soulbound/Soulbound.java b/src/com/me/tft_02/soulbound/Soulbound.java similarity index 80% rename from src/main/java/com/me/tft_02/soulbound/Soulbound.java rename to src/com/me/tft_02/soulbound/Soulbound.java index 6e20a58..7e8498f 100644 --- a/src/main/java/com/me/tft_02/soulbound/Soulbound.java +++ b/src/com/me/tft_02/soulbound/Soulbound.java @@ -2,8 +2,6 @@ package com.me.tft_02.soulbound; import java.io.File; -import net.gravitydevelopment.updater.soulbound.Updater; - import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -61,8 +59,6 @@ public class Soulbound extends JavaPlugin { getCommand("bindonuse").setExecutor(new BindOnUseCommand()); getCommand("bindonequip").setExecutor(new BindOnEquipCommand()); getCommand("unbind").setExecutor(new UnbindCommand()); - - checkForUpdates(); } private void registerEvents() { @@ -112,25 +108,4 @@ public class Soulbound extends JavaPlugin { ItemsConfig.getInstance(); } - private void checkForUpdates() { - if (!Config.getInstance().getUpdateCheckEnabled()) { - return; - } - - Updater updater = new Updater(this, 53483, soulbound, Updater.UpdateType.NO_DOWNLOAD, false); - - if (updater.getResult() != Updater.UpdateResult.UPDATE_AVAILABLE) { - this.updateAvailable = false; - return; - } - - if (updater.getLatestType().equals("beta") && !Config.getInstance().getPreferBeta()) { - this.updateAvailable = false; - return; - } - - this.updateAvailable = true; - getLogger().info("Soulbound is outdated!"); - getLogger().info("http://dev.bukkit.org/server-mods/soulbound/"); - } } diff --git a/src/main/java/com/me/tft_02/soulbound/api/ItemAPI.java b/src/com/me/tft_02/soulbound/api/ItemAPI.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/api/ItemAPI.java rename to src/com/me/tft_02/soulbound/api/ItemAPI.java diff --git a/src/main/java/com/me/tft_02/soulbound/commands/BindCommand.java b/src/com/me/tft_02/soulbound/commands/BindCommand.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/commands/BindCommand.java rename to src/com/me/tft_02/soulbound/commands/BindCommand.java diff --git a/src/main/java/com/me/tft_02/soulbound/commands/BindOnEquipCommand.java b/src/com/me/tft_02/soulbound/commands/BindOnEquipCommand.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/commands/BindOnEquipCommand.java rename to src/com/me/tft_02/soulbound/commands/BindOnEquipCommand.java diff --git a/src/main/java/com/me/tft_02/soulbound/commands/BindOnPickupCommand.java b/src/com/me/tft_02/soulbound/commands/BindOnPickupCommand.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/commands/BindOnPickupCommand.java rename to src/com/me/tft_02/soulbound/commands/BindOnPickupCommand.java diff --git a/src/main/java/com/me/tft_02/soulbound/commands/BindOnUseCommand.java b/src/com/me/tft_02/soulbound/commands/BindOnUseCommand.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/commands/BindOnUseCommand.java rename to src/com/me/tft_02/soulbound/commands/BindOnUseCommand.java diff --git a/src/main/java/com/me/tft_02/soulbound/commands/SoulboundCommand.java b/src/com/me/tft_02/soulbound/commands/SoulboundCommand.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/commands/SoulboundCommand.java rename to src/com/me/tft_02/soulbound/commands/SoulboundCommand.java diff --git a/src/main/java/com/me/tft_02/soulbound/commands/UnbindCommand.java b/src/com/me/tft_02/soulbound/commands/UnbindCommand.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/commands/UnbindCommand.java rename to src/com/me/tft_02/soulbound/commands/UnbindCommand.java diff --git a/src/main/java/com/me/tft_02/soulbound/config/AutoUpdateConfigLoader.java b/src/com/me/tft_02/soulbound/config/AutoUpdateConfigLoader.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/config/AutoUpdateConfigLoader.java rename to src/com/me/tft_02/soulbound/config/AutoUpdateConfigLoader.java diff --git a/src/main/java/com/me/tft_02/soulbound/config/Config.java b/src/com/me/tft_02/soulbound/config/Config.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/config/Config.java rename to src/com/me/tft_02/soulbound/config/Config.java diff --git a/src/main/java/com/me/tft_02/soulbound/config/ConfigLoader.java b/src/com/me/tft_02/soulbound/config/ConfigLoader.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/config/ConfigLoader.java rename to src/com/me/tft_02/soulbound/config/ConfigLoader.java diff --git a/src/main/java/com/me/tft_02/soulbound/config/ItemsConfig.java b/src/com/me/tft_02/soulbound/config/ItemsConfig.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/config/ItemsConfig.java rename to src/com/me/tft_02/soulbound/config/ItemsConfig.java diff --git a/src/main/java/com/me/tft_02/soulbound/datatypes/ActionType.java b/src/com/me/tft_02/soulbound/datatypes/ActionType.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/datatypes/ActionType.java rename to src/com/me/tft_02/soulbound/datatypes/ActionType.java diff --git a/src/main/java/com/me/tft_02/soulbound/datatypes/SoulbindItem.java b/src/com/me/tft_02/soulbound/datatypes/SoulbindItem.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/datatypes/SoulbindItem.java rename to src/com/me/tft_02/soulbound/datatypes/SoulbindItem.java diff --git a/src/main/java/com/me/tft_02/soulbound/events/SoulbindItemEvent.java b/src/com/me/tft_02/soulbound/events/SoulbindItemEvent.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/events/SoulbindItemEvent.java rename to src/com/me/tft_02/soulbound/events/SoulbindItemEvent.java diff --git a/src/main/java/com/me/tft_02/soulbound/hooks/EpicBossRecodedListener.java b/src/com/me/tft_02/soulbound/hooks/EpicBossRecodedListener.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/hooks/EpicBossRecodedListener.java rename to src/com/me/tft_02/soulbound/hooks/EpicBossRecodedListener.java diff --git a/src/main/java/com/me/tft_02/soulbound/listeners/BlockListener.java b/src/com/me/tft_02/soulbound/listeners/BlockListener.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/listeners/BlockListener.java rename to src/com/me/tft_02/soulbound/listeners/BlockListener.java diff --git a/src/main/java/com/me/tft_02/soulbound/listeners/EntityListener.java b/src/com/me/tft_02/soulbound/listeners/EntityListener.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/listeners/EntityListener.java rename to src/com/me/tft_02/soulbound/listeners/EntityListener.java diff --git a/src/main/java/com/me/tft_02/soulbound/listeners/InventoryListener.java b/src/com/me/tft_02/soulbound/listeners/InventoryListener.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/listeners/InventoryListener.java rename to src/com/me/tft_02/soulbound/listeners/InventoryListener.java diff --git a/src/main/java/com/me/tft_02/soulbound/listeners/PlayerListener.java b/src/com/me/tft_02/soulbound/listeners/PlayerListener.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/listeners/PlayerListener.java rename to src/com/me/tft_02/soulbound/listeners/PlayerListener.java diff --git a/src/main/java/com/me/tft_02/soulbound/listeners/SelfListener.java b/src/com/me/tft_02/soulbound/listeners/SelfListener.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/listeners/SelfListener.java rename to src/com/me/tft_02/soulbound/listeners/SelfListener.java diff --git a/src/main/java/com/me/tft_02/soulbound/runnables/SoulbindInventoryTask.java b/src/com/me/tft_02/soulbound/runnables/SoulbindInventoryTask.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/runnables/SoulbindInventoryTask.java rename to src/com/me/tft_02/soulbound/runnables/SoulbindInventoryTask.java diff --git a/src/main/java/com/me/tft_02/soulbound/runnables/UpdateArmorTask.java b/src/com/me/tft_02/soulbound/runnables/UpdateArmorTask.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/runnables/UpdateArmorTask.java rename to src/com/me/tft_02/soulbound/runnables/UpdateArmorTask.java diff --git a/src/main/java/com/me/tft_02/soulbound/runnables/UpdateInventoryTask.java b/src/com/me/tft_02/soulbound/runnables/UpdateInventoryTask.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/runnables/UpdateInventoryTask.java rename to src/com/me/tft_02/soulbound/runnables/UpdateInventoryTask.java diff --git a/src/main/java/com/me/tft_02/soulbound/util/CommandUtils.java b/src/com/me/tft_02/soulbound/util/CommandUtils.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/util/CommandUtils.java rename to src/com/me/tft_02/soulbound/util/CommandUtils.java diff --git a/src/main/java/com/me/tft_02/soulbound/util/DurabilityUtils.java b/src/com/me/tft_02/soulbound/util/DurabilityUtils.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/util/DurabilityUtils.java rename to src/com/me/tft_02/soulbound/util/DurabilityUtils.java diff --git a/src/main/java/com/me/tft_02/soulbound/util/ItemUtils.java b/src/com/me/tft_02/soulbound/util/ItemUtils.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/util/ItemUtils.java rename to src/com/me/tft_02/soulbound/util/ItemUtils.java diff --git a/src/main/java/com/me/tft_02/soulbound/util/LogFilter.java b/src/com/me/tft_02/soulbound/util/LogFilter.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/util/LogFilter.java rename to src/com/me/tft_02/soulbound/util/LogFilter.java diff --git a/src/main/java/com/me/tft_02/soulbound/util/Misc.java b/src/com/me/tft_02/soulbound/util/Misc.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/util/Misc.java rename to src/com/me/tft_02/soulbound/util/Misc.java diff --git a/src/main/java/com/me/tft_02/soulbound/util/Permissions.java b/src/com/me/tft_02/soulbound/util/Permissions.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/util/Permissions.java rename to src/com/me/tft_02/soulbound/util/Permissions.java diff --git a/src/main/java/com/me/tft_02/soulbound/util/PlayerData.java b/src/com/me/tft_02/soulbound/util/PlayerData.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/util/PlayerData.java rename to src/com/me/tft_02/soulbound/util/PlayerData.java diff --git a/src/main/java/com/me/tft_02/soulbound/util/StringUtils.java b/src/com/me/tft_02/soulbound/util/StringUtils.java similarity index 100% rename from src/main/java/com/me/tft_02/soulbound/util/StringUtils.java rename to src/com/me/tft_02/soulbound/util/StringUtils.java diff --git a/src/main/java/config.yml b/src/config.yml similarity index 100% rename from src/main/java/config.yml rename to src/config.yml diff --git a/src/main/java/items.yml b/src/items.yml similarity index 100% rename from src/main/java/items.yml rename to src/items.yml diff --git a/src/main/assembly/package.xml b/src/main/assembly/package.xml deleted file mode 100644 index 30993fb..0000000 --- a/src/main/assembly/package.xml +++ /dev/null @@ -1,14 +0,0 @@ - - bin - false - - zip - - - - ${project.build.directory}/${artifactId}.jar - / - Soulbound.jar - - - \ No newline at end of file diff --git a/src/main/java/net/gravitydevelopment/updater/soulbound/Updater.java b/src/main/java/net/gravitydevelopment/updater/soulbound/Updater.java deleted file mode 100644 index e019352..0000000 --- a/src/main/java/net/gravitydevelopment/updater/soulbound/Updater.java +++ /dev/null @@ -1,558 +0,0 @@ -/* - * Updater for Bukkit. - * - * This class provides the means to safely and easily update a plugin, or check to see if it is updated using dev.bukkit.org - */ - -package net.gravitydevelopment.updater.soulbound; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.Enumeration; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; - -import com.me.tft_02.soulbound.config.Config; - -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; - -/** - * Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed. - *

- * VERY, VERY IMPORTANT: Because there are no standards for adding auto-update toggles in your plugin's config, this system provides NO CHECK WITH YOUR CONFIG to make sure the user has allowed auto-updating. - *
- * It is a BUKKIT POLICY that you include a boolean value in your config that prevents the auto-updater from running AT ALL. - *
- * If you fail to include this option in your config, your plugin will be REJECTED when you attempt to submit it to dev.bukkit.org. - *

- * An example of a good configuration option would be something similar to 'auto-update: true' - if this value is set to false you may NOT run the auto-updater. - *
- * If you are unsure about these rules, please read the plugin submission guidelines: http://goo.gl/8iU5l - * - * @author Gravity - * @version 2.0 - */ - -public class Updater { - - private Plugin plugin; - private UpdateType type; - private String versionName; - private String versionLink; - private String versionType; - private String versionGameVersion; - - private boolean announce; // Whether to announce file downloads - - private URL url; // Connecting to RSS - private File file; // The plugin's file - private Thread thread; // Updater thread - - private int id = -1; // Project's Curse ID - private String apiKey = null; // BukkitDev ServerMods API key - private static final String TITLE_VALUE = "name"; // Gets remote file's title - private static final String LINK_VALUE = "downloadUrl"; // Gets remote file's download link - private static final String TYPE_VALUE = "releaseType"; // Gets remote file's release type - private static final String VERSION_VALUE = "gameVersion"; // Gets remote file's build version - private static final String QUERY = "/servermods/files?projectIds="; // Path to GET - private static final String HOST = "https://api.curseforge.com"; // Slugs will be appended to this to get to the project's RSS feed - - private static final int BYTE_SIZE = 1024; // Used for downloading files - private YamlConfiguration config; // Config file - private String updateFolder;// The folder that downloads will be placed in - private Updater.UpdateResult result = Updater.UpdateResult.SUCCESS; // Used for determining the outcome of the update process - - /** - * Gives the dev the result of the update process. Can be obtained by called getResult(). - */ - public enum UpdateResult { - /** - * The updater found an update, and has readied it to be loaded the next time the server restarts/reloads. - */ - SUCCESS, - /** - * The updater did not find an update, and nothing was downloaded. - */ - NO_UPDATE, - /** - * The server administrator has disabled the updating system - */ - DISABLED, - /** - * The updater found an update, but was unable to download it. - */ - FAIL_DOWNLOAD, - /** - * For some reason, the updater was unable to contact dev.bukkit.org to download the file. - */ - FAIL_DBO, - /** - * When running the version check, the file on DBO did not contain the a version in the format 'vVersion' such as 'v1.0'. - */ - FAIL_NOVERSION, - /** - * The id provided by the plugin running the updater was invalid and doesn't exist on DBO. - */ - FAIL_BADID, - /** - * The server administrator has improperly configured their API key in the configuration - */ - FAIL_APIKEY, - /** - * The updater found an update, but because of the UpdateType being set to NO_DOWNLOAD, it wasn't downloaded. - */ - UPDATE_AVAILABLE - } - - /** - * Allows the dev to specify the type of update that will be run. - */ - public enum UpdateType { - /** - * Run a version check, and then if the file is out of date, download the newest version. - */ - DEFAULT, - /** - * Don't run a version check, just find the latest update and download it. - */ - NO_VERSION_CHECK, - /** - * Get information about the version and the download size, but don't actually download anything. - */ - NO_DOWNLOAD - } - - /** - * Initialize the updater - * - * @param plugin The plugin that is checking for an update. - * @param id The dev.bukkit.org id of the project - * @param file The file that the plugin is running from, get this by doing this.getFile() from within your main class. - * @param type Specify the type of update this will be. See {@link UpdateType} - * @param announce True if the program should announce the progress of new updates in console - */ - public Updater(Plugin plugin, int id, File file, UpdateType type, boolean announce) { - this.plugin = plugin; - this.type = type; - this.announce = announce; - this.file = file; - this.id = id; - this.updateFolder = plugin.getServer().getUpdateFolder(); - - final File pluginFile = plugin.getDataFolder().getParentFile(); - final File updaterFile = new File(pluginFile, "Updater"); - final File updaterConfigFile = new File(updaterFile, "config.yml"); - - if (!updaterFile.exists()) { - updaterFile.mkdir(); - } - if (!updaterConfigFile.exists()) { - try { - updaterConfigFile.createNewFile(); - } - catch (final IOException e) { - plugin.getLogger().severe("The updater could not create a configuration in " + updaterFile.getAbsolutePath()); - e.printStackTrace(); - } - } - this.config = YamlConfiguration.loadConfiguration(updaterConfigFile); - - this.config.options().header("This configuration file affects all plugins using the Updater system (version 2+ - http://forums.bukkit.org/threads/96681/ )" + '\n' - + "If you wish to use your API key, read http://wiki.bukkit.org/ServerMods_API and place it below." + '\n' - + "Some updating systems will not adhere to the disabled value, but these may be turned off in their plugin's configuration."); - this.config.addDefault("api-key", "PUT_API_KEY_HERE"); - this.config.addDefault("disable", false); - - if (this.config.get("api-key", null) == null) { - this.config.options().copyDefaults(true); - try { - this.config.save(updaterConfigFile); - } - catch (final IOException e) { - plugin.getLogger().severe("The updater could not save the configuration in " + updaterFile.getAbsolutePath()); - e.printStackTrace(); - } - } - - if (this.config.getBoolean("disable")) { - this.result = UpdateResult.DISABLED; - return; - } - - String key = this.config.getString("api-key"); - if (key.equalsIgnoreCase("PUT_API_KEY_HERE") || key.equals("")) { - key = null; - } - - this.apiKey = key; - - try { - this.url = new URL(Updater.HOST + Updater.QUERY + id); - } - catch (final MalformedURLException e) { - plugin.getLogger().severe("The project ID provided for updating, " + id + " is invalid."); - this.result = UpdateResult.FAIL_BADID; - e.printStackTrace(); - } - - this.thread = new Thread(new UpdateRunnable()); - this.thread.start(); - } - - /** - * Get the result of the update process. - */ - public Updater.UpdateResult getResult() { - this.waitForThread(); - return this.result; - } - - /** - * Get the latest version's release type (release, beta, or alpha). - */ - public String getLatestType() { - this.waitForThread(); - return this.versionType; - } - - /** - * Get the latest version's game version. - */ - public String getLatestGameVersion() { - this.waitForThread(); - return this.versionGameVersion; - } - - /** - * Get the latest version's name. - */ - public String getLatestName() { - this.waitForThread(); - return this.versionName; - } - - /** - * Get the latest version's file link. - */ - public String getLatestFileLink() { - this.waitForThread(); - return this.versionLink; - } - - /** - * As the result of Updater output depends on the thread's completion, it is necessary to wait for the thread to finish - * before allowing anyone to check the result. - */ - private void waitForThread() { - if ((this.thread != null) && this.thread.isAlive()) { - try { - this.thread.join(); - } - catch (final InterruptedException e) { - e.printStackTrace(); - } - } - } - - /** - * Save an update from dev.bukkit.org into the server's update folder. - */ - private void saveFile(File folder, String file, String u) { - if (!folder.exists()) { - folder.mkdir(); - } - BufferedInputStream in = null; - FileOutputStream fout = null; - try { - // Download the file - final URL url = new URL(u); - final int fileLength = url.openConnection().getContentLength(); - in = new BufferedInputStream(url.openStream()); - fout = new FileOutputStream(folder.getAbsolutePath() + "/" + file); - - final byte[] data = new byte[Updater.BYTE_SIZE]; - int count; - if (this.announce) { - this.plugin.getLogger().info("About to download a new update: " + this.versionName); - } - long downloaded = 0; - while ((count = in.read(data, 0, Updater.BYTE_SIZE)) != -1) { - downloaded += count; - fout.write(data, 0, count); - final int percent = (int) ((downloaded * 100) / fileLength); - if (this.announce && ((percent % 10) == 0)) { - this.plugin.getLogger().info("Downloading update: " + percent + "% of " + fileLength + " bytes."); - } - } - //Just a quick check to make sure we didn't leave any files from last time... - for (final File xFile : new File(this.plugin.getDataFolder().getParent(), this.updateFolder).listFiles()) { - if (xFile.getName().endsWith(".zip")) { - xFile.delete(); - } - } - // Check to see if it's a zip file, if it is, unzip it. - final File dFile = new File(folder.getAbsolutePath() + "/" + file); - if (dFile.getName().endsWith(".zip")) { - // Unzip - this.unzip(dFile.getCanonicalPath()); - } - if (this.announce) { - this.plugin.getLogger().info("Finished updating."); - } - } - catch (final Exception ex) { - this.plugin.getLogger().warning("The auto-updater tried to download a new update, but was unsuccessful."); - this.result = Updater.UpdateResult.FAIL_DOWNLOAD; - } - finally { - try { - if (in != null) { - in.close(); - } - if (fout != null) { - fout.close(); - } - } - catch (final Exception ex) { - } - } - } - - /** - * Part of Zip-File-Extractor, modified by Gravity for use with Bukkit - */ - private void unzip(String file) { - try { - final File fSourceZip = new File(file); - final String zipPath = file.substring(0, file.length() - 4); - ZipFile zipFile = new ZipFile(fSourceZip); - Enumeration e = zipFile.entries(); - while (e.hasMoreElements()) { - ZipEntry entry = e.nextElement(); - File destinationFilePath = new File(zipPath, entry.getName()); - destinationFilePath.getParentFile().mkdirs(); - if (entry.isDirectory()) { - continue; - } - - final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); - int b; - final byte buffer[] = new byte[Updater.BYTE_SIZE]; - final FileOutputStream fos = new FileOutputStream(destinationFilePath); - final BufferedOutputStream bos = new BufferedOutputStream(fos, Updater.BYTE_SIZE); - while ((b = bis.read(buffer, 0, Updater.BYTE_SIZE)) != -1) { - bos.write(buffer, 0, b); - } - bos.flush(); - bos.close(); - bis.close(); - final String name = destinationFilePath.getName(); - if (name.endsWith(".jar") && this.pluginFile(name)) { - destinationFilePath.renameTo(new File(this.plugin.getDataFolder().getParent(), this.updateFolder + "/" + name)); - } - - entry = null; - destinationFilePath = null; - } - e = null; - zipFile.close(); - zipFile = null; - - // Move any plugin data folders that were included to the right place, Bukkit won't do this for us. - for (final File dFile : new File(zipPath).listFiles()) { - if (dFile.isDirectory()) { - if (this.pluginFile(dFile.getName())) { - final File oFile = new File(this.plugin.getDataFolder().getParent(), dFile.getName()); // Get current dir - final File[] contents = oFile.listFiles(); // List of existing files in the current dir - for (final File cFile : dFile.listFiles()) // Loop through all the files in the new dir - { - boolean found = false; - for (final File xFile : contents) // Loop through contents to see if it exists - { - if (xFile.getName().equals(cFile.getName())) { - found = true; - break; - } - } - if (!found) { - // Move the new file into the current dir - cFile.renameTo(new File(oFile.getCanonicalFile() + "/" + cFile.getName())); - } - else { - // This file already exists, so we don't need it anymore. - cFile.delete(); - } - } - } - } - dFile.delete(); - } - new File(zipPath).delete(); - fSourceZip.delete(); - } - catch (final IOException ex) { - this.plugin.getLogger().warning("The auto-updater tried to unzip a new update file, but was unsuccessful."); - this.result = Updater.UpdateResult.FAIL_DOWNLOAD; - ex.printStackTrace(); - } - new File(file).delete(); - } - - /** - * Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out of a zip. - */ - private boolean pluginFile(String name) { - for (final File file : new File("plugins").listFiles()) { - if (file.getName().equals(name)) { - return true; - } - } - return false; - } - - /** - * Check to see if the program should continue by evaluation whether the plugin is already updated, or shouldn't be updated - */ - private boolean versionCheck(String title) { - if (type != UpdateType.NO_VERSION_CHECK) { - String version = plugin.getDescription().getVersion(); - title = title.substring(1); - - String[] oldTokens = version.split("-"); - String[] newTokens = title.split("-"); - - int oldVersion = Integer.parseInt(oldTokens[0].replaceAll("[.]", "")); - int newVersion = Integer.parseInt(newTokens[0].replaceAll("[.]", "")); - - // Check versions - if (oldVersion < newVersion) { - return true; - } - - // Check release vs. beta & SNAPSHOT - if (newTokens.length == 1 && oldTokens.length == 3 && oldVersion == newVersion) { - return true; - } - - // Check beta vs. SNAPSHOT - if (version.contains("SNAPSHOT") && title.contains("beta")) { - if (Integer.parseInt(oldTokens[1].substring(8)) <= Integer.parseInt(newTokens[1].substring(4))) { - return true; - } - - result = UpdateResult.NO_UPDATE; - return false; - } - - // Check beta vs. beta - if (version.contains("beta") && title.contains("beta")) { - if (Integer.parseInt(oldTokens[1].substring(4)) < Integer.parseInt(newTokens[1].substring(4))) { - return true; - } - - result = UpdateResult.NO_UPDATE; - return false; - } - - if (oldTokens.length == 3 && !version.contains("beta") && !version.contains("SNAPSHOT")) { - plugin.getLogger().warning("Could not get information about this Soulbound version; perhaps you are running a custom one?"); - result = UpdateResult.FAIL_NOVERSION; - return false; - } - - result = UpdateResult.NO_UPDATE; - return false; - } - - return true; - } - - private boolean read() { - try { - final URLConnection conn = this.url.openConnection(); - conn.setConnectTimeout(5000); - - if (this.apiKey != null) { - conn.addRequestProperty("X-API-Key", this.apiKey); - } - conn.addRequestProperty("User-Agent", "Updater (by Gravity)"); - - conn.setDoOutput(true); - - final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); - final String response = reader.readLine(); - - final JSONArray array = (JSONArray) JSONValue.parse(response); - - if (array.size() == 0) { - this.plugin.getLogger().warning("The updater could not find any files for the project id " + this.id); - this.result = UpdateResult.FAIL_BADID; - return false; - } - - this.versionName = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TITLE_VALUE); - this.versionLink = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.LINK_VALUE); - this.versionType = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TYPE_VALUE); - this.versionGameVersion = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.VERSION_VALUE); - - return true; - } - catch (final IOException e) { - if (e.getMessage().contains("HTTP response code: 403")) { - this.plugin.getLogger().warning("dev.bukkit.org rejected the API key provided in plugins/Updater/config.yml"); - this.plugin.getLogger().warning("Please double-check your configuration to ensure it is correct."); - this.result = UpdateResult.FAIL_APIKEY; - } - else { - this.plugin.getLogger().warning("The updater could not contact dev.bukkit.org for updating."); - this.plugin.getLogger().warning("If you have not recently modified your configuration and this is the first time you are seeing this message, the site may be experiencing temporary downtime."); - this.result = UpdateResult.FAIL_DBO; - } - - if (Config.getInstance().getVerboseLoggingEnabled()) { - e.printStackTrace(); - } - - return false; - } - } - - private class UpdateRunnable implements Runnable { - - @Override - public void run() { - if (Updater.this.url != null) { - // Obtain the results of the project's file feed - if (Updater.this.read()) { - if (Updater.this.versionCheck(Updater.this.versionName)) { - if ((Updater.this.versionLink != null) && (Updater.this.type != UpdateType.NO_DOWNLOAD)) { - String name = Updater.this.file.getName(); - // If it's a zip file, it shouldn't be downloaded as the plugin's name - if (Updater.this.versionLink.endsWith(".zip")) { - final String[] split = Updater.this.versionLink.split("/"); - name = split[split.length - 1]; - } - Updater.this.saveFile(new File(Updater.this.plugin.getDataFolder().getParent(), Updater.this.updateFolder), name, Updater.this.versionLink); - } - else { - Updater.this.result = UpdateResult.UPDATE_AVAILABLE; - } - } - } - } - } - } -} diff --git a/src/main/java/plugin.yml b/src/plugin.yml similarity index 100% rename from src/main/java/plugin.yml rename to src/plugin.yml