Use the new class here

This commit is contained in:
Minecon724 2024-12-31 13:36:03 +01:00
parent d922221589
commit ad36edd5cd
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
2 changed files with 8 additions and 11 deletions

View file

@ -6,9 +6,9 @@
package eu.m724.tweaks.updater;
import eu.m724.tweaks.DebugLogger;
import eu.m724.tweaks.Language;
import eu.m724.tweaks.updater.cache.VersionedResource;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.FileOutputStream;
@ -19,18 +19,15 @@ import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletionException;
import java.util.logging.Logger;
import java.util.stream.Collectors;
public class UpdateChecker extends BukkitRunnable {
private final Set<VersionedResource> resources;
private final Logger logger;
static final Set<VersionedResource> availableUpdates = new HashSet<>();
static LocalTime lastChecked = null;
UpdateChecker(Plugin plugin, Set<VersionedResource> resources) {
this.logger = Logger.getLogger(plugin.getLogger().getName() + "." + getClass().getSimpleName());
UpdateChecker(Set<VersionedResource> resources) {
this.resources = resources; // TODO make a copy?
}
@ -49,9 +46,9 @@ public class UpdateChecker extends BukkitRunnable {
if (!versionedResource.equals(newResource)) {
resources.remove(versionedResource);
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) {
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 {
if (!newResource.running().equals(newResource.latest())) {
@ -62,7 +59,7 @@ public class UpdateChecker extends BukkitRunnable {
resources.add(newResource);
}
} 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() {
int n = availableUpdates.size();
if (n == 0) return;
logger.info(Language.getString("updateAvailableNotice", n));
DebugLogger.info(Language.getString("updateAvailableNotice", n));
availableUpdates.stream()
.map(u -> "- %s (%s -> %s)".formatted(u.resource().name(), u.running().label(), u.latest().label()))
.forEach(logger::info);
.forEach(DebugLogger::info);
}
@Override

View file

@ -60,7 +60,7 @@ public class UpdaterManager {
)).collect(Collectors.toSet());
new UpdateChecker(plugin, versionedResources)
new UpdateChecker(versionedResources)
.runTaskTimerAsynchronously(plugin, 600, 12 * 3600 * 20);
updatesCommand.setExecutor(new UpdaterCommands());