From 530f79d11b6e91234e3c5a9432fee4a27162dd55 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Wed, 18 May 2016 20:42:10 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4ext=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pw/yumc/Yum/ext/BukkitUpdater.java | 41 +++++++++---------- .../java/pw/yumc/Yum/ext/SpigotUpdater.java | 10 ----- src/main/java/pw/yumc/Yum/ext/Updater.java | 15 +------ 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/src/main/java/pw/yumc/Yum/ext/BukkitUpdater.java b/src/main/java/pw/yumc/Yum/ext/BukkitUpdater.java index dd2eedd..2ea893a 100644 --- a/src/main/java/pw/yumc/Yum/ext/BukkitUpdater.java +++ b/src/main/java/pw/yumc/Yum/ext/BukkitUpdater.java @@ -27,9 +27,6 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.error.Report; - /** * Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed. *

@@ -60,8 +57,13 @@ public class BukkitUpdater extends Updater { private static final int BYTE_SIZE = 1024; // Used for downloading files + // Update information + // private static final String BUKKIT_DEV_SLUG = "protocollib"; + // private static final int BUKKIT_DEV_ID = 45564; + 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 @@ -322,22 +324,21 @@ public class BukkitUpdater extends Updater { destinationFilePath.getParentFile().mkdirs(); if (entry.isDirectory()) { continue; - } else { - final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); - int b; - final byte buffer[] = new byte[BukkitUpdater.BYTE_SIZE]; - final FileOutputStream fos = new FileOutputStream(destinationFilePath); - final BufferedOutputStream bos = new BufferedOutputStream(fos, BukkitUpdater.BYTE_SIZE); - while ((b = bis.read(buffer, 0, BukkitUpdater.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)); - } + } + final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); + int b; + final byte buffer[] = new byte[BukkitUpdater.BYTE_SIZE]; + final FileOutputStream fos = new FileOutputStream(destinationFilePath); + final BufferedOutputStream bos = new BufferedOutputStream(fos, BukkitUpdater.BYTE_SIZE); + while ((b = bis.read(buffer, 0, BukkitUpdater.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; @@ -399,8 +400,6 @@ public class BukkitUpdater extends Updater { } } catch (final Exception e) { // Any generic error will be handled here - ProtocolLibrary.getErrorReporter().reportDetailed(BukkitUpdater.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(e).callerParam(this)); - } finally { // Invoke the listeners on the main thread for (final Runnable listener : listeners) { diff --git a/src/main/java/pw/yumc/Yum/ext/SpigotUpdater.java b/src/main/java/pw/yumc/Yum/ext/SpigotUpdater.java index 83c9b5b..26b93c3 100644 --- a/src/main/java/pw/yumc/Yum/ext/SpigotUpdater.java +++ b/src/main/java/pw/yumc/Yum/ext/SpigotUpdater.java @@ -24,8 +24,6 @@ import java.net.URL; import org.bukkit.plugin.Plugin; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.error.Report; import com.google.common.base.Charsets; import com.google.common.io.Closer; @@ -83,7 +81,6 @@ public final class SpigotUpdater extends Updater { @Override public void start(final UpdateType type) { waitForThread(); - this.type = type; this.thread = new Thread(new SpigotUpdateRunnable()); this.thread.start(); @@ -95,19 +92,12 @@ public final class SpigotUpdater extends Updater { try { final String version = getSpigotVersion(); remoteVersion = version; - if (versionCheck(version)) { result = UpdateResult.SPIGOT_UPDATE_AVAILABLE; } else { result = UpdateResult.NO_UPDATE; } } catch (final Throwable ex) { - // if (ProtocolLibrary.getConfig().isDebug()) { - ProtocolLibrary.getErrorReporter().reportDetailed(SpigotUpdater.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(ex).callerParam(this)); - // } else { - // plugin.getLogger().log(Level.WARNING, "Failed to check for updates: " + ex); - // } - // ProtocolLibrary.disableUpdates(); } finally { // Invoke the listeners on the main thread for (final Runnable listener : listeners) { diff --git a/src/main/java/pw/yumc/Yum/ext/Updater.java b/src/main/java/pw/yumc/Yum/ext/Updater.java index 2713bbe..965f84e 100644 --- a/src/main/java/pw/yumc/Yum/ext/Updater.java +++ b/src/main/java/pw/yumc/Yum/ext/Updater.java @@ -22,8 +22,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.plugin.Plugin; -import com.comphenix.protocol.error.ReportType; -import com.comphenix.protocol.utility.MinecraftVersion; import com.google.common.base.Preconditions; /** @@ -31,7 +29,6 @@ import com.google.common.base.Preconditions; */ public abstract class Updater { - public static final ReportType REPORT_CANNOT_UPDATE_PLUGIN = new ReportType("Cannot update ProtocolLib."); protected Plugin plugin; protected String versionName; @@ -181,20 +178,12 @@ public abstract class Updater { remoteVersion = remoteVersion.substring(1); } - final MinecraftVersion parsedRemote = new MinecraftVersion(remoteVersion); - final MinecraftVersion parsedCurrent = new MinecraftVersion(plugin.getDescription().getVersion()); + final String localVersion = plugin.getDescription().getVersion(); - if (devBuild && parsedRemote.equals(parsedCurrent)) { + if (devBuild && remoteVersion.equals(localVersion)) { // They're using a dev build and this version has been released return !remoteVersion.contains("-BETA") && !remoteVersion.contains("-SNAPSHOT"); } - - // The remote version has to be greater - if (parsedRemote.compareTo(parsedCurrent) <= 0) { - // We already have the latest version, or this build is tagged for no-update - this.result = BukkitUpdater.UpdateResult.NO_UPDATE; - return false; - } } return true; }