geforkt von Mirrors/Paper
Made the auto-update-checker suggest channels to server administrators if they're upgrading past their preferred channel.
Dieser Commit ist enthalten in:
Ursprung
a5be079797
Commit
eb934c760d
@ -175,6 +175,7 @@ public final class CraftServer implements Server {
|
|||||||
|
|
||||||
updater = new AutoUpdater(new BukkitDLUpdaterService(configuration.getString("auto-updater.host")), getLogger(), configuration.getString("auto-updater.preferred-channel"));
|
updater = new AutoUpdater(new BukkitDLUpdaterService(configuration.getString("auto-updater.host")), getLogger(), configuration.getString("auto-updater.preferred-channel"));
|
||||||
updater.setEnabled(configuration.getBoolean("auto-updater.enabled"));
|
updater.setEnabled(configuration.getBoolean("auto-updater.enabled"));
|
||||||
|
updater.setSuggestChannels(configuration.getBoolean("auto-updater.suggest-channels"));
|
||||||
updater.getOnBroken().addAll(configuration.getStringList("auto-updater.on-broken"));
|
updater.getOnBroken().addAll(configuration.getStringList("auto-updater.on-broken"));
|
||||||
updater.getOnUpdate().addAll(configuration.getStringList("auto-updater.on-update"));
|
updater.getOnUpdate().addAll(configuration.getStringList("auto-updater.on-update"));
|
||||||
updater.check(serverVersion);
|
updater.check(serverVersion);
|
||||||
|
@ -10,6 +10,23 @@ public class ArtifactDetails {
|
|||||||
private String version;
|
private String version;
|
||||||
private Date created;
|
private Date created;
|
||||||
private FileDetails file;
|
private FileDetails file;
|
||||||
|
private ChannelDetails channel;
|
||||||
|
|
||||||
|
public ChannelDetails getChannel() {
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChannel(ChannelDetails channel) {
|
||||||
|
this.channel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIsBroken() {
|
||||||
|
return isBroken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsBroken(boolean isBroken) {
|
||||||
|
this.isBroken = isBroken;
|
||||||
|
}
|
||||||
|
|
||||||
public FileDetails getFile() {
|
public FileDetails getFile() {
|
||||||
return file;
|
return file;
|
||||||
@ -78,4 +95,34 @@ public class ArtifactDetails {
|
|||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ChannelDetails {
|
||||||
|
private String name;
|
||||||
|
private String slug;
|
||||||
|
private int priority;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPriority() {
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriority(int priority) {
|
||||||
|
this.priority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlug() {
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlug(String slug) {
|
||||||
|
this.slug = slug;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ public class AutoUpdater {
|
|||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
private ArtifactDetails current = null;
|
private ArtifactDetails current = null;
|
||||||
private ArtifactDetails latest = null;
|
private ArtifactDetails latest = null;
|
||||||
|
private boolean suggestChannels = true;
|
||||||
|
|
||||||
public AutoUpdater(BukkitDLUpdaterService service, Logger log, String channel) {
|
public AutoUpdater(BukkitDLUpdaterService service, Logger log, String channel) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
@ -35,6 +36,14 @@ public class AutoUpdater {
|
|||||||
this.enabled = isEnabled;
|
this.enabled = isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean shouldSuggestChannels() {
|
||||||
|
return suggestChannels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuggestChannels(boolean suggestChannels) {
|
||||||
|
this.suggestChannels = suggestChannels;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getOnBroken() {
|
public List<String> getOnBroken() {
|
||||||
return onBroken;
|
return onBroken;
|
||||||
}
|
}
|
||||||
@ -100,6 +109,17 @@ public class AutoUpdater {
|
|||||||
|
|
||||||
log.severe("Unfortunately, there is not yet a newer version suitable for your server. We would advise you wait an hour or two, or try out a dev build.");
|
log.severe("Unfortunately, there is not yet a newer version suitable for your server. We would advise you wait an hour or two, or try out a dev build.");
|
||||||
log.severe("----- ------------------- -----");
|
log.severe("----- ------------------- -----");
|
||||||
|
} else if ((current != null) && (shouldSuggestChannels())) {
|
||||||
|
ArtifactDetails.ChannelDetails prefChan = service.getChannel(channel, "preferred channel details");
|
||||||
|
|
||||||
|
if ((prefChan != null) && (current.getChannel().getPriority() < prefChan.getPriority())) {
|
||||||
|
log.info("----- Bukkit Auto Updater -----");
|
||||||
|
log.info("It appears that you're running a " + current.getChannel().getName() + ", when you've specified in bukkit.yml that you prefer to run " + prefChan.getName() + "s.");
|
||||||
|
log.info("If you would like to be kept informed about new " + current.getChannel().getName() + " releases, it is recommended that you change 'preferred-channel' in your bukkit.yml to '" + current.getChannel().getSlug() + "'.");
|
||||||
|
log.info("With that set, you will be told whenever a new version is available for download, so that you can always keep up to date and secure with the latest fixes.");
|
||||||
|
log.info("If you would like to disable this warning, simply set 'suggest-channels' to false in bukkit.yml.");
|
||||||
|
log.info("----- ------------------- -----");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
@ -13,7 +13,8 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class BukkitDLUpdaterService {
|
public class BukkitDLUpdaterService {
|
||||||
private static final String API_PREFIX = "/api/1.0/downloads/projects/craftbukkit/view/";
|
private static final String API_PREFIX_ARTIFACT = "/api/1.0/downloads/projects/craftbukkit/view/";
|
||||||
|
private static final String API_PREFIX_CHANNEL = "/api/1.0/downloads/channels/";
|
||||||
private static final DateDeserializer dateDeserializer = new DateDeserializer();
|
private static final DateDeserializer dateDeserializer = new DateDeserializer();
|
||||||
private final String host;
|
private final String host;
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ public class BukkitDLUpdaterService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactDetails fetchArtifact(String slug) throws UnsupportedEncodingException, IOException {
|
public ArtifactDetails fetchArtifact(String slug) throws UnsupportedEncodingException, IOException {
|
||||||
URL url = new URL("http", host, API_PREFIX + slug);
|
URL url = new URL("http", host, API_PREFIX_ARTIFACT + slug);
|
||||||
InputStreamReader reader = null;
|
InputStreamReader reader = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -50,6 +51,35 @@ public class BukkitDLUpdaterService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArtifactDetails.ChannelDetails getChannel(String slug, String name) {
|
||||||
|
try {
|
||||||
|
return fetchChannel(slug);
|
||||||
|
} catch (UnsupportedEncodingException ex) {
|
||||||
|
Logger.getLogger(BukkitDLUpdaterService.class.getName()).log(Level.WARNING, "Could not get " + name + ": " + ex.getClass().getSimpleName());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Logger.getLogger(BukkitDLUpdaterService.class.getName()).log(Level.WARNING, "Could not get " + name + ": " + ex.getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArtifactDetails.ChannelDetails fetchChannel(String slug) throws UnsupportedEncodingException, IOException {
|
||||||
|
URL url = new URL("http", host, API_PREFIX_CHANNEL + slug);
|
||||||
|
InputStreamReader reader = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
reader = new InputStreamReader(url.openStream());
|
||||||
|
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, dateDeserializer).setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
|
||||||
|
ArtifactDetails.ChannelDetails fromJson = gson.fromJson(reader, ArtifactDetails.ChannelDetails.class);
|
||||||
|
|
||||||
|
return fromJson;
|
||||||
|
} finally {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class DateDeserializer implements JsonDeserializer<Date> {
|
static class DateDeserializer implements JsonDeserializer<Date> {
|
||||||
private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ auto-updater:
|
|||||||
on-update: [warn-console, warn-ops]
|
on-update: [warn-console, warn-ops]
|
||||||
preferred-channel: rb
|
preferred-channel: rb
|
||||||
host: dl.bukkit.org
|
host: dl.bukkit.org
|
||||||
|
suggest-channels: true
|
||||||
aliases:
|
aliases:
|
||||||
# icanhasbukkit:
|
# icanhasbukkit:
|
||||||
# - version
|
# - version
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren