Add update channel config

This commit is contained in:
GeorgH93 2020-05-05 02:54:40 +02:00
parent d01f91edc9
commit 7cb27ffb15
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
6 changed files with 31 additions and 12 deletions

View File

@ -38,7 +38,7 @@
<dependency>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>PluginLib</artifactId>
<version>1.0.24-SNAPSHOT</version>
<version>1.0.25-SNAPSHOT</version>
</dependency>
<!-- BadRabbit -->
<dependency>

View File

@ -200,10 +200,12 @@ InventoryManagement:
Enabled: true
Misc:
# Enables/Disables the auto-update function of the plugin.
AutoUpdate: true
AutoUpdate:
# When auto update is disabled you still can use the build in update function manually with /backpack update
Enabled: true
Channel: ${updateChannel}
# Enable this option if you are using a BungeeCord setup!
UseBungeeCord: false
# Config file version. Don't touch it!
Version: 28
Version: 29

View File

@ -38,7 +38,7 @@
public class Config extends Configuration implements DatabaseConnectionConfiguration
{
private static final int CONFIG_VERSION = 28, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20;
private static final int CONFIG_VERSION = 29, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20;
public Config(JavaPlugin plugin)
{
@ -64,7 +64,10 @@ protected void doUpgrade(@NotNull YamlFileManager oldConfig)
{
Map<String, String> remappedKeys = new HashMap<>();
if(oldConfig.getVersion() <= 23) remappedKeys.put("ItemFilter.Materials", "ItemFilter.Blacklist");
doUpgrade(oldConfig, remappedKeys);
if(oldConfig.getVersion() <= 28) remappedKeys.put("Misc.AutoUpdate.Enabled", "Misc.AutoUpdate");
Collection<String> keysToKeep = oldConfig.getYamlE().getKeysFiltered("Database\\.SQL\\.(MaxLifetime|IdleTimeout)");
keysToKeep.addAll(oldConfig.getYamlE().getKeysFiltered("Database\\.Tables\\.Fields\\..+"));
doUpgrade(oldConfig, remappedKeys, keysToKeep);
}
}
@ -185,15 +188,28 @@ public ShrinkApproach getShrinkApproach()
}
}
public boolean getAutoUpdate()
//region Misc getters
public boolean useUpdater()
{
return getConfigE().getBoolean("Misc.AutoUpdate", true);
return getConfigE().getBoolean("Misc.AutoUpdate.Enabled", getConfigE().getBoolean("Misc.AutoUpdate", true));
}
public String getUpdateChannel()
{
String channel = getConfigE().getString("Misc.AutoUpdate.Channel", "Release");
if("Release".equals(channel) || "Master".equals(channel) || "Dev".equals(channel))
{
return channel;
}
else logger.info("Unknown update Channel: " + channel);
return null;
}
public boolean isBungeeCordModeEnabled()
{
return getConfigE().getBoolean("Misc.UseBungeeCord", false);
}
//endregion
public long getCommandCooldown()
{

View File

@ -19,5 +19,5 @@
public class MagicValues
{
public static final String MIN_PCGF_PLUGIN_LIB_VERSION = "1.0.24-SNAPSHOT";
public static final String MIN_PCGF_PLUGIN_LIB_VERSION = "1.0.25-SNAPSHOT";
}

View File

@ -137,7 +137,7 @@ public void onEnable()
lang = new Language(this);
load();
if(config.getAutoUpdate()) updater.update();
if(config.useUpdater()) updater.update();
getLogger().info(StringUtils.getPluginEnabledMessage(getDescription().getName()));
}
@ -145,7 +145,7 @@ public void onEnable()
public void onDisable()
{
if(config == null) return;
if(config.getAutoUpdate()) updater.update();
if(config.useUpdater()) updater.update();
unload();
updater.waitForAsyncOperation(); // Wait for an update to finish
getLogger().info(StringUtils.getPluginDisabledMessage(getDescription().getName()));
@ -159,6 +159,7 @@ public void update(final @Nullable UpdateResponseCallback updateResponseCallback
private void load()
{
updater.setChannel(config.getUpdateChannel());
lang.load(config);
database = Database.getDatabase(this);
if(database == null)

View File

@ -7,7 +7,7 @@
<packaging>pom</packaging>
<properties>
<revision>2.3.7-RC1</revision>
<revision>2.3.7</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>