mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancydialogs: Add version fetcher and config
This commit is contained in:
@@ -2,11 +2,6 @@ Commit hash: %COMMIT_HASH%
|
|||||||
|
|
||||||
Commit message: %COMMIT_MESSAGE%
|
Commit message: %COMMIT_MESSAGE%
|
||||||
|
|
||||||
Changes:
|
|
||||||
- Added default values for confirmation dialog
|
|
||||||
- Added support for the select input
|
|
||||||
- Marked Folia as supported
|
|
||||||
|
|
||||||
*(The last commit message does not always directly reflect the changes related to this version.)*
|
*(The last commit message does not always directly reflect the changes related to this version.)*
|
||||||
|
|
||||||
Keep in mind that this is a snapshot version. Snapshot versions are **not** meant to be used in production. They are for **testing purposes only** and may contain bugs or incomplete features. Use at your own risk.
|
Keep in mind that this is a snapshot version. Snapshot versions are **not** meant to be used in production. They are for **testing purposes only** and may contain bugs or incomplete features. Use at your own risk.
|
||||||
@@ -1 +1 @@
|
|||||||
0.0.6
|
0.0.7
|
||||||
@@ -125,8 +125,9 @@ tasks {
|
|||||||
val props = mapOf(
|
val props = mapOf(
|
||||||
"description" to project.description,
|
"description" to project.description,
|
||||||
"version" to getFDVersion(),
|
"version" to getFDVersion(),
|
||||||
"hash" to gitCommitHash.get(),
|
"commit_hash" to gitCommitHash.get(),
|
||||||
"build" to (System.getenv("BUILD_ID") ?: "").ifEmpty { "undefined" }
|
"channel" to (System.getenv("RELEASE_CHANNEL") ?: "").ifEmpty { "undefined" },
|
||||||
|
"platform" to (System.getenv("RELEASE_PLATFORM") ?: "").ifEmpty { "undefined" }
|
||||||
)
|
)
|
||||||
|
|
||||||
inputs.properties(props)
|
inputs.properties(props)
|
||||||
|
|||||||
@@ -25,11 +25,15 @@ import de.oliver.fancyanalytics.logger.LogLevel;
|
|||||||
import de.oliver.fancyanalytics.logger.appender.Appender;
|
import de.oliver.fancyanalytics.logger.appender.Appender;
|
||||||
import de.oliver.fancyanalytics.logger.appender.ConsoleAppender;
|
import de.oliver.fancyanalytics.logger.appender.ConsoleAppender;
|
||||||
import de.oliver.fancyanalytics.logger.appender.JsonAppender;
|
import de.oliver.fancyanalytics.logger.appender.JsonAppender;
|
||||||
|
import de.oliver.fancylib.VersionConfig;
|
||||||
import de.oliver.fancylib.serverSoftware.ServerSoftware;
|
import de.oliver.fancylib.serverSoftware.ServerSoftware;
|
||||||
import de.oliver.fancylib.translations.Language;
|
import de.oliver.fancylib.translations.Language;
|
||||||
import de.oliver.fancylib.translations.TextConfig;
|
import de.oliver.fancylib.translations.TextConfig;
|
||||||
import de.oliver.fancylib.translations.Translator;
|
import de.oliver.fancylib.translations.Translator;
|
||||||
|
import de.oliver.fancylib.versionFetcher.MasterVersionFetcher;
|
||||||
|
import de.oliver.fancylib.versionFetcher.VersionFetcher;
|
||||||
import de.oliver.fancysitula.api.utils.ServerVersion;
|
import de.oliver.fancysitula.api.utils.ServerVersion;
|
||||||
|
import org.apache.maven.artifact.versioning.ComparableVersion;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import revxrsal.commands.Lamp;
|
import revxrsal.commands.Lamp;
|
||||||
@@ -38,10 +42,9 @@ import revxrsal.commands.bukkit.actor.BukkitCommandActor;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
import static java.util.concurrent.CompletableFuture.supplyAsync;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
||||||
|
|
||||||
@@ -49,6 +52,8 @@ public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
|||||||
private final ExtendedFancyLogger fancyLogger;
|
private final ExtendedFancyLogger fancyLogger;
|
||||||
|
|
||||||
private FancyDialogsConfig fdConfig;
|
private FancyDialogsConfig fdConfig;
|
||||||
|
private VersionFetcher versionFetcher;
|
||||||
|
private VersionConfig versionConfig;
|
||||||
private Translator translator;
|
private Translator translator;
|
||||||
private DialogRegistry dialogRegistry;
|
private DialogRegistry dialogRegistry;
|
||||||
private DialogStorage dialogStorage;
|
private DialogStorage dialogStorage;
|
||||||
@@ -98,6 +103,10 @@ public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
|||||||
.findFirst().orElse(translator.getFallbackLanguage());
|
.findFirst().orElse(translator.getFallbackLanguage());
|
||||||
translator.setSelectedLanguage(selectedLanguage);
|
translator.setSelectedLanguage(selectedLanguage);
|
||||||
|
|
||||||
|
versionFetcher = new MasterVersionFetcher(getName());
|
||||||
|
versionConfig = new VersionConfig(this, versionFetcher);
|
||||||
|
versionConfig.load();
|
||||||
|
|
||||||
dialogStorage = new JsonDialogStorage();
|
dialogStorage = new JsonDialogStorage();
|
||||||
Collection<DialogData> dialogData = dialogStorage.loadAll();
|
Collection<DialogData> dialogData = dialogStorage.loadAll();
|
||||||
|
|
||||||
@@ -120,6 +129,25 @@ public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
final ComparableVersion currentVersion = new ComparableVersion(versionConfig.getVersion());
|
||||||
|
supplyAsync(versionFetcher::fetchNewestVersion)
|
||||||
|
.thenApply(Objects::requireNonNull)
|
||||||
|
.whenComplete((newest, error) -> {
|
||||||
|
if (error != null || newest.compareTo(currentVersion) <= 0) {
|
||||||
|
return; // could not get the newest version or already on latest
|
||||||
|
}
|
||||||
|
|
||||||
|
fancyLogger.warn("You are not using the latest version of the FancyDialogs plugin.");
|
||||||
|
getLogger().warning("""
|
||||||
|
|
||||||
|
-------------------------------------------------------
|
||||||
|
You are not using the latest version of the FancyDialogs plugin.
|
||||||
|
Please update to the newest version (%s).
|
||||||
|
%s
|
||||||
|
-------------------------------------------------------
|
||||||
|
""".formatted(newest, versionFetcher.getDownloadUrl()));
|
||||||
|
});
|
||||||
|
|
||||||
if (!ServerSoftware.isPaper()) {
|
if (!ServerSoftware.isPaper()) {
|
||||||
fancyLogger.warn("""
|
fancyLogger.warn("""
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
@@ -131,7 +159,7 @@ public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String version = Bukkit.getMinecraftVersion();
|
String version = Bukkit.getMinecraftVersion();
|
||||||
if (ServerVersion.getByVersion(version).getProtocolVersion() < 771) {
|
if (ServerVersion.getByVersion(version).getProtocolVersion() < ServerVersion.v1_21_6.getProtocolVersion()) {
|
||||||
fancyLogger.error("""
|
fancyLogger.error("""
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
FancyDialogs requires Minecraft version 1.21.6 or higher.
|
FancyDialogs requires Minecraft version 1.21.6 or higher.
|
||||||
@@ -155,7 +183,6 @@ public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
|||||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||||
|
|
||||||
Analytics analytics = new Analytics();
|
Analytics analytics = new Analytics();
|
||||||
analytics.registerMetrics();
|
|
||||||
analytics.start();
|
analytics.start();
|
||||||
|
|
||||||
fancyLogger.info("Successfully enabled FancyDialogs version %s".formatted(getDescription().getVersion()));
|
fancyLogger.info("Successfully enabled FancyDialogs version %s".formatted(getDescription().getVersion()));
|
||||||
@@ -209,6 +236,10 @@ public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
|||||||
return fdConfig;
|
return fdConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VersionConfig getVersionConfig() {
|
||||||
|
return versionConfig;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DialogRegistry getDialogRegistry() {
|
public DialogRegistry getDialogRegistry() {
|
||||||
return dialogRegistry;
|
return dialogRegistry;
|
||||||
|
|||||||
@@ -2,9 +2,15 @@ package com.fancyinnovations.fancydialogs.analytics;
|
|||||||
|
|
||||||
import com.fancyinnovations.fancydialogs.FancyDialogsPlugin;
|
import com.fancyinnovations.fancydialogs.FancyDialogsPlugin;
|
||||||
import de.oliver.fancyanalytics.api.FancyAnalyticsAPI;
|
import de.oliver.fancyanalytics.api.FancyAnalyticsAPI;
|
||||||
|
import de.oliver.fancyanalytics.api.events.Event;
|
||||||
import de.oliver.fancyanalytics.api.metrics.MetricSupplier;
|
import de.oliver.fancyanalytics.api.metrics.MetricSupplier;
|
||||||
|
import de.oliver.fancylib.VersionConfig;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class Analytics {
|
public class Analytics {
|
||||||
|
|
||||||
private final FancyAnalyticsAPI api;
|
private final FancyAnalyticsAPI api;
|
||||||
@@ -14,12 +20,17 @@ public class Analytics {
|
|||||||
api.getConfig().setDisableLogging(true);
|
api.getConfig().setDisableLogging(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerMetrics() {
|
private void registerMetrics() {
|
||||||
api.registerMinecraftPluginMetrics(FancyDialogsPlugin.get());
|
api.registerMinecraftPluginMetrics(FancyDialogsPlugin.get());
|
||||||
api.getExceptionHandler().registerLogger(FancyDialogsPlugin.get().getLogger());
|
api.getExceptionHandler().registerLogger(FancyDialogsPlugin.get().getLogger());
|
||||||
api.getExceptionHandler().registerLogger(Bukkit.getLogger());
|
api.getExceptionHandler().registerLogger(Bukkit.getLogger());
|
||||||
api.getExceptionHandler().registerLogger(FancyDialogsPlugin.get().getFancyLogger());
|
api.getExceptionHandler().registerLogger(FancyDialogsPlugin.get().getFancyLogger());
|
||||||
|
|
||||||
|
api.registerStringMetric(new MetricSupplier<>("language", () -> FancyDialogsPlugin.get().getTranslator().getSelectedLanguage().getLanguageCode()));
|
||||||
|
|
||||||
|
api.registerStringMetric(new MetricSupplier<>("release_channel", () -> FancyDialogsPlugin.get().getVersionConfig().getChannel()));
|
||||||
|
api.registerStringMetric(new MetricSupplier<>("release_platform", () -> FancyDialogsPlugin.get().getVersionConfig().getPlatform()));
|
||||||
|
|
||||||
api.registerStringMetric(new MetricSupplier<>("server_size", () -> {
|
api.registerStringMetric(new MetricSupplier<>("server_size", () -> {
|
||||||
long onlinePlayers = Bukkit.getOnlinePlayers().size();
|
long onlinePlayers = Bukkit.getOnlinePlayers().size();
|
||||||
|
|
||||||
@@ -45,8 +56,51 @@ public class Analytics {
|
|||||||
api.registerNumberMetric(new MetricSupplier<>("amount_dialogs", () -> (double) FancyDialogsPlugin.get().getDialogRegistry().getAll().size()));
|
api.registerNumberMetric(new MetricSupplier<>("amount_dialogs", () -> (double) FancyDialogsPlugin.get().getDialogRegistry().getAll().size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
private void checkIfVersionUpdated() {
|
||||||
api.initialize();
|
VersionConfig versionConfig = FancyDialogsPlugin.get().getVersionConfig();
|
||||||
|
|
||||||
|
String currentVersion = versionConfig.getVersion();
|
||||||
|
String lastVersion = "N/A";
|
||||||
|
|
||||||
|
File versionFile = new File(FancyDialogsPlugin.get().getDataFolder(), "version.yml");
|
||||||
|
if (!versionFile.exists()) {
|
||||||
|
try {
|
||||||
|
Files.write(versionFile.toPath(), currentVersion.getBytes());
|
||||||
|
} catch (IOException e) {
|
||||||
|
FancyDialogsPlugin.get().getFancyLogger().warn("Could not write version file.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
lastVersion = new String(Files.readAllBytes(versionFile.toPath()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
FancyDialogsPlugin.get().getFancyLogger().warn("Could not read version file.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lastVersion.equals(currentVersion)) {
|
||||||
|
FancyDialogsPlugin.get().getFancyLogger().info("Plugin has been updated from version " + lastVersion + " to " + currentVersion + ".");
|
||||||
|
api.sendEvent(
|
||||||
|
new Event("PluginVersionUpdated")
|
||||||
|
.withProperty("from", lastVersion)
|
||||||
|
.withProperty("to", currentVersion)
|
||||||
|
.withProperty("commit_hash", versionConfig.getCommitHash())
|
||||||
|
.withProperty("channel", versionConfig.getChannel())
|
||||||
|
.withProperty("platform", versionConfig.getPlatform())
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.write(versionFile.toPath(), currentVersion.getBytes());
|
||||||
|
} catch (IOException e) {
|
||||||
|
FancyDialogsPlugin.get().getFancyLogger().warn("Could not write version file.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
registerMetrics();
|
||||||
|
api.initialize();
|
||||||
|
checkIfVersionUpdated();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
plugins/fancydialogs/src/main/resources/version.yml
Normal file
4
plugins/fancydialogs/src/main/resources/version.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
version: $version
|
||||||
|
commit_hash: $commit_hash
|
||||||
|
platform: $platform
|
||||||
|
channel: $channel
|
||||||
Reference in New Issue
Block a user