Use the new class here
This commit is contained in:
parent
d922221589
commit
ad36edd5cd
2 changed files with 8 additions and 11 deletions
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
package eu.m724.tweaks.updater;
|
package eu.m724.tweaks.updater;
|
||||||
|
|
||||||
|
import eu.m724.tweaks.DebugLogger;
|
||||||
import eu.m724.tweaks.Language;
|
import eu.m724.tweaks.Language;
|
||||||
import eu.m724.tweaks.updater.cache.VersionedResource;
|
import eu.m724.tweaks.updater.cache.VersionedResource;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -19,18 +19,15 @@ import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class UpdateChecker extends BukkitRunnable {
|
public class UpdateChecker extends BukkitRunnable {
|
||||||
private final Set<VersionedResource> resources;
|
private final Set<VersionedResource> resources;
|
||||||
private final Logger logger;
|
|
||||||
|
|
||||||
static final Set<VersionedResource> availableUpdates = new HashSet<>();
|
static final Set<VersionedResource> availableUpdates = new HashSet<>();
|
||||||
static LocalTime lastChecked = null;
|
static LocalTime lastChecked = null;
|
||||||
|
|
||||||
UpdateChecker(Plugin plugin, Set<VersionedResource> resources) {
|
UpdateChecker(Set<VersionedResource> resources) {
|
||||||
this.logger = Logger.getLogger(plugin.getLogger().getName() + "." + getClass().getSimpleName());
|
|
||||||
this.resources = resources; // TODO make a copy?
|
this.resources = resources; // TODO make a copy?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,9 +46,9 @@ public class UpdateChecker extends BukkitRunnable {
|
||||||
if (!versionedResource.equals(newResource)) {
|
if (!versionedResource.equals(newResource)) {
|
||||||
resources.remove(versionedResource);
|
resources.remove(versionedResource);
|
||||||
if (newResource.running() == null) {
|
if (newResource.running() == null) {
|
||||||
logger.info("Unable to find installed version of %s".formatted(pluginName));
|
DebugLogger.info("Unable to find installed version of %s".formatted(pluginName));
|
||||||
if (versionedResource.running() != null) {
|
if (versionedResource.running() != null) {
|
||||||
logger.info("Did you downgrade %s? If so, clear cache".formatted(pluginName));
|
DebugLogger.info("Did you downgrade %s? If so, clear cache".formatted(pluginName));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!newResource.running().equals(newResource.latest())) {
|
if (!newResource.running().equals(newResource.latest())) {
|
||||||
|
@ -62,7 +59,7 @@ public class UpdateChecker extends BukkitRunnable {
|
||||||
resources.add(newResource);
|
resources.add(newResource);
|
||||||
}
|
}
|
||||||
} catch (CompletionException e) {
|
} catch (CompletionException e) {
|
||||||
logger.severe("Unable to refresh %s: %s".formatted(pluginName, e.getMessage()));
|
DebugLogger.severe("Unable to refresh %s: %s".formatted(pluginName, e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,11 +67,11 @@ public class UpdateChecker extends BukkitRunnable {
|
||||||
private void alert() {
|
private void alert() {
|
||||||
int n = availableUpdates.size();
|
int n = availableUpdates.size();
|
||||||
if (n == 0) return;
|
if (n == 0) return;
|
||||||
logger.info(Language.getString("updateAvailableNotice", n));
|
DebugLogger.info(Language.getString("updateAvailableNotice", n));
|
||||||
|
|
||||||
availableUpdates.stream()
|
availableUpdates.stream()
|
||||||
.map(u -> "- %s (%s -> %s)".formatted(u.resource().name(), u.running().label(), u.latest().label()))
|
.map(u -> "- %s (%s -> %s)".formatted(u.resource().name(), u.running().label(), u.latest().label()))
|
||||||
.forEach(logger::info);
|
.forEach(DebugLogger::info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class UpdaterManager {
|
||||||
)).collect(Collectors.toSet());
|
)).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
|
||||||
new UpdateChecker(plugin, versionedResources)
|
new UpdateChecker(versionedResources)
|
||||||
.runTaskTimerAsynchronously(plugin, 600, 12 * 3600 * 20);
|
.runTaskTimerAsynchronously(plugin, 600, 12 * 3600 * 20);
|
||||||
|
|
||||||
updatesCommand.setExecutor(new UpdaterCommands());
|
updatesCommand.setExecutor(new UpdaterCommands());
|
||||||
|
|
Loading…
Reference in a new issue