Archiviert
13
0

Update to the latest version of Gravity's Updater class.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-10-17 02:14:02 +02:00
Ursprung 42395abe75
Commit 6a0600cd7f
3 geänderte Dateien mit 525 neuen und 577 gelöschten Zeilen

Datei anzeigen

@ -19,21 +19,15 @@ package com.comphenix.protocol;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.error.Report;
import com.comphenix.protocol.error.ReportType;
import com.comphenix.protocol.metrics.Updater; import com.comphenix.protocol.metrics.Updater;
import com.comphenix.protocol.metrics.Updater.UpdateResult;
import com.comphenix.protocol.metrics.Updater.UpdateType; import com.comphenix.protocol.metrics.Updater.UpdateType;
import com.comphenix.protocol.timing.TimedListenerManager; import com.comphenix.protocol.timing.TimedListenerManager;
import com.comphenix.protocol.timing.TimingReportGenerator; import com.comphenix.protocol.timing.TimingReportGenerator;
import com.comphenix.protocol.utility.WrappedScheduler;
/** /**
* Handles the "protocol" administration command. * Handles the "protocol" administration command.
@ -46,10 +40,6 @@ class CommandProtocol extends CommandBase {
*/ */
public static final String NAME = "protocol"; public static final String NAME = "protocol";
public static final ReportType REPORT_NETWORK_ERROR = new ReportType("Network error: %s");
public static final ReportType REPORT_CANNOT_CHECK_FOR_UPDATES = new ReportType("Cannot check updates for ProtocolLib.");
public static final ReportType REPORT_CANNOT_UPDATE_PLUGIN = new ReportType("Cannot update ProtocolLib.");
private Plugin plugin; private Plugin plugin;
private Updater updater; private Updater updater;
private ProtocolConfig config; private ProtocolConfig config;
@ -80,49 +70,31 @@ class CommandProtocol extends CommandBase {
} }
public void checkVersion(final CommandSender sender) { public void checkVersion(final CommandSender sender) {
// Perform on an async thread performUpdate(sender, UpdateType.NO_DOWNLOAD);
WrappedScheduler.runAsynchronouslyOnce(plugin, new Runnable() {
@Override
public void run() {
try {
UpdateResult result = updater.update(UpdateType.NO_DOWNLOAD, true);
sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + result.toString());
} catch (Exception e) {
if (isNetworkError(e)) {
getReporter().reportWarning(CommandProtocol.this,
Report.newBuilder(REPORT_NETWORK_ERROR).messageParam(e.getCause().getMessage())
);
} else {
getReporter().reportDetailed(CommandProtocol.this, Report.newBuilder(REPORT_CANNOT_CHECK_FOR_UPDATES).error(e).callerParam(sender));
}
}
}
}, 0L);
updateFinished();
} }
public void updateVersion(final CommandSender sender) { public void updateVersion(final CommandSender sender) {
performUpdate(sender, UpdateType.DEFAULT);
}
private void performUpdate(final CommandSender sender, UpdateType type) {
if (updater.isChecking()) {
sender.sendMessage(ChatColor.RED + "Already checking for an update.");
return;
}
// Perform on an async thread // Perform on an async thread
WrappedScheduler.runAsynchronouslyOnce(plugin, new Runnable() { Runnable notify = new Runnable() {
@Override @Override
public void run() { public void run() {
try { sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + updater.getResult());
UpdateResult result = updater.update(UpdateType.DEFAULT, true);
sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + result.toString()); updater.removeListener(this);
} catch (Exception e) { updateFinished();
if (isNetworkError(e)) {
getReporter().reportWarning(CommandProtocol.this,
Report.newBuilder(REPORT_NETWORK_ERROR).messageParam(e.getCause().getMessage())
);
} else {
getReporter().reportDetailed(CommandProtocol.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(e).callerParam(sender));
}
}
} }
}, 0L); };
updater.start(type);
updateFinished(); updater.addListener(notify);
} }
private void toggleTimings(CommandSender sender, String[] args) { private void toggleTimings(CommandSender sender, String[] args) {
@ -174,20 +146,6 @@ class CommandProtocol extends CommandBase {
} }
} }
private boolean isNetworkError(Exception e) {
Throwable cause = e.getCause();
if (cause instanceof UnknownHostException) {
// These are always network problems
return true;
} if (cause instanceof IOException) {
// Thanks for making the message a part of the API ...
return cause.getMessage().contains("HTTP response");
} else {
return false;
}
}
/** /**
* Prevent further automatic updates until the next delay. * Prevent further automatic updates until the next delay.
*/ */

Datei anzeigen

@ -47,6 +47,7 @@ import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
import com.comphenix.protocol.metrics.Statistics; import com.comphenix.protocol.metrics.Statistics;
import com.comphenix.protocol.metrics.Updater; import com.comphenix.protocol.metrics.Updater;
import com.comphenix.protocol.metrics.Updater.UpdateResult; import com.comphenix.protocol.metrics.Updater.UpdateResult;
import com.comphenix.protocol.metrics.Updater.UpdateType;
import com.comphenix.protocol.reflect.compiler.BackgroundCompiler; import com.comphenix.protocol.reflect.compiler.BackgroundCompiler;
import com.comphenix.protocol.utility.ChatExtensions; import com.comphenix.protocol.utility.ChatExtensions;
import com.comphenix.protocol.utility.MinecraftVersion; import com.comphenix.protocol.utility.MinecraftVersion;
@ -93,6 +94,10 @@ public class ProtocolLibrary extends JavaPlugin {
*/ */
public static final String MINECRAFT_LAST_RELEASE_DATE = "2013-07-08"; public static final String MINECRAFT_LAST_RELEASE_DATE = "2013-07-08";
// Update information
static final String BUKKIT_DEV_SLUG = "protocollib";
static final int BUKKIT_DEV_ID = 45564;
/** /**
* The number of milliseconds per second. * The number of milliseconds per second.
*/ */
@ -179,8 +184,8 @@ public class ProtocolLibrary extends JavaPlugin {
// Handle unexpected Minecraft versions // Handle unexpected Minecraft versions
MinecraftVersion version = verifyMinecraftVersion(); MinecraftVersion version = verifyMinecraftVersion();
// Set updater // Set updater - this will not perform any update automatically
updater = new Updater(this, logger, "protocollib", getFile(), "protocol.info"); updater = new Updater(this, BUKKIT_DEV_ID, getFile(), UpdateType.NO_DOWNLOAD, true);
unhookTask = new DelayedSingleTask(this); unhookTask = new DelayedSingleTask(this);
protocolManager = PacketFilterManager.newBuilder(). protocolManager = PacketFilterManager.newBuilder().