mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 11:36:51 +01:00
Update to the latest version of Gravity's Updater class.
This commit is contained in:
parent
42395abe75
commit
6a0600cd7f
@ -19,21 +19,15 @@ package com.comphenix.protocol;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
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.UpdateResult;
|
||||
import com.comphenix.protocol.metrics.Updater.UpdateType;
|
||||
import com.comphenix.protocol.timing.TimedListenerManager;
|
||||
import com.comphenix.protocol.timing.TimingReportGenerator;
|
||||
import com.comphenix.protocol.utility.WrappedScheduler;
|
||||
|
||||
/**
|
||||
* Handles the "protocol" administration command.
|
||||
@ -46,10 +40,6 @@ class CommandProtocol extends CommandBase {
|
||||
*/
|
||||
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 Updater updater;
|
||||
private ProtocolConfig config;
|
||||
@ -80,49 +70,31 @@ class CommandProtocol extends CommandBase {
|
||||
}
|
||||
|
||||
public void checkVersion(final CommandSender sender) {
|
||||
// Perform on an async thread
|
||||
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();
|
||||
performUpdate(sender, UpdateType.NO_DOWNLOAD);
|
||||
}
|
||||
|
||||
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
|
||||
WrappedScheduler.runAsynchronouslyOnce(plugin, new Runnable() {
|
||||
Runnable notify = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
UpdateResult result = updater.update(UpdateType.DEFAULT, 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_UPDATE_PLUGIN).error(e).callerParam(sender));
|
||||
}
|
||||
}
|
||||
sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + updater.getResult());
|
||||
|
||||
updater.removeListener(this);
|
||||
updateFinished();
|
||||
}
|
||||
}, 0L);
|
||||
|
||||
updateFinished();
|
||||
};
|
||||
updater.start(type);
|
||||
updater.addListener(notify);
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
|
@ -47,6 +47,7 @@ import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
|
||||
import com.comphenix.protocol.metrics.Statistics;
|
||||
import com.comphenix.protocol.metrics.Updater;
|
||||
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.utility.ChatExtensions;
|
||||
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";
|
||||
|
||||
// Update information
|
||||
static final String BUKKIT_DEV_SLUG = "protocollib";
|
||||
static final int BUKKIT_DEV_ID = 45564;
|
||||
|
||||
/**
|
||||
* The number of milliseconds per second.
|
||||
*/
|
||||
@ -179,8 +184,8 @@ public class ProtocolLibrary extends JavaPlugin {
|
||||
// Handle unexpected Minecraft versions
|
||||
MinecraftVersion version = verifyMinecraftVersion();
|
||||
|
||||
// Set updater
|
||||
updater = new Updater(this, logger, "protocollib", getFile(), "protocol.info");
|
||||
// Set updater - this will not perform any update automatically
|
||||
updater = new Updater(this, BUKKIT_DEV_ID, getFile(), UpdateType.NO_DOWNLOAD, true);
|
||||
|
||||
unhookTask = new DelayedSingleTask(this);
|
||||
protocolManager = PacketFilterManager.newBuilder().
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user