chore: 调整ext更新部分

This commit is contained in:
502647092 2016-05-18 20:42:10 +08:00
parent c7e10a88b6
commit 530f79d11b
3 changed files with 22 additions and 44 deletions

View File

@ -27,9 +27,6 @@ import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; 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. * Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed.
* <p/> * <p/>
@ -60,8 +57,13 @@ public class BukkitUpdater extends Updater {
private static final int BYTE_SIZE = 1024; // Used for downloading files 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 URL url; // Connecting to RSS
private File file; // The plugin's file private File file; // The plugin's file
private Thread thread; // Updater thread private Thread thread; // Updater thread
private int id = -1; // Project's Curse ID private int id = -1; // Project's Curse ID
@ -322,22 +324,21 @@ public class BukkitUpdater extends Updater {
destinationFilePath.getParentFile().mkdirs(); destinationFilePath.getParentFile().mkdirs();
if (entry.isDirectory()) { if (entry.isDirectory()) {
continue; continue;
} else { }
final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
int b; int b;
final byte buffer[] = new byte[BukkitUpdater.BYTE_SIZE]; final byte buffer[] = new byte[BukkitUpdater.BYTE_SIZE];
final FileOutputStream fos = new FileOutputStream(destinationFilePath); final FileOutputStream fos = new FileOutputStream(destinationFilePath);
final BufferedOutputStream bos = new BufferedOutputStream(fos, BukkitUpdater.BYTE_SIZE); final BufferedOutputStream bos = new BufferedOutputStream(fos, BukkitUpdater.BYTE_SIZE);
while ((b = bis.read(buffer, 0, BukkitUpdater.BYTE_SIZE)) != -1) { while ((b = bis.read(buffer, 0, BukkitUpdater.BYTE_SIZE)) != -1) {
bos.write(buffer, 0, b); bos.write(buffer, 0, b);
} }
bos.flush(); bos.flush();
bos.close(); bos.close();
bis.close(); bis.close();
final String name = destinationFilePath.getName(); final String name = destinationFilePath.getName();
if (name.endsWith(".jar") && this.pluginFile(name)) { if (name.endsWith(".jar") && this.pluginFile(name)) {
destinationFilePath.renameTo(new File(this.plugin.getDataFolder().getParent(), this.updateFolder + "/" + name)); destinationFilePath.renameTo(new File(this.plugin.getDataFolder().getParent(), this.updateFolder + "/" + name));
}
} }
entry = null; entry = null;
destinationFilePath = null; destinationFilePath = null;
@ -399,8 +400,6 @@ public class BukkitUpdater extends Updater {
} }
} catch (final Exception e) { } catch (final Exception e) {
// Any generic error will be handled here // Any generic error will be handled here
ProtocolLibrary.getErrorReporter().reportDetailed(BukkitUpdater.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(e).callerParam(this));
} finally { } finally {
// Invoke the listeners on the main thread // Invoke the listeners on the main thread
for (final Runnable listener : listeners) { for (final Runnable listener : listeners) {

View File

@ -24,8 +24,6 @@ import java.net.URL;
import org.bukkit.plugin.Plugin; 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.base.Charsets;
import com.google.common.io.Closer; import com.google.common.io.Closer;
@ -83,7 +81,6 @@ public final class SpigotUpdater extends Updater {
@Override @Override
public void start(final UpdateType type) { public void start(final UpdateType type) {
waitForThread(); waitForThread();
this.type = type; this.type = type;
this.thread = new Thread(new SpigotUpdateRunnable()); this.thread = new Thread(new SpigotUpdateRunnable());
this.thread.start(); this.thread.start();
@ -95,19 +92,12 @@ public final class SpigotUpdater extends Updater {
try { try {
final String version = getSpigotVersion(); final String version = getSpigotVersion();
remoteVersion = version; remoteVersion = version;
if (versionCheck(version)) { if (versionCheck(version)) {
result = UpdateResult.SPIGOT_UPDATE_AVAILABLE; result = UpdateResult.SPIGOT_UPDATE_AVAILABLE;
} else { } else {
result = UpdateResult.NO_UPDATE; result = UpdateResult.NO_UPDATE;
} }
} catch (final Throwable ex) { } 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 { } finally {
// Invoke the listeners on the main thread // Invoke the listeners on the main thread
for (final Runnable listener : listeners) { for (final Runnable listener : listeners) {

View File

@ -22,8 +22,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.comphenix.protocol.error.ReportType;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
/** /**
@ -31,7 +29,6 @@ import com.google.common.base.Preconditions;
*/ */
public abstract class Updater { public abstract class Updater {
public static final ReportType REPORT_CANNOT_UPDATE_PLUGIN = new ReportType("Cannot update ProtocolLib.");
protected Plugin plugin; protected Plugin plugin;
protected String versionName; protected String versionName;
@ -181,20 +178,12 @@ public abstract class Updater {
remoteVersion = remoteVersion.substring(1); remoteVersion = remoteVersion.substring(1);
} }
final MinecraftVersion parsedRemote = new MinecraftVersion(remoteVersion); final String localVersion = plugin.getDescription().getVersion();
final MinecraftVersion parsedCurrent = new MinecraftVersion(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 // They're using a dev build and this version has been released
return !remoteVersion.contains("-BETA") && !remoteVersion.contains("-SNAPSHOT"); 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; return true;
} }