From 81146d6f0ad3dfb29f982348129b7b5690a5c607 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Thu, 26 Jan 2023 19:35:21 +0100 Subject: [PATCH] Move magic values to pom --- Components/Minepacks-MagicValues/pom.xml | 26 +++++++ .../resources/Minepacks.properties | 3 + .../pcgamingfreaks/Minepacks/MagicValues.java | 69 +++++++++++++++++++ Minepacks/pom.xml | 14 +++- Minepacks/resources/config.yml | 2 +- Minepacks/resources/lang/en.yml | 2 +- .../Bukkit/Command/UpdateCommand.java | 4 +- .../Minepacks/Bukkit/Database/Config.java | 4 +- .../Minepacks/Bukkit/MagicValues.java | 26 ------- .../Minepacks/Bukkit/Minepacks.java | 1 + .../Minepacks/Bukkit/MinepacksBadRabbit.java | 1 + pom.xml | 1 + 12 files changed, 120 insertions(+), 33 deletions(-) create mode 100644 Components/Minepacks-MagicValues/pom.xml create mode 100644 Components/Minepacks-MagicValues/resources/Minepacks.properties create mode 100644 Components/Minepacks-MagicValues/src/at/pcgamingfreaks/Minepacks/MagicValues.java delete mode 100644 Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/MagicValues.java diff --git a/Components/Minepacks-MagicValues/pom.xml b/Components/Minepacks-MagicValues/pom.xml new file mode 100644 index 0000000..76b9fdd --- /dev/null +++ b/Components/Minepacks-MagicValues/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + Minepacks-MagicValues + + Minepacks-Parent + at.pcgamingfreaks + ${revision} + ../../pom.xml + + ${revision} + jar + + Minepacks-MagicValues + Contains the magic values used by Minepacks. + + + clean install + src + + + resources + true + + + + diff --git a/Components/Minepacks-MagicValues/resources/Minepacks.properties b/Components/Minepacks-MagicValues/resources/Minepacks.properties new file mode 100644 index 0000000..665d0e6 --- /dev/null +++ b/Components/Minepacks-MagicValues/resources/Minepacks.properties @@ -0,0 +1,3 @@ +LanguageFileVersion=${languageFileVersion} +ConfigFileVersion=${configFileVersion} +PCGFPluginLibVersion=${pcgfPluginLibVersion} diff --git a/Components/Minepacks-MagicValues/src/at/pcgamingfreaks/Minepacks/MagicValues.java b/Components/Minepacks-MagicValues/src/at/pcgamingfreaks/Minepacks/MagicValues.java new file mode 100644 index 0000000..e5b1966 --- /dev/null +++ b/Components/Minepacks-MagicValues/src/at/pcgamingfreaks/Minepacks/MagicValues.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2023 GeorgH93 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package at.pcgamingfreaks.Minepacks; + +import org.jetbrains.annotations.NotNull; + +import java.io.InputStream; +import java.util.Properties; + +public class MagicValues +{ + public static final int LANG_VERSION; + public static final int CONFIG_VERSION; + public static final String MIN_PCGF_PLUGIN_LIB_VERSION; + public static final String MIN_MC_VERSION_FOR_UPDATES = "1.8"; + + static + { + String pcgfPluginLibVersion = "99999", langVersion = "0", configVersion = "0"; + + try(InputStream propertiesStream = MagicValues.class.getClassLoader().getResourceAsStream("Minepacks.properties")) + { + Properties properties = new Properties(); + properties.load(propertiesStream); + + pcgfPluginLibVersion = properties.getProperty("PCGFPluginLibVersion"); + langVersion = properties.getProperty("LanguageFileVersion"); + configVersion = properties.getProperty("ConfigFileVersion"); + } + catch(Exception e) + { + e.printStackTrace(); + } + MIN_PCGF_PLUGIN_LIB_VERSION = pcgfPluginLibVersion; + // Try to parse the version strings, fall back to a known min version + LANG_VERSION = tryParse(langVersion, 20); + CONFIG_VERSION = tryParse(configVersion, 33); + } + + private static int tryParse(@NotNull String string, int fallbackValue) + { + try + { + return Integer.parseInt(string); + } + catch (NumberFormatException ignored) + { + System.out.println("Failed to parse integer '" + string + "'! Falling back to: " + fallbackValue); + } + return fallbackValue; + } + + private MagicValues() { /* You should not create an instance of this utility class! */ } +} diff --git a/Minepacks/pom.xml b/Minepacks/pom.xml index f1d0832..6454080 100644 --- a/Minepacks/pom.xml +++ b/Minepacks/pom.xml @@ -26,6 +26,10 @@ Normal Release 3.3.0 + + 33 + 20 + 1.0.39-SNAPSHOT @@ -42,11 +46,16 @@ Minepacks-API ${revision} + + at.pcgamingfreaks + Minepacks-MagicValues + ${revision} + at.pcgamingfreaks PluginLib - 1.0.38-SNAPSHOT + ${pcgfPluginLibVersion} @@ -104,6 +113,7 @@ at.pcgamingfreaks:Minepacks-API + at.pcgamingfreaks:Minepacks-MagicValues @@ -175,6 +185,7 @@ at.pcgamingfreaks:Minepacks-API + at.pcgamingfreaks:Minepacks-MagicValues at.pcgamingfreaks:PluginLib @@ -270,6 +281,7 @@ at.pcgamingfreaks:Minepacks-API + at.pcgamingfreaks:Minepacks-MagicValues at.pcgamingfreaks:BadRabbit-Bukkit at.pcgamingfreaks:Minepacks diff --git a/Minepacks/resources/config.yml b/Minepacks/resources/config.yml index 234e3eb..351f2e0 100644 --- a/Minepacks/resources/config.yml +++ b/Minepacks/resources/config.yml @@ -219,4 +219,4 @@ Misc: UseBungeeCord: false # Config file version. Don't touch it! -Version: 33 \ No newline at end of file +Version: ${configFileVersion} \ No newline at end of file diff --git a/Minepacks/resources/lang/en.yml b/Minepacks/resources/lang/en.yml index 1ffa7f8..f1b0ea2 100644 --- a/Minepacks/resources/lang/en.yml +++ b/Minepacks/resources/lang/en.yml @@ -122,4 +122,4 @@ LanguageName: "english" Author: "GeorgH93" # Language file version. Don't touch it! -Version: 20 \ No newline at end of file +Version: ${languageFileVersion} \ No newline at end of file diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/UpdateCommand.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/UpdateCommand.java index e867ba3..741e207 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/UpdateCommand.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/UpdateCommand.java @@ -20,9 +20,9 @@ import at.pcgamingfreaks.Bukkit.MCVersion; import at.pcgamingfreaks.Bukkit.Message.Message; import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksCommand; -import at.pcgamingfreaks.Minepacks.Bukkit.MagicValues; import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks; import at.pcgamingfreaks.Minepacks.Bukkit.Permissions; +import at.pcgamingfreaks.Minepacks.MagicValues; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -48,7 +48,7 @@ public UpdateCommand(Minepacks plugin) @Override public void execute(@NotNull final CommandSender sender, final @NotNull String mainCommandAlias, final @NotNull String alias, final @NotNull String[] args) { - if(MCVersion.isNewerOrEqualThan(MagicValues.MIN_MC_VERSION_FOR_UPDATES)) + if(MCVersion.isNewerOrEqualThan(MCVersion.getFromVersionName(MagicValues.MIN_MC_VERSION_FOR_UPDATES))) { messageCheckingForUpdates.send(sender); /*if_not[STANDALONE]*/ diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java index 3ebd4ab..671c8a3 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java @@ -27,9 +27,9 @@ import at.pcgamingfreaks.Database.DatabaseConnectionConfiguration; import at.pcgamingfreaks.Minepacks.Bukkit.API.WorldBlacklistMode; import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.OldFileUpdater; -import at.pcgamingfreaks.Minepacks.Bukkit.MagicValues; import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks; import at.pcgamingfreaks.Minepacks.Bukkit.ShrinkApproach; +import at.pcgamingfreaks.Minepacks.MagicValues; import at.pcgamingfreaks.Version; import org.bukkit.*; @@ -205,7 +205,7 @@ public ShrinkApproach getShrinkApproach() //region Misc getters public boolean useUpdater() { - return (MCVersion.isNewerOrEqualThan(MagicValues.MIN_MC_VERSION_FOR_UPDATES)) && getConfigE().getBoolean("Misc.AutoUpdate.Enabled", getConfigE().getBoolean("Misc.AutoUpdate", true)); + return (MCVersion.isNewerOrEqualThan(MCVersion.getFromVersionName(MagicValues.MIN_MC_VERSION_FOR_UPDATES))) && getConfigE().getBoolean("Misc.AutoUpdate.Enabled", getConfigE().getBoolean("Misc.AutoUpdate", true)); } public String getUpdateChannel() diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/MagicValues.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/MagicValues.java deleted file mode 100644 index 187ab08..0000000 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/MagicValues.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2022 GeorgH93 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package at.pcgamingfreaks.Minepacks.Bukkit; - -import at.pcgamingfreaks.Bukkit.MCVersion; - -public class MagicValues -{ - public static final String MIN_PCGF_PLUGIN_LIB_VERSION = "1.0.36-SNAPSHOT"; - public static final MCVersion MIN_MC_VERSION_FOR_UPDATES = MCVersion.MC_1_8; -} \ No newline at end of file diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java index 81998c5..f18d336 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java @@ -32,6 +32,7 @@ import at.pcgamingfreaks.Minepacks.Bukkit.Listener.ItemFilter; import at.pcgamingfreaks.Minepacks.Bukkit.Listener.*; import at.pcgamingfreaks.Minepacks.Bukkit.SpecialInfoWorker.NoDatabaseWorker; +import at.pcgamingfreaks.Minepacks.MagicValues; import at.pcgamingfreaks.Plugin.IPlugin; import at.pcgamingfreaks.StringUtils; import at.pcgamingfreaks.Updater.UpdateResponseCallback; diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/MinepacksBadRabbit.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/MinepacksBadRabbit.java index 7fd5479..b6bf2b8 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/MinepacksBadRabbit.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/MinepacksBadRabbit.java @@ -18,6 +18,7 @@ package at.pcgamingfreaks.Minepacks.Bukkit; import at.pcgamingfreaks.BadRabbit.Bukkit.BadRabbit; +import at.pcgamingfreaks.Minepacks.MagicValues; import at.pcgamingfreaks.Version; import org.bukkit.Bukkit; diff --git a/pom.xml b/pom.xml index fc7f306..04b66e9 100644 --- a/pom.xml +++ b/pom.xml @@ -142,6 +142,7 @@ Minepacks-API + Components/Minepacks-MagicValues Minepacks