diff --git a/.runConfigurations/Run tests.run.xml b/.runConfigurations/Run tests.run.xml new file mode 100644 index 0000000000000000000000000000000000000000..7d21d77617a17620ed6159af2cde980e1f02fe28 --- /dev/null +++ b/.runConfigurations/Run tests.run.xml @@ -0,0 +1,23 @@ +<component name="ProjectRunConfigurationManager"> + <configuration default="false" name="Run tests" type="GradleRunConfiguration" factoryName="Gradle"> + <ExternalSystemSettings> + <option name="executionName" /> + <option name="externalProjectPath" value="$PROJECT_DIR$" /> + <option name="externalSystemIdString" value="GRADLE" /> + <option name="scriptParameters" value="--info --stacktrace" /> + <option name="taskDescriptions"> + <list /> + </option> + <option name="taskNames"> + <list> + <option value="test" /> + </list> + </option> + <option name="vmOptions" /> + </ExternalSystemSettings> + <ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess> + <ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess> + <DebugAllEnabled>false</DebugAllEnabled> + <method v="2" /> + </configuration> +</component> \ No newline at end of file diff --git a/README.md b/README.md index 35f1f66a165e52487ba60bbee250e4fdd8847e9d..c722960515e23d37213006ffee7b03b49fb7d630 100644 --- a/README.md +++ b/README.md @@ -260,6 +260,7 @@ After checking the configuration, run ServerPackCreator again, and it'll do it's ```properties de.griefed.serverpackcreator.versioncheck.prerelease=false de.griefed.serverpackcreator.language=en_us +# Do NOT edit de.griefed.serverpackcreator.configuration.fallbackmodslist MANUALLY. You can update this from the menu in the GUI. de.griefed.serverpackcreator.configuration.fallbackmodslist=3dSkinLayers-,AdvancementPlaques-,AmbientSounds_,armorchroma-,backtools-,BetterAdvancements-,BetterAnimationsCollection-,BetterDarkMode-,BetterF3-,BetterF3-,BetterFoliage-,BetterPingDisplay-,BetterPlacement-,Blur-,catalogue-,cherishedworlds-,classicbar-,clickadv-,ClientTweaks_,configured-,Controlling-,CraftPresence-,CTM-,customdiscordrpc-,CustomMainMenu-,DefaultOptions_,defaultoptions-,desiredservers-,Ding-,drippyloadingscreen_,drippyloadingscreen-,Durability101-,dynamic-music-,DynamicSurroundings-,DynamicSurroundingsHuds-,dynmus-,EiraMoticons_,eiramoticons-,EnchantmentDescriptions-,EquipmentCompare-,extremesoundmuffler-,extremeSoundMuffler-,Fallingleaves-,fallingleaves-,fancymenu_,findme-,flickerfix-,FpsReducer-,FullscreenWindowed-,InventoryEssentials_,InventorySpam-,InventoryTweaks-,invtweaks-,ItemBorders-,itemzoom,itlt-,jeed-,jehc-,jeiintegration_,JEITweaker-,just-enough-harvestcraft-,justenoughbeacons-,JustEnoughCalculation-,JustEnoughProfessions-,JustEnoughProfessions-,JustEnoughResources-,keywizard-,konkrete_,lazydfu-,LegendaryTooltips-,light-overlay-,LightOverlay-,LLOverlayReloaded-,loadmyresources_,lootbeams-,mcbindtype-,medievalmusic-,modnametooltip_,modnametooltip-,moreoverlays-,MouseTweaks-,multihotbar-,MyServerIsCompatible-,Neat ,NotifMod-,OldJavaWarning-,OptiFine,OptiForge,ornaments-,overloadedarmorbar-,PackMenu-,PickUpNotifier-,Ping-,preciseblockplacing-,presencefootsteps-,PresenceFootsteps-,ReAuth-,ResourceLoader-,shutupexperimentalsettings-,SimpleDiscordRichPresence-,smoothboot-,sounddeviceoptions-,SpawnerFix-,spoticraft-,tconplanner-,timestamps-,Tips-,TipTheScales-,Toast Control-,Toast-Control-,ToastControl-,torchoptimizer-,torohealth-,toughnessbar-,TravelersTitles-,WindowedFullscreen-,WorldNameRandomizer-,yisthereautojump- de.griefed.serverpackcreator.configuration.hastebinserver=https://haste.zneix.eu/documents de.griefed.serverpackcreator.serverpack.autodiscoverenabled=true @@ -279,27 +280,27 @@ de.griefed.serverpackcreator.configuration.directories.mustinclude=mods,config,d de.griefed.serverpackcreator.curseforge.api.token= ``` -| Property | Description | -|------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------| -| de.griefed.serverpackcreator.versioncheck.prerelease | `true` or `false`. Whether to check for available pre-releases, too, when checking for updates. | -| de.griefed.serverpackcreator.language | The language in which ServerPackCreator should run. | -| de.griefed.serverpackcreator.configuration.fallbackmodslist | Comma separated fallback-list of clientside-only mods. | -| de.griefed.serverpackcreator.configuration.hastebinserver | Address of a HasteBin server to use for config and logs uploading. | -| de.griefed.serverpackcreator.serverpack.autodiscoverenabled | `true` or `false`. Whether to try and determine sideness of mods in a modpack automatically. | -| de.griefed.serverpackcreator.gui.darkmode | GUI-only. `true` or `false`. Whether to use dark-mode in the GUI. | -| de.griefed.serverpackcreator.configuration.directories.serverpacks | The directory in which server packs will be generated and stored in. | -| de.griefed.serverpackcreator.curseforge.cleanup.enabled | `true` or `false`. Whether to cleanup files after generating a server pack from a CurseForge project. | -| de.griefed.serverpackcreator.serverpack.cleanup.enabled | `true` or `false`. Whether to cleanup files after generating a server pack. | -| de.griefed.serverpackcreator.serverpack.overwrite.enabled | `true` or `false`. Whether an already existing server pack should be overwritten. | -| de.griefed.serverpackcreator.configuration.directories.shouldexclude | List of directories which should not be in a server pack. | -| de.griefed.serverpackcreator.spring.cursecontroller.regenerate.enabled | `true` or `false`. Web only. Whether regeneration of an already available CurseForge project server pack is allowed/enabled. | -| de.griefed.serverpackcreator.spring.schedules.database.cleanup | Web-only. Cron-schedule at which checks are run and server packs cleaned up. | -| de.griefed.serverpackcreator.spring.schedules.files.cleanup | Web-only. Cron-schedule at which checks are run and files from server pack generations are cleaned up. | -| de.griefed.serverpackcreator.spring.schedules.versions.refresh | Web-only. Cron-schedule at which the available Minecraft, Forge and Fabric versions are refreshed. | -| de.griefed.serverpackcreator.spring.artemis.queue.max_disk_usage | Web-only. Maximum disk usage in percent at which no new tasks are accepted, preventing the generation of new server packs. | -| de.griefed.serverpackcreator.configuration.saveloadedconfig | GUI-only. `true` or `false`. Whether to overwrite the last manually loaded configuration file, too. | -| de.griefed.serverpackcreator.configuration.directories.mustinclude | List of directories which must be included in a server pack. | -| de.griefed.serverpackcreator.curseforge.api.token | CurseAPI token used for generating server packs from CurseForge projects. | +| Property | Description | +|------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| de.griefed.serverpackcreator.versioncheck.prerelease | `true` or `false`. Whether to check for available pre-releases, too, when checking for updates. | +| de.griefed.serverpackcreator.language | The language in which ServerPackCreator should run. | +| de.griefed.serverpackcreator.configuration.fallbackmodslist | Comma separated fallback-list of clientside-only mods. Do NOT edit de.griefed.serverpackcreator.configuration.fallbackmodslist MANUALLY. You can update this from the menu in the GUI. | +| de.griefed.serverpackcreator.configuration.hastebinserver | Address of a HasteBin server to use for config and logs uploading. | +| de.griefed.serverpackcreator.serverpack.autodiscoverenabled | `true` or `false`. Whether to try and determine sideness of mods in a modpack automatically. | +| de.griefed.serverpackcreator.gui.darkmode | GUI-only. `true` or `false`. Whether to use dark-mode in the GUI. | +| de.griefed.serverpackcreator.configuration.directories.serverpacks | The directory in which server packs will be generated and stored in. | +| de.griefed.serverpackcreator.curseforge.cleanup.enabled | `true` or `false`. Whether to cleanup files after generating a server pack from a CurseForge project. | +| de.griefed.serverpackcreator.serverpack.cleanup.enabled | `true` or `false`. Whether to cleanup files after generating a server pack. | +| de.griefed.serverpackcreator.serverpack.overwrite.enabled | `true` or `false`. Whether an already existing server pack should be overwritten. | +| de.griefed.serverpackcreator.configuration.directories.shouldexclude | List of directories which should not be in a server pack. | +| de.griefed.serverpackcreator.spring.cursecontroller.regenerate.enabled | `true` or `false`. Web only. Whether regeneration of an already available CurseForge project server pack is allowed/enabled. | +| de.griefed.serverpackcreator.spring.schedules.database.cleanup | Web-only. Cron-schedule at which checks are run and server packs cleaned up. | +| de.griefed.serverpackcreator.spring.schedules.files.cleanup | Web-only. Cron-schedule at which checks are run and files from server pack generations are cleaned up. | +| de.griefed.serverpackcreator.spring.schedules.versions.refresh | Web-only. Cron-schedule at which the available Minecraft, Forge and Fabric versions are refreshed. | +| de.griefed.serverpackcreator.spring.artemis.queue.max_disk_usage | Web-only. Maximum disk usage in percent at which no new tasks are accepted, preventing the generation of new server packs. | +| de.griefed.serverpackcreator.configuration.saveloadedconfig | GUI-only. `true` or `false`. Whether to overwrite the last manually loaded configuration file, too. | +| de.griefed.serverpackcreator.configuration.directories.mustinclude | List of directories which must be included in a server pack. | +| de.griefed.serverpackcreator.curseforge.api.token | CurseAPI token used for generating server packs from CurseForge projects. | # 5.1.2 Default `application.properties` @@ -362,304 +363,13 @@ If you wish to run ServerPackCreator with your locale (if it is already supporte 2. Running `java -jar ServerPackCreator-x.x.x.jar` without `-lang en_us` or any other language will set the locale to en_us by default and create the lang.properties-file. 3. Modify the `serverpackcreator.properties`-file in the same directory as ServerPackCreator-X-X-X.jar and set your locale like this `lang=your_locale` for example `lang=en_us` -## 6.2 Using the GUI +## 6.2 Using ServerPackCreator -You want to create a server pack for your modpack, right? +**Detailed How-To guides are available at [my wiki](https://wiki.griefed.de/en/Documentation/ServerPackCreator/ServerPackCreator-HowTo)!** -There are a couple of things you need to do in order to create a server pack for your modpack: +Make sure to give them a read if you are just getting started with ServerPackCreator, or you need some help. -**1:** Find out whether any mod in your modpack is a clientside-only mod. Those are often mods which only add things to Minecraft which are of a graphical nature, like UI stuff. You need to know whether any mod in your modpack is a clientside-only mod, because having clientside-only mods in your server pack could crash your server unexpectedly. - -**2:** Find the modloader, the modloader version and which Minecraft version your modpack is for. - -**3:** Consider the folders in your modpack directory which you must inlcude in server pack in order for your server to work. Usually folders like `config` ,`mods` ,`scripts` and so on. - -Those are the most important parts in making a server pack, I find. - -If you're on Windows, go to <https://github.com/Griefed/ServerPackCreator/releases/latest> and download `serverpackcreator-X.X.X.exe` and place it somewhere you will remember. If you're on Linux or Mac, download the `serverpackcreator-X.X.X.jar` - -The .exe can be started with a regular double click. The .jar needs to be started from the CLI with `java -jar serverpackcreator-X.X.X.jar`. - -The first run of ServerPackCreator will create a couple of default files in the directory you started it in. If you plan on including any of these in your server pack, make sure you've customized them to your needs. They're in a directory called `server_files` in the same directory in which you executed `ServerPackCreator-X.X.X.jar` or `ServerPackCreator-X.X.X.exe` and will contain the following files which you can customize to your hearts content: - -- `server.properties` - -- `server-icon.png` - -Once the ServerPackCreator window opened, you need to fill in all the information you gathered in the previously mentioned steps 1 to 3 into the designated textfields. -From top to bottom: - -**Enter the path to your modpack directory:** You will also need to configure ServerPackCreator to point at the directory your modpack files are in. Click the folder icon on the right hand side to the first textfield, which will open your file explorer so you can browse to and select your modpack directory. - -**Enter the list of clientside-only mods in your modpack:** Enter the list of clientside-only mods for your modpack into the second textfield.Every entry must be separated by a "," and NOT contain special characters such as [ \] ( ) \ / ; - -**Enter the list of directories or files in your modpack to include in the server pack:** Enter the list of folders of your modpack which need to be included in your server pack. Every entry must be separated by a "," and NOT contain special characters such as [ \] ( ) \ / ; - -**Enter the path to your Java executable/binary (optional):** If you are not sure where your java installation is located at, you can leave it blank and ServerPackCreator will try to determine said path by itself. - -**Enter the Minecraft version your modpack uses:** Enter the Minecraft version your modpack runs in - -**Enter the modloader your modpack uses:** Enter the modloader your modpack runs with. Must be either Forge or Fabric. Other modloaders are not supported. - -**Enter the version of the modloader your modpack uses:** Enter the version of the modloader your modpack uses. - -Last but not least, checkboxes: - -**"Install modloader server in server pack?"** Does what it says on the tin. Whehter to install the Forge/Fabric server for the version you specified. - -**"Include server-icon.png in server pack?"** Whether to include a custom server-icon.png in your server pack. - -**"Include server.properties in server pack"** Whether to include a custom server.properties in your server pack. - -**"Include start scripts in server pack?"** Whether to include custom start scripts for your server pack. - -**"Create ZIP-archive of server pack?"** Whether ServerPackCreator should create a zipped archive of your server pack. - -**Edit JVM flags** Open the dialog for editing of your JVM flags / Java Args via Menu->Edit->Edit Start-Scripts Java Args. - -After you've customized and configured everything to your liking, click the button on the bottom. ServerPackCreator will check your configuration for errors and start generating your server pack should no errors be detected. When the server pack is finished, a prompt will open which will ask you whether you want to browse your newly created server pack in your file explorer. - -That's pretty much it! Sounds like a lot, but honestly, all the stuff you need to do in order to configure ServerPackCreator you pretty much need to do anyway if you want to create a server pack. - -Have fun! - -## 6.3 Using the Command-line Interface - -### 6.3.1 Windows - -**1.** Download the latest version of ServerPackCreator from the Releases page: https://github.com/Griefed/ServerPackCreator/releases - -**2.** Copy the .jar file to the partent directory of your modpack. Example: - - - -**3.** Open a command prompt by Shift-Right-Clicking into a free space of the explorer window, followed by a click on "Open command prompt here": - - - -**4.** Start the initial setup of ServerPackCreator by running it with the command: `java -jar ServerPackCreator-X.X.X.jar` (X.X.X corresponds to the version you downloaded. It will probably be different to the version used in these screenshots.) - -This will generate the default files of ServerpackCreator and tell you to customize these files before running again. Example for the directory above: -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ ├── server.properties -└── ServerPackCreator.jar -``` - -With the example above, the settings would look exactly like they are already set in the serverpackcreator.conf (or creator.conf if using older version). Note that modpackDir points at a directory *relative* to the ServerPackCreator.jar. Absolute paths *should* be usable, but are currently untested. - -Configure the config file to your liking. Double check the path to your Java installation if you intend on having SPC install the modloader-server. - -For a detailed explanation of the configuration, check chapter 5. Configuration - -**5.** After you double checked that you've set up your serverpackcreator.conf it is time to run ServerPackCreator again. Simply run `java -jar ServerPackCreator-X.X.X.jar` again (X.X.X corresponds to the version you downloaded. It will probably be different to the version used in these screenshots.) - -**6.** ServerPackCreator should now start telling you what it is currently doing. Logging of these actions may be very verbose, depending on which part SPC is currently working on. Should you have configured your config file correctly and should I have released a bug-free version of SPC, it will run until the console says "Done!". (Depending on the hardware you are running on, this may take some time.) - -Included in one of the last messages by SPC is the location of your newly generated serverpack. - -If you've set `includeZipCreation` to true, there will also be a zip-file called `server_pack.zip` in your modpack folder. - -Please note: The zip file **does not** contain Mojang's minecraft-server.jar. Distributing Mojang's software is against their Terms of Service and End User License Agreement. The zip file *does* however, contain scripts for both Windows and Linux, to download the minecraft-server.jar for your serverpack. That means that Users who download your serverpack simply need to run either of those two scripts and it will download the needed file for their modded Minecraft server. - -Enjoy! - -Example after successfully running SPC: - -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ ├── addons.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ └── server.properties -├── ServerPackCreator-1.1.0.jar -└── server-packs - └── Survive Create Prosper 4 - └── ... - └── Survive Create Prosper 4_server_pack.zip -``` - -### 6.3.2 Linux - -**1.** Switch to a directory where you want ServerPackCreator to be stored in and where it can save and deploy all of its files. - -**2.** Create and save the following script to download the latest version of ServerPackCreator: -```bash -#!/bin/bash -# Retrieve the latest version of ServerPackCreator - -VERSION=$(curl --silent "https://api.github.com/repos/Griefed/ServerPackCreator/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') - -echo "Latest ServerPackCreator version is: $VERSION" - -echo "" - -echo "Retrieving..." - -curl -o ServerPackCreator-$VERSION.jar -L https://github.com/Griefed/ServerPackCreator/releases/download/$VERSION/serverpackcreator-$VERSION.jar - -if [ -f ServerPackCreator-$VERSION.jar ]; then - echo "Successfully retrieved ServerPackCreator version $VERSION" -else - echo "Something seems to have gone wrong..." - echo "ServerPackCreator-$VERSION could not be found..." -fi -``` - -Save it, `chmod +x` it, and run it. - -This script will download the latest version of ServerPackCreator from GitHub and safe it to a file called ServerPackCreator-(version).jar. - -**3.** Start the initial setup of ServerPackCreator by running it with the command: java -jar ServerPackCreator-X.X.X.jar (X.X.X corresponds to the version you downloaded.) - -This will generate the default files of ServerpackCreator and tell you to customize these files before running again. Example: - -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ ├── addons.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ └── server.properties -└── ServerPackCreator-X.X.X.jar -``` - -With the example above, the settings would look exactly like they are already set in the serverpackcreator.conf. - -Configure the config file to your liking. Double check the path to your Java installation if you intend on having SPC install the modloader-server. - -For a detailed explanation of the configuration, check chapter 5. Configuration. - -**6.** After you double checked that you've set up your serverpackcreator.conf (or creator.conf if using older version) it is time to run ServerPackCreator again. Simply run `java -jar ServerPackCreator-X.X.X.jar` again (X.X.X corresponds to the version you downloaded. It will probably be different to the version used in these screenshots.) - -**7.** ServerPackCreator should now start telling you what it is currently doing. Logging of these actions may be very verbose, depending on which part SPC is currently working on. Should you have configured your config file correctly and should I have released a bug-free version of SPC, it will run until the console says "Done!". (Depending on the hardware you are running on, this may take some time.) - -Included in one of the last messages by SPC is the location of your newly generated serverpack. - -If you've set `includeZipCreation` to true, there will also be a zip-file called `server_pack.zip` in your modpack folder. - -Please note: The zip file **does not** contain Mojang's minecraft-server.jar. Distributing Mojang's software is against their Terms of Service and End User License Agreement. The zip file *does* however, contain scripts for both Windows and Linux, to download the minecraft-server.jar for your serverpack. That means that Users who download your serverpack simply need to run either of those two scripts and it will download the needed file for their modded Minecraft server. - -Enjoy! - -Example after successfully running SPC: - -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ ├── addons.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ └── server.properties -├── ServerPackCreator-1.1.0.jar -└── server-packs - └── Survive Create Prosper 4 - └── ... - └── Survive Create Prosper 4_server_pack.zip -``` - -### 6.3.3 Mac - -(By user [whitebear60](https://github.com/whitebear60)) - -**1.** Download the latest version of ServerPackCreator from the Releases page: https://github.com/Griefed/ServerPackCreator/releases - -**2.** Copy the .jar file to the partent directory of your modpack. Example: - - - -**3.** Open Terminal using Spotlight, Launchpad or by running `Terminal.app` from `/Applications/Utilities` folder - -**4.** Change the active directory to the one with ServerPackCreator jar and your modpacks. - - -**5.** Start the initial setup of ServerPackCreator by running it with the command: `java -jar ServerPackCreator-X.X.X.jar` (X.X.X corresponds to the version you downloaded. It will probably be different to the version used in these screenshots.) - -This will generate the default files of ServerpackCreator and tell you to customize these files before running again. Example for the directory above: - -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ ├── addons.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ └── server.properties -├── ServerPackCreator-1.1.0.jar -└── server-packs - └── Survive Create Prosper 4 - └── ... - └── Survive Create Prosper 4_server_pack.zip -``` - -With the example above, the settings would look exactly like they are already set in the serverpackcreator.conf. Note that modpackDir points at a directory *relative* to the ServerPackCreator.jar. Absolute paths *should* be usable, but are currently untested. - -Configure the config file to your liking. Double check the path to your Java installation if you intend on having SPC install the modloader-server. - -For a detailed explanation of the configuration, check chapter 5. Configuration - -**6.** After you double checked that you've set up your serverpackcreator.conf (or creator.conf if using older version) it is time to run ServerPackCreator again. Simply run `java -jar ServerPackCreator-X.X.X.jar` again (X.X.X corresponds to the version you downloaded. It will probably be different to the version used in these screenshots.) - -**7.** ServerPackCreator should now start telling you what it is currently doing. Logging of these actions may be very verbose, depending on which part SPC is currently working on. Should you have configured your config file correctly and should I have released a bug-free version of SPC, it will run until the console says "Done!". (Depending on the hardware you are running on, this may take some time.) - -Included in one of the last messages by SPC is the location of your newly generated serverpack. - -If you've set `includeZipCreation` to true, there will also be a zip-file called `server_pack.zip` in your modpack folder. - -Please note: The zip file **does not** contain Mojang's minecraft-server.jar. Distributing Mojang's software is against their Terms of Service and End User License Agreement. The zip file *does* however, contain scripts for both Windows and Linux, to download the minecraft-server.jar for your serverpack. That means that Users who download your serverpack simply need to run either of those two scripts and it will download the needed file for their modded Minecraft server. - -Enjoy! - -Example after successfully running SPC: - -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ ├── addons.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ └── server.properties -├── ServerPackCreator-1.1.0.jar -└── server-packs - └── Survive Create Prosper 4 - └── ... - └── Survive Create Prosper 4_server_pack.zip -``` - -## 6.4 Docker +## 6.3 Docker | Tags | Description | |-----------|-----------------------------------------------------------------------------------------------| @@ -675,7 +385,7 @@ When running as a docker container, there are a couple more settings you need to | PGID | The groupID under which this container is run as. Important for file access and permissions. Run **cat /etc/passwd | grep -i $(whoami)** to find your groupID. | | STARTUP_PARAMETER | Decides which mode ServerPackCreator will start in. `cli` for commandline interface, which will generate a server pack from the given config. `web` for starting ServerPackCreator as a webservice. | | -### 6.4.1 Using docker-compose: +### 6.3.1 Using docker-compose: ```docker-compose.yml version: "2" diff --git a/backend/main/java/de/griefed/serverpackcreator/ApplicationPlugins.java b/backend/main/java/de/griefed/serverpackcreator/ApplicationPlugins.java deleted file mode 100644 index 658a459059a2fc553e51ef1263c8b3b45e55dd0a..0000000000000000000000000000000000000000 --- a/backend/main/java/de/griefed/serverpackcreator/ApplicationPlugins.java +++ /dev/null @@ -1,129 +0,0 @@ -/* Copyright (C) 2022 Griefed - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - * - * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE - */ -package de.griefed.serverpackcreator; - -import de.griefed.serverpackcreator.plugins.serverpackhandler.PostGenExtension; -import de.griefed.serverpackcreator.plugins.serverpackhandler.PreZipExtension; -import de.griefed.serverpackcreator.plugins.serverpackhandler.PreGenExtension; -import de.griefed.serverpackcreator.plugins.swinggui.TabExtension; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.util.FileUtils; -import org.pf4j.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -/** - * Manager for ServerPackCreator plugins. In itself it doesn't do much. It gathers lists of all available extensions for - * {@link TabExtension},{@link PreGenExtension},{@link PreZipExtension} and {@link PostGenExtension} so they can then be - * run during server pack generation and during initialization of the GUI. - * @author Griefed - */ -@Component -public class ApplicationPlugins extends JarPluginManager { - - private static final Logger LOG = LogManager.getLogger(ApplicationPlugins.class); - - public final List<PreGenExtension> PLUGINS_SERVERPACKSTART; - public final List<PreZipExtension> PLUGINS_SERVERPACKCREATED; - public final List<PostGenExtension> PLUGINS_SERVERPACKARCHIVECREATED; - public final List<TabExtension> PLUGINS_TABBEDPANE; - - @Autowired - public ApplicationPlugins() { - - LOG.info("Plugins directory: " + new File(System.getProperty("pf4j.pluginsDir", "plugins")).getAbsolutePath()); - - loadPlugins(); - startPlugins(); - - this.PLUGINS_SERVERPACKSTART = getExtensions(PreGenExtension.class); - this.PLUGINS_SERVERPACKCREATED = getExtensions(PreZipExtension.class); - this.PLUGINS_SERVERPACKARCHIVECREATED = getExtensions(PostGenExtension.class); - this.PLUGINS_TABBEDPANE = getExtensions(TabExtension.class); - - availablePluginsAndExtensions(); - } - - @Override - protected ExtensionFactory createExtensionFactory() { - return new SingletonExtensionFactory(); - } - - private void availablePluginsAndExtensions() { - if (PLUGINS_SERVERPACKSTART.size() > 0) { - LOG.info("Available PreGenExtension plugins:"); - for (PreGenExtension start : PLUGINS_SERVERPACKSTART) { - LOG.info("Name: " + start.getName()); - LOG.info("Description:" + start.getDescription()); - LOG.info("Version: " + start.getVersion()); - LOG.info("Author: " + start.getAuthor()); - } - } else { - LOG.info("No PreGenExtensions installed."); - } - - if (PLUGINS_SERVERPACKCREATED.size() > 0) { - LOG.info("Available PreZipExtension plugins:"); - for (PreZipExtension created : PLUGINS_SERVERPACKCREATED) { - LOG.info("Name: " + created.getName()); - LOG.info("Description:" + created.getDescription()); - LOG.info("Version: " + created.getVersion()); - LOG.info("Author: " + created.getAuthor()); - } - } else { - LOG.info("No PreZipExtension installed."); - } - - if (PLUGINS_SERVERPACKARCHIVECREATED.size() > 0) { - LOG.info("Available PostGenExtension plugins:"); - for (PostGenExtension archive : PLUGINS_SERVERPACKARCHIVECREATED) { - LOG.info("Name: " + archive.getName()); - LOG.info("Description:" + archive.getDescription()); - LOG.info("Version: " + archive.getVersion()); - LOG.info("Author: " + archive.getAuthor()); - } - } else { - LOG.info("No PostGenExtension installed."); - } - - if (PLUGINS_TABBEDPANE.size() > 0) { - LOG.info("Available TabExtension plugins:"); - for (TabExtension pane : PLUGINS_TABBEDPANE) { - LOG.info("Name: " + pane.getName()); - LOG.info("Description:" + pane.getDescription()); - LOG.info("Version: " + pane.getVersion()); - LOG.info("Author: " + pane.getAuthor()); - } - } else { - LOG.info("No TabExtension installed."); - } - - - - - - - } -} diff --git a/backend/main/java/de/griefed/serverpackcreator/ApplicationProperties.java b/backend/main/java/de/griefed/serverpackcreator/ApplicationProperties.java index c201df40fdd233e2706173ce45f586cb69ce807a..63c700b3dc91a53d921ea88b5d99cbbadad0c4b4 100644 --- a/backend/main/java/de/griefed/serverpackcreator/ApplicationProperties.java +++ b/backend/main/java/de/griefed/serverpackcreator/ApplicationProperties.java @@ -28,7 +28,7 @@ import org.springframework.stereotype.Component; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; -import java.nio.file.Path; +import java.nio.file.Files; import java.nio.file.Paths; import java.util.*; @@ -50,9 +50,19 @@ public class ApplicationProperties extends Properties { public final File FILE_FORGE_ONE_SEVEN_USER_JVM_ARGS = new File("user_jvm_args.txt"); private final String FALLBACK_MODS_DEFAULT_ASSTRING = "3dSkinLayers-," + + "3dskinlayers-," + + "Absolutely-Not-A-Zoom-Mod-," + "AdvancementPlaques-," + + "AmbientEnvironment-," + "AmbientSounds_," + + "antighost-," + "armorchroma-," + + "armorpointspp-," + + "ArmorSoundTweak-," + + "authme-," + + "autoreconnect-," + + "auto-reconnect-," + + "axolotl-item-fix-," + "backtools-," + "BetterAdvancements-," + "BetterAnimationsCollection-," + @@ -61,12 +71,15 @@ public class ApplicationProperties extends Properties { "BetterFoliage-," + "BetterPingDisplay-," + "BetterPlacement-," + + "BetterTaskbar-," + "bhmenu-," + "BH-Menu-," + "Blur-," + + "borderless-mining-," + "catalogue-," + "charmonium-," + "Charmonium-," + + "chat_heads-," + "cherishedworlds-," + "classicbar-," + "clickadv-," + @@ -75,20 +88,24 @@ public class ApplicationProperties extends Properties { "Controlling-," + "CraftPresence-," + "CTM-," + + "cullleaves-," + "customdiscordrpc-," + "CustomMainMenu-," + "dashloader-," + "DefaultOptions_," + "defaultoptions-," + + "DeleteWorldsToTrash-," + "desiredservers-," + "Ding-," + "drippyloadingscreen_," + "drippyloadingscreen-," + + "DripSounds-," + "Durability101-," + "dynamic-music-," + "DynamicSurroundings-," + "DynamicSurroundingsHuds-," + "dynmus-," + + "effective-," + "EiraMoticons_," + "eiramoticons-," + "EnchantmentDescriptions-," + @@ -96,11 +113,13 @@ public class ApplicationProperties extends Properties { "EquipmentCompare-," + "extremesoundmuffler-," + "extremeSoundMuffler-," + + "fabricemotes-," + "Fallingleaves-," + "fallingleaves-," + "fancymenu_," + "findme-," + "flickerfix-," + + "FPS-Monitor-," + "FpsReducer-," + "FullscreenWindowed-," + "InventoryEssentials_," + @@ -120,6 +139,7 @@ public class ApplicationProperties extends Properties { "JustEnoughProfessions-," + "JustEnoughProfessions-," + "JustEnoughResources-," + + "keymap-," + "keywizard-," + "konkrete_," + "lazydfu-," + @@ -135,9 +155,13 @@ public class ApplicationProperties extends Properties { "modnametooltip-," + "moreoverlays-," + "MouseTweaks-," + + "movement-vision-," + "multihotbar-," + + "musicdr-," + + "music-duration-reducer-," + "MyServerIsCompatible-," + "Neat ," + + "ngrok-lan-expose-mod-," + "NotifMod-," + "OldJavaWarning-," + "OptiFine," + @@ -288,7 +312,7 @@ public class ApplicationProperties extends Properties { * but has the advantage of always providing default values if any property in the applications.properties * on the filesystem should be commented out. */ - try (InputStream inputStream = new FileInputStream("serverpackcreator.properties")) { + try (InputStream inputStream = Files.newInputStream(Paths.get("serverpackcreator.properties"))) { new Properties(); load(inputStream); } catch ( @@ -316,7 +340,7 @@ public class ApplicationProperties extends Properties { this.setProperty("de.griefed.serverpackcreator.configuration.directories.serverpacks",tempDir); this.directoryServerPacks = tempDir; - try (OutputStream outputStream = new FileOutputStream(this.FILE_SERVERPACKCREATOR_PROPERTIES)) { + try (OutputStream outputStream = Files.newOutputStream(this.FILE_SERVERPACKCREATOR_PROPERTIES.toPath())) { this.store(outputStream, null); } catch (IOException ex) { LOG.error("Couldn't write properties-file.", ex); @@ -410,7 +434,7 @@ public class ApplicationProperties extends Properties { */ public ApplicationProperties reload() { - try (InputStream inputStream = new FileInputStream("serverpackcreator.properties")) { + try (InputStream inputStream = Files.newInputStream(Paths.get("serverpackcreator.properties"))) { new Properties(); load(inputStream); } catch ( @@ -434,7 +458,7 @@ public class ApplicationProperties extends Properties { this.setProperty("de.griefed.serverpackcreator.configuration.directories.serverpacks",tempDir); this.directoryServerPacks = tempDir; - try (OutputStream outputStream = new FileOutputStream(this.FILE_SERVERPACKCREATOR_PROPERTIES)) { + try (OutputStream outputStream = Files.newOutputStream(this.FILE_SERVERPACKCREATOR_PROPERTIES.toPath())) { this.store(outputStream, null); } catch (IOException ex) { LOG.error("Couldn't write properties-file.", ex); @@ -633,6 +657,71 @@ public class ApplicationProperties extends Properties { return isCurseForgeActivated; } + /** + * Update the fallback clientside-only modlist of our <code>serverpackcreator.properties</code> from the main-repository + * or one of its mirrors. + * @author Griefed + * @return <code>true</code> if the fallback-property was updated. + */ + public boolean updateFallback() { + + Properties properties; + + try (InputStream github = new URL("https://raw.githubusercontent.com/Griefed/ServerPackCreator/main/backend/main/resources/serverpackcreator.properties").openStream()) { + + properties = new Properties(); + properties.load(github); + + } catch (IOException e) { + + LOG.debug("GitHub could not be reached. Checking GitLab.",e); + properties = null; + try (InputStream gitlab = new URL("https://gitlab.com/Griefed/ServerPackCreator/-/raw/main/backend/main/resources/serverpackcreator.properties").openStream()) { + + properties = new Properties(); + properties.load(gitlab); + + } catch (IOException ex) { + LOG.debug("GitLab could not be reached. Checking GitGriefed",ex); + properties = null; + try (InputStream gitgriefed = new URL("https://git.griefed.de/Griefed/ServerPackCreator/-/raw/main/backend/main/resources/serverpackcreator.properties").openStream()) { + + properties = new Properties(); + properties.load(gitgriefed); + + } catch (IOException exe) { + LOG.debug("GitGriefed could not be reached.",exe); + properties = null; + } + } + } + + if (properties != null && + getProperty("de.griefed.serverpackcreator.configuration.fallbackmodslist").hashCode() != + properties.getProperty("de.griefed.serverpackcreator.configuration.fallbackmodslist").hashCode()) { + + setProperty( + "de.griefed.serverpackcreator.configuration.fallbackmodslist", + properties.getProperty("de.griefed.serverpackcreator.configuration.fallbackmodslist") + ); + + try (OutputStream outputStream = Files.newOutputStream(this.FILE_SERVERPACKCREATOR_PROPERTIES.toPath())) { + this.store(outputStream, null); + } catch (IOException ex) { + LOG.error("Couldn't write properties-file.", ex); + } + + this.listFallbackMods = new ArrayList<>(Arrays.asList(this.getProperty("de.griefed.serverpackcreator.configuration.fallbackmodslist",this.FALLBACK_MODS_DEFAULT_ASSTRING).split(","))); + LOG.debug("Fallbackmodslist set to: " + this.listFallbackMods); + LOG.info("The fallback-list for clientside only mods has been updated."); + return true; + + } else { + LOG.info("No fallback-list updates available."); + return false; + } + } + @Override public String toString() { return "ApplicationProperties{" + diff --git a/backend/main/java/de/griefed/serverpackcreator/ConfigurationHandler.java b/backend/main/java/de/griefed/serverpackcreator/ConfigurationHandler.java index 3b729225a5c5774f81d724259d0f234d929e76e5..8a13e08f5fcb14a0b59357094ebf99cd97c38ee7 100644 --- a/backend/main/java/de/griefed/serverpackcreator/ConfigurationHandler.java +++ b/backend/main/java/de/griefed/serverpackcreator/ConfigurationHandler.java @@ -28,7 +28,9 @@ import de.griefed.serverpackcreator.curseforge.InvalidFileException; import de.griefed.serverpackcreator.curseforge.InvalidModpackException; import de.griefed.serverpackcreator.i18n.LocalizationManager; import de.griefed.serverpackcreator.spring.serverpack.ServerPackModel; -import de.griefed.serverpackcreator.utilities.*; +import de.griefed.serverpackcreator.utilities.ConfigUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -54,13 +56,10 @@ public class ConfigurationHandler { private final LocalizationManager LOCALIZATIONMANAGER; private final CurseCreateModpack CURSECREATEMODPACK; - private final VersionLister VERSIONLISTER; + private final VersionMeta VERSIONMETA; private final ApplicationProperties APPLICATIONPROPERTIES; - private final BooleanUtilities BOOLEANUTILITIES; + private final Utilities UTILITIES; private final ConfigUtilities CONFIGUTILITIES; - private final ListUtilities LISTUTILITIES; - private final StringUtilities STRINGUTILITIES; - private final SystemUtilities SYSTEMUTILITIES; /** * <strong>Constructor</strong><p> @@ -74,19 +73,15 @@ public class ConfigurationHandler { * @param injectedCurseCreateModpack Instance of {@link CurseCreateModpack} in case the modpack has to be created from a combination of * CurseForge projectID and fileID, from which to <em>then</em> create the server pack. * @param injectedApplicationProperties Instance of {@link Properties} required for various different things. - * @param injectedVersionLister Instance of {@link VersionLister} required for everything version-related. - * @param injectedBooleanUtilities Instance of {@link BooleanUtilities}. - * @param injectedListUtilities Instance of {@link ListUtilities}. - * @param injectedStringUtilities Instance of {@link StringUtilities}. - * @param injectedSystemUtilities Instance of {@link SystemUtilities}. + * @param injectedVersionMeta Instance of {@link VersionMeta} required for everything version-related. + * @param injectedUtilities Instance of {@link Utilities}. * @param injectedConfigUtilities Instance of {@link ConfigUtilities}. + * @throws IOException if the {@link VersionMeta} could not be instantiated. */ @Autowired public ConfigurationHandler(LocalizationManager injectedLocalizationManager, CurseCreateModpack injectedCurseCreateModpack, - VersionLister injectedVersionLister, ApplicationProperties injectedApplicationProperties, - BooleanUtilities injectedBooleanUtilities, ListUtilities injectedListUtilities, - StringUtilities injectedStringUtilities, SystemUtilities injectedSystemUtilities, - ConfigUtilities injectedConfigUtilities) { + VersionMeta injectedVersionMeta, ApplicationProperties injectedApplicationProperties, + Utilities injectedUtilities, ConfigUtilities injectedConfigUtilities) throws IOException { if (injectedApplicationProperties == null) { this.APPLICATIONPROPERTIES = new ApplicationProperties(); @@ -100,49 +95,26 @@ public class ConfigurationHandler { this.LOCALIZATIONMANAGER = injectedLocalizationManager; } - if (injectedVersionLister == null) { - this.VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); + if (injectedVersionMeta == null) { + this.VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); } else { - this.VERSIONLISTER = injectedVersionLister; + this.VERSIONMETA = injectedVersionMeta; } - - if (injectedBooleanUtilities == null) { - this.BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - } else { - this.BOOLEANUTILITIES = injectedBooleanUtilities; - } - - if (injectedListUtilities == null) { - this.LISTUTILITIES = new ListUtilities(); - } else { - this.LISTUTILITIES = injectedListUtilities; - } - - if (injectedStringUtilities == null) { - this.STRINGUTILITIES = new StringUtilities(); - } else { - this.STRINGUTILITIES = injectedStringUtilities; - } - - if (injectedSystemUtilities == null) { - this.SYSTEMUTILITIES = new SystemUtilities(); + if (injectedUtilities == null) { + this.UTILITIES = new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); } else { - this.SYSTEMUTILITIES = injectedSystemUtilities; + this.UTILITIES = injectedUtilities; } if (injectedConfigUtilities == null) { - this.CONFIGUTILITIES = new ConfigUtilities( - LOCALIZATIONMANAGER, BOOLEANUTILITIES, LISTUTILITIES, APPLICATIONPROPERTIES, STRINGUTILITIES, VERSIONLISTER - ); + this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, UTILITIES, APPLICATIONPROPERTIES, VERSIONMETA); } else { this.CONFIGUTILITIES = injectedConfigUtilities; } if (injectedCurseCreateModpack == null) { - this.CURSECREATEMODPACK = new CurseCreateModpack( - LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES - ); + this.CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES, CONFIGUTILITIES); } else { this.CURSECREATEMODPACK = injectedCurseCreateModpack; } @@ -305,8 +277,6 @@ public class ConfigurationHandler { */ public boolean checkConfiguration(@NotNull File configFile, @NotNull ConfigurationModel configurationModel, @NotNull List<String> encounteredErrors, boolean downloadAndCreateModpack, boolean quietCheck) { - LOG.info(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.checkconfig.start")); - FileConfig config = null; try { @@ -336,14 +306,14 @@ public class ConfigurationHandler { configurationModel.setModLoaderVersion(config.getOrElse("modLoaderVersion","")); configurationModel.setJavaArgs(config.getOrElse("javaArgs","empty")); - configurationModel.setServerPackSuffix(STRINGUTILITIES.pathSecureText(config.getOrElse("serverPackSuffix",""))); + configurationModel.setServerPackSuffix(UTILITIES.StringUtils().pathSecureText(config.getOrElse("serverPackSuffix",""))); configurationModel.setServerIconPath(config.getOrElse("serverIconPath","").replace("\\", "/")); configurationModel.setServerPropertiesPath(config.getOrElse("serverPropertiesPath","").replace("\\", "/")); - configurationModel.setIncludeServerInstallation(BOOLEANUTILITIES.convertToBoolean(String.valueOf(config.getOrElse("includeServerInstallation","False")))); - configurationModel.setIncludeServerIcon(BOOLEANUTILITIES.convertToBoolean(String.valueOf(config.getOrElse("includeServerIcon", "False")))); - configurationModel.setIncludeServerProperties(BOOLEANUTILITIES.convertToBoolean(String.valueOf(config.getOrElse("includeServerProperties", "False")))); - configurationModel.setIncludeZipCreation(BOOLEANUTILITIES.convertToBoolean(String.valueOf(config.getOrElse("includeZipCreation","False")))); + configurationModel.setIncludeServerInstallation(UTILITIES.BooleanUtils().convertToBoolean(String.valueOf(config.getOrElse("includeServerInstallation","False")))); + configurationModel.setIncludeServerIcon(UTILITIES.BooleanUtils().convertToBoolean(String.valueOf(config.getOrElse("includeServerIcon", "False")))); + configurationModel.setIncludeServerProperties(UTILITIES.BooleanUtils().convertToBoolean(String.valueOf(config.getOrElse("includeServerProperties", "False")))); + configurationModel.setIncludeZipCreation(UTILITIES.BooleanUtils().convertToBoolean(String.valueOf(config.getOrElse("includeZipCreation","False")))); } else { @@ -470,7 +440,7 @@ public class ConfigurationHandler { if (checkModloader(configurationModel.getModLoader())) { - if (isMinecraftVersionCorrect(configurationModel.getMinecraftVersion())) { + if (VERSIONMETA.minecraft().checkMinecraftVersion(configurationModel.getMinecraftVersion())) { /* This log is meant to be read by the user, therefore we allow translation. */ LOG.debug(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.debug.isdir.minecraftversion")); @@ -513,7 +483,9 @@ public class ConfigurationHandler { } - if (quietCheck) CONFIGUTILITIES.printConfigurationModel(configurationModel); + if (quietCheck) { + CONFIGUTILITIES.printConfigurationModel(configurationModel); + } if (!configHasError) { @@ -616,7 +588,7 @@ public class ConfigurationHandler { } // Extract the archive to the modpack directory. - SYSTEMUTILITIES.unzipArchive(configurationModel.getModpackDir(), destination); + UTILITIES.FileUtils().unzipArchive(configurationModel.getModpackDir(), destination); // Expand the already set copyDirs with suggestions from extracted ZIP-archive. List<String> newCopyDirs = CONFIGUTILITIES.suggestCopyDirs(destination); @@ -1168,8 +1140,6 @@ public class ConfigurationHandler { LOG.debug("What? " + fileOrDirectory + " is neither a file nor directory."); } - APPLICATIONPROPERTIES.addToListOfDirectoriesToExclude(directory.substring(directory.lastIndexOf("!") + 1)); - // Check if the entry exists } else { @@ -1236,14 +1206,14 @@ public class ConfigurationHandler { } else { LOG.debug("Acquiring path to Java installation from system properties..."); - checkedJavaPath = SYSTEMUTILITIES.acquireJavaPathFromSystem(); + checkedJavaPath = UTILITIES.SystemUtils().acquireJavaPathFromSystem(); LOG.debug("Automatically acquired path to Java installation: " + checkedJavaPath); } } catch (NullPointerException ex) { - checkedJavaPath = SYSTEMUTILITIES.acquireJavaPathFromSystem(); + checkedJavaPath = UTILITIES.SystemUtils().acquireJavaPathFromSystem(); LOG.debug("Automatically acquired path to Java installation: " + checkedJavaPath); @@ -1275,12 +1245,7 @@ public class ConfigurationHandler { } /** - * Depending on whether Forge or Fabric was specified as the modloader, this will call the corresponding version check - * to verify that the user correctly set their modloader version.<br> - * If the user specified Forge as their modloader, {@link #isForgeVersionCorrect(String, String)} is called and the version - * the user specified is checked against Forge's version manifest..<br> - * If the user specified Fabric as their modloader, {@link #isFabricVersionCorrect(String)} is called and the version - * the user specified is checked against Fabric's version manifest. + * Check the given Minecraft and modloader versions for the specified modloader. * @author Griefed * @param modloader String. The passed modloader which determines whether the check for Forge or Fabric is called. * @param modloaderVersion String. The version of the modloader which is checked against the corresponding modloaders manifest. @@ -1289,11 +1254,11 @@ public class ConfigurationHandler { */ public boolean checkModloaderVersion(String modloader, String modloaderVersion, String minecraftVersion) { - if (modloader.equalsIgnoreCase("Forge") && isForgeVersionCorrect(modloaderVersion, minecraftVersion)) { + if (modloader.equalsIgnoreCase("Forge") && VERSIONMETA.forge().checkForgeAndMinecraftVersion(minecraftVersion,modloaderVersion)) { return true; - } else if (modloader.equalsIgnoreCase("Fabric") && isFabricVersionCorrect(modloaderVersion)) { + } else if (modloader.equalsIgnoreCase("Fabric") && VERSIONMETA.fabric().checkFabricVersion(modloaderVersion)) { return true; @@ -1302,94 +1267,8 @@ public class ConfigurationHandler { /* This log is meant to be read by the user, therefore we allow translation. */ LOG.error(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.error.checkmodloaderversion")); - - - return false; - - } - } - - /** - * Check whether the specified Minecraft version is correct by searching the version list of the Minecraft manifest - * for the specified version. - * @author Griefed - * @param minecraftVersion String. The version to check for in Minecraft's version manifest. - * @return Boolean. Returns true if the specified Minecraft version could be found in Mojang's manifest. - */ - public boolean isMinecraftVersionCorrect(String minecraftVersion) { - - if (!minecraftVersion.equals("")) { - - return VERSIONLISTER.getMinecraftReleaseVersions().contains(minecraftVersion); - - } else { - - /* This log is meant to be read by the user, therefore we allow translation. */ - LOG.error(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.error.isminecraftversioncorrect.empty")); - return false; - } - } - /** - * Check whether the specified Fabric version is correct by searching the version list of the Fabric manifest - * for the specified version. - * @author Griefed - * @param fabricVersion String. The version to check for in Fabric's version manifest. - * @return Boolean. Returns true if the specified fabric version could be found in Fabric's manifest. - */ - public boolean isFabricVersionCorrect(String fabricVersion) { - - if (!fabricVersion.equals("")) { - - return VERSIONLISTER.getFabricVersions().contains(fabricVersion); - - } else { - - /* This log is meant to be read by the user, therefore we allow translation. */ - LOG.error(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.error.isfabricversioncorrect.empty")); - - return false; - } - } - - /** - * Check whether the specified Forge version is correct by searching the version list of the Forge manifest - * for the specified version. - * @author Griefed - * @param forgeVersion String. The version to check for in Forge's version manifest. - * @param minecraftVersion String. The minecraft version to check the Forge version with. - * @return Boolean. Returns true if the specified Forge version could be found in Forge's manifest. - */ - public boolean isForgeVersionCorrect(String forgeVersion, String minecraftVersion) { - - if (!forgeVersion.equals("")) { - - try { - - for (String version : VERSIONLISTER.getForgeMeta().get(minecraftVersion)) { - - if (version.equals(forgeVersion)) { - - return true; - - } - - } - - } catch (NullPointerException ignored) { - - return false; - - } - - return false; - - } else { - - /* This log is meant to be read by the user, therefore we allow translation. */ - LOG.error(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.error.isforgeversioncorrect.empty")); - return false; } } } \ No newline at end of file diff --git a/backend/main/java/de/griefed/serverpackcreator/DefaultFiles.java b/backend/main/java/de/griefed/serverpackcreator/DefaultFiles.java index b2b6164bd5b1c487feb0c7dbd800c88094f6b11a..09fd62af8cfd3086b636fb93e51c0b0fa5ca4798 100644 --- a/backend/main/java/de/griefed/serverpackcreator/DefaultFiles.java +++ b/backend/main/java/de/griefed/serverpackcreator/DefaultFiles.java @@ -19,13 +19,21 @@ */ package de.griefed.serverpackcreator; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import de.griefed.serverpackcreator.i18n.LocalizationManager; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import java.io.*; import java.net.URL; import java.nio.channels.Channels; @@ -83,6 +91,8 @@ public class DefaultFiles { } else { this.LOCALIZATIONMANAGER = injectedLocalizationManager; } + + filesSetup(); } /** @@ -337,47 +347,172 @@ public class DefaultFiles { File fileName = new File(String.format("./work/%s", manifestToRefresh)); - if (fileName.delete()) { - LOG.debug(String.format("Deleted %s.", manifestToRefresh)); + if (fileName.exists()) { + + try (InputStream existing = new FileInputStream(fileName); InputStream newManifest = manifestUrl.openStream()) { + + int countOldFile = 0; + int countNewFile = 0; + + if (manifestToRefresh.toString().endsWith("json")) { + + if (manifestToRefresh.toString().contains("forge")) { + + for (JsonNode mcVer : getJson(existing)) { + countOldFile += mcVer.size(); + } + for (JsonNode mcVer : getJson(newManifest)) { + countNewFile += mcVer.size(); + } + + } else { + + countOldFile = getJson(existing).get("versions").size(); + countNewFile = getJson(newManifest).get("versions").size(); + } + + } else { + + countOldFile = getXml(existing).getElementsByTagName("version").getLength(); + countNewFile = getXml(newManifest).getElementsByTagName("version").getLength(); + } + + LOG.debug("Nodes/Versions/Size in/of old " + manifestToRefresh + ": " + countOldFile); + LOG.debug("Nodes/Versions/Size in/of new " + manifestToRefresh + ": " + countNewFile); + + if (countNewFile > countOldFile) { + + LOG.info("Refreshing " + manifestToRefresh + "."); + + refresh(manifestUrl, fileName); + + } else { + + LOG.info("Manifest " + manifestToRefresh + " does not need to be refreshed."); + + } + + } catch (IOException ex) { + + LOG.error("Couldn't refresh manifest " + manifestToRefresh, ex); + + } + + } else { + + refresh(manifestUrl, fileName); + } + + + } + + private void refresh(URL manifestUrl, File manifestToRefresh) { + FileUtils.deleteQuietly(manifestToRefresh); + + try { + FileUtils.createParentDirectories(manifestToRefresh); + } catch (IOException ignored) { + } + ReadableByteChannel readableByteChannel = null; + FileOutputStream fileOutputStream = null; + FileChannel fileChannel = null; + try { - ReadableByteChannel readableByteChannel = Channels.newChannel(manifestUrl.openStream()); - FileOutputStream downloadManifestOutputStream; + readableByteChannel = Channels.newChannel(manifestUrl.openStream()); + + fileOutputStream = new FileOutputStream(manifestToRefresh); + + fileChannel = fileOutputStream.getChannel(); + + fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE); + + } catch (IOException ex) { + + LOG.error("An error occurred downloading " + manifestToRefresh + ".", ex); + FileUtils.deleteQuietly(manifestToRefresh); + + } finally { try { - downloadManifestOutputStream = new FileOutputStream(fileName); - } catch (FileNotFoundException ex) { + //noinspection ConstantConditions + fileOutputStream.flush(); + } catch (Exception ignored) { - LOG.debug(String.format("Couldn't find %s.", fileName), ex); + } - if (!fileName.exists()) { - LOG.debug(String.format("Creating Manifest %s.", fileName)); + try { + fileOutputStream.close(); + } catch (Exception ignored) { - if (fileName.createNewFile()) { - /* This log is meant to be read by the user, therefore we allow translation. */ - LOG.info(String.format(LOCALIZATIONMANAGER.getLocalizedString("defaultfiles.log.debug.manifest.created"), fileName)); + } + + try { + //noinspection ConstantConditions + readableByteChannel.close(); + } catch (Exception ignored) { - } else { - LOG.error(String.format("Error: Could not create Manifest %s.", fileName)); - } - } - downloadManifestOutputStream = new FileOutputStream(fileName); } - FileChannel downloadManifestOutputStreamChannel = downloadManifestOutputStream.getChannel(); - downloadManifestOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE); - downloadManifestOutputStream.flush(); + try { + //noinspection ConstantConditions + fileChannel.close(); + } catch (Exception ignored) { - downloadManifestOutputStream.close(); - readableByteChannel.close(); - downloadManifestOutputStreamChannel.close(); + } - } catch (Exception ex) { + } + } - LOG.error(String.format("Error: Something went wrong during the download of the %s Manifest.", fileName), ex); + /** + * Reads the Fabric manifest-file into a {@link Document} and {@link Document#normalize()} it. + * @author Griefed + * @param manifest The xml-file to parse into a Document. + * @return Document. Returns the file parsed into a Document. + */ + private Document getXml(InputStream manifest) { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = null; + Document xml = null; + try { + documentBuilder = documentBuilderFactory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } + try { + assert documentBuilder != null; + xml = documentBuilder.parse(manifest); + } catch (SAXException | IOException e) { + e.printStackTrace(); } + assert xml != null; + xml.normalize(); + return xml; + } + + /** + * Acquire a {@link JsonNode} from the given json file. + * @author Griefed + * @param inputStream {@link InputStream}. The file to read. + * @return {@link JsonNode} containing the files json data. + * @throws IOException when the file could not be parsed/read into a {@link JsonNode}. + */ + private JsonNode getJson(InputStream inputStream) throws IOException { + return getObjectMapper().readTree(inputStream); + } + + /** + * Getter for the object-mapper used for working with JSON-data. + * @author Griefed + * @return ObjectMapper. Returns the object-mapper used for working with JSON-data. + */ + private ObjectMapper getObjectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + return objectMapper; } /** diff --git a/backend/main/java/de/griefed/serverpackcreator/Main.java b/backend/main/java/de/griefed/serverpackcreator/Main.java index 7a21fb71b997baff1339c920c97046a618e7a279..4c485921c75c92bd0e5e3a4f429e236ca55a384d 100644 --- a/backend/main/java/de/griefed/serverpackcreator/Main.java +++ b/backend/main/java/de/griefed/serverpackcreator/Main.java @@ -20,10 +20,13 @@ package de.griefed.serverpackcreator; import de.griefed.serverpackcreator.curseforge.CurseCreateModpack; +import de.griefed.serverpackcreator.plugins.ApplicationPlugins; import de.griefed.serverpackcreator.swing.SwingGuiInitializer; import de.griefed.serverpackcreator.i18n.LocalizationManager; import de.griefed.serverpackcreator.utilities.*; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; import de.griefed.serverpackcreator.utilities.misc.Generated; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -76,14 +79,36 @@ public class Main { * @author Griefed * @param args Commandline arguments with which ServerPackCreator is run. Determines which mode ServerPackCreator * will enter and which locale is used. + * @throws IOException if the {@link VersionMeta} could not be instantiated. */ - public static void main(String[] args) { + public static void main(String[] args) throws IOException { - JarUtilities jarUtilities = new JarUtilities(); + ApplicationProperties APPLICATIONPROPERTIES = new ApplicationProperties(); + + List<String> programArgs = Arrays.asList(args); + + LocalizationManager LOCALIZATIONMANAGER; + if (Arrays.asList(args).contains("-lang")) { + + // Init the LocalizationManager with the locale passed by the cli arguments. + LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES, programArgs.get(programArgs.indexOf("-lang") + 1)); + + } else { - HashMap<String, String> systemInformation = jarUtilities.systemInformation(jarUtilities.getApplicationHomeForClass(Main.class)); + // Check local serverpackcreator.properties file for locale setting. + LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); + + } + + DefaultFiles DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - jarUtilities.copyFileFromJar(log4j2xml); + VersionMeta VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); + + Utilities UTILITIES = new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + + HashMap<String, String> systemInformation = UTILITIES.JarUtils().systemInformation(UTILITIES.JarUtils().getApplicationHomeForClass(Main.class)); + + UTILITIES.JarUtils().copyFileFromJar(log4j2xml); try { properties.createNewFile(); } catch (IOException ex) { @@ -100,28 +125,13 @@ public class Main { langSource = "de/griefed/resources/lang"; } - jarUtilities.copyFolderFromJar(systemInformation.get("jarPath"),langSource, "lang", prefix, ".properties"); + UTILITIES.JarUtils().copyFolderFromJar(systemInformation.get("jarPath"),langSource, "lang", prefix, ".properties"); } catch (IOException ex) { LOG.error("Error copying \"/de/griefed/resources/lang\" from the JAR-file."); } - ApplicationProperties APPLICATIONPROPERTIES = new ApplicationProperties(); - List<String> programArgs = Arrays.asList(args); - - LocalizationManager LOCALIZATIONMANAGER; - if (Arrays.asList(args).contains("-lang")) { - - // Init the LocalizationManager with the locale passed by the cli arguments. - LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES, programArgs.get(programArgs.indexOf("-lang") + 1)); - - } else { - - // Check local serverpackcreator.properties file for locale setting. - LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); - - } //Print system information to console and logs. LOG.debug("Gathering system information to include in log to make debugging easier."); @@ -196,9 +206,6 @@ public class Main { System.exit(0); } - DefaultFiles DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - DEFAULTFILES.filesSetup(); - //noinspection unused FileWatcher FILEWATCHER = new FileWatcher(APPLICATIONPROPERTIES, DEFAULTFILES); @@ -209,52 +216,33 @@ public class Main { } else { - regular(APPLICATIONPROPERTIES, LOCALIZATIONMANAGER, args); + regular(APPLICATIONPROPERTIES, LOCALIZATIONMANAGER, VERSIONMETA, UTILITIES, args); } } - private static void regular(ApplicationProperties APPLICATIONPROPERTIES, LocalizationManager LOCALIZATIONMANAGER, String[] args) { - - ListUtilities LISTUTILITIES = new ListUtilities(); - StringUtilities STRINGUTILITIES = new StringUtilities(); - SystemUtilities SYSTEMUTILITIES = new SystemUtilities(); + private static void regular(ApplicationProperties APPLICATIONPROPERTIES, LocalizationManager LOCALIZATIONMANAGER, VersionMeta VERSIONMETA, Utilities UTILITIES, String[] args) throws IOException { UpdateChecker UPDATECHECKER = new UpdateChecker(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - VersionLister VERSIONLISTER = new VersionLister( - APPLICATIONPROPERTIES - ); - - BooleanUtilities BOOLEANUTILITIES = new BooleanUtilities( - LOCALIZATIONMANAGER, APPLICATIONPROPERTIES - ); - - ConfigUtilities CONFIGUTILITIES = new ConfigUtilities( - LOCALIZATIONMANAGER, BOOLEANUTILITIES, LISTUTILITIES, APPLICATIONPROPERTIES, STRINGUTILITIES, - VERSIONLISTER - ); + ConfigUtilities CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, UTILITIES, APPLICATIONPROPERTIES, VERSIONMETA); CurseCreateModpack CURSECREATEMODPACK = new CurseCreateModpack( - LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, - STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES + LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES, CONFIGUTILITIES ); ConfigurationHandler CONFIGURATIONHANDLER = new ConfigurationHandler( - LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONLISTER, APPLICATIONPROPERTIES, BOOLEANUTILITIES, - LISTUTILITIES, STRINGUTILITIES, SYSTEMUTILITIES, CONFIGUTILITIES + LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONMETA, APPLICATIONPROPERTIES, UTILITIES, CONFIGUTILITIES ); ConfigurationCreator CONFIGURATIONCREATOR = new ConfigurationCreator( - LOCALIZATIONMANAGER, CONFIGURATIONHANDLER, BOOLEANUTILITIES, APPLICATIONPROPERTIES, LISTUTILITIES, - STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES, CURSECREATEMODPACK, VERSIONLISTER + LOCALIZATIONMANAGER, CONFIGURATIONHANDLER, APPLICATIONPROPERTIES, UTILITIES, CURSECREATEMODPACK, VERSIONMETA, CONFIGUTILITIES ); ApplicationPlugins APPLICATIONPLUGINS = new ApplicationPlugins(); ServerPackHandler SERVERPACKHANDLER = new ServerPackHandler( - LOCALIZATIONMANAGER, CURSECREATEMODPACK, CONFIGURATIONHANDLER, APPLICATIONPROPERTIES, VERSIONLISTER, - BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, SYSTEMUTILITIES, CONFIGUTILITIES, APPLICATIONPLUGINS + LOCALIZATIONMANAGER, CURSECREATEMODPACK, APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES, APPLICATIONPLUGINS, CONFIGUTILITIES ); if (Arrays.asList(args).contains("-cgen")) { @@ -285,8 +273,7 @@ public class Main { SwingGuiInitializer swingGuiInitializer = new SwingGuiInitializer( LOCALIZATIONMANAGER, CONFIGURATIONHANDLER, CURSECREATEMODPACK, SERVERPACKHANDLER, APPLICATIONPROPERTIES, - VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES, - UPDATECHECKER, APPLICATIONPLUGINS + VERSIONMETA, UTILITIES, UPDATECHECKER, APPLICATIONPLUGINS, CONFIGUTILITIES ); swingGuiInitializer.mainGUI(); diff --git a/backend/main/java/de/griefed/serverpackcreator/ServerPackHandler.java b/backend/main/java/de/griefed/serverpackcreator/ServerPackHandler.java index e2708e09c1f1e4c8d5f33ee29e3fac04af0673b1..ba4cfbfcac3da290b354c55deddfef3e9747b153 100644 --- a/backend/main/java/de/griefed/serverpackcreator/ServerPackHandler.java +++ b/backend/main/java/de/griefed/serverpackcreator/ServerPackHandler.java @@ -25,11 +25,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.moandjiezana.toml.Toml; import de.griefed.serverpackcreator.curseforge.CurseCreateModpack; import de.griefed.serverpackcreator.i18n.LocalizationManager; -import de.griefed.serverpackcreator.plugins.serverpackhandler.PreGenExtension; -import de.griefed.serverpackcreator.plugins.serverpackhandler.PostGenExtension; -import de.griefed.serverpackcreator.plugins.serverpackhandler.PreZipExtension; +import de.griefed.serverpackcreator.plugins.ApplicationPlugins; import de.griefed.serverpackcreator.spring.serverpack.ServerPackModel; -import de.griefed.serverpackcreator.utilities.*; +import de.griefed.serverpackcreator.utilities.ConfigUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.model.ExcludeFileFilter; import net.lingala.zip4j.model.ZipParameters; @@ -45,7 +45,6 @@ import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import java.math.BigInteger; -import java.net.MalformedURLException; import java.net.URL; import java.nio.file.*; import java.util.*; @@ -53,7 +52,6 @@ import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.stream.Stream; -import java.util.zip.ZipEntry; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; @@ -73,15 +71,11 @@ public class ServerPackHandler { private final LocalizationManager LOCALIZATIONMANAGER; private final CurseCreateModpack CURSECREATEMODPACK; - private final ConfigurationHandler CONFIGURATIONHANDLER; - private final VersionLister VERSIONLISTER; + private final VersionMeta VERSIONMETA; private final ApplicationProperties APPLICATIONPROPERTIES; - private final BooleanUtilities BOOLEANUTILITIES; - private final ConfigUtilities CONFIGUTILITIES; - private final ListUtilities LISTUTILITIES; - private final StringUtilities STRINGUTILITIES; - private final SystemUtilities SYSTEMUTILITIES; + private final Utilities UTILITIES; private final ApplicationPlugins APPLICATIONPLUGINS; + private final ConfigUtilities CONFIGUTILITIES; /** * <strong>Constructor</strong><p> @@ -91,22 +85,17 @@ public class ServerPackHandler { * @author Griefed * @param injectedLocalizationManager Instance of {@link LocalizationManager} required for localized log messages. * @param injectedCurseCreateModpack Instance of {@link CurseCreateModpack} required for creating a modpack from CurseForge. - * @param injectedConfigurationHandler Instance of {@link ConfigurationHandler} required for accessing checks. * @param injectedApplicationProperties Instance of {@link Properties} required for various different things. - * @param injectedVersionLister Instance of {@link VersionLister} required for everything version related. - * @param injectedBooleanUtilities Instance of {@link BooleanUtilities}. - * @param injectedListUtilities Instance of {@link ListUtilities}. - * @param injectedStringUtilities Instance of {@link StringUtilities}. - * @param injectedSystemUtilities Instance of {@link SystemUtilities}. - * @param injectedConfigUtilities Instance of {@link ConfigUtilities}. + * @param injectedVersionMeta Instance of {@link VersionMeta} required for everything version related. + * @param injectedUtilities Instance of {@link Utilities}. * @param injectedPluginManager Instance of {@link ApplicationPlugins}. + * @param injectedConfigUtilities Instance of {@link ConfigUtilities} + * @throws IOException if the {@link VersionMeta} could not be instantiated. */ @Autowired public ServerPackHandler(LocalizationManager injectedLocalizationManager, CurseCreateModpack injectedCurseCreateModpack, - ConfigurationHandler injectedConfigurationHandler, ApplicationProperties injectedApplicationProperties, - VersionLister injectedVersionLister, BooleanUtilities injectedBooleanUtilities, ListUtilities injectedListUtilities, - StringUtilities injectedStringUtilities, SystemUtilities injectedSystemUtilities, ConfigUtilities injectedConfigUtilities, - ApplicationPlugins injectedPluginManager) { + ApplicationProperties injectedApplicationProperties, VersionMeta injectedVersionMeta, + Utilities injectedUtilities, ApplicationPlugins injectedPluginManager, ConfigUtilities injectedConfigUtilities) throws IOException { if (injectedApplicationProperties == null) { this.APPLICATIONPROPERTIES = new ApplicationProperties(); @@ -120,66 +109,35 @@ public class ServerPackHandler { this.LOCALIZATIONMANAGER = injectedLocalizationManager; } - if (injectedVersionLister == null) { - this.VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); - } else { - this.VERSIONLISTER = injectedVersionLister; - } - - if (injectedBooleanUtilities == null) { - this.BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + if (injectedVersionMeta == null) { + this.VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); } else { - this.BOOLEANUTILITIES = injectedBooleanUtilities; + this.VERSIONMETA = injectedVersionMeta; } - if (injectedListUtilities == null) { - this.LISTUTILITIES = new ListUtilities(); + if (injectedUtilities == null) { + this.UTILITIES = new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); } else { - this.LISTUTILITIES = injectedListUtilities; - } - - if (injectedStringUtilities == null) { - this.STRINGUTILITIES = new StringUtilities(); - } else { - this.STRINGUTILITIES = injectedStringUtilities; - } - - if (injectedSystemUtilities == null) { - this.SYSTEMUTILITIES = new SystemUtilities(); - } else { - this.SYSTEMUTILITIES = injectedSystemUtilities; + this.UTILITIES = injectedUtilities; } if (injectedConfigUtilities == null) { - this.CONFIGUTILITIES = new ConfigUtilities( - LOCALIZATIONMANAGER, BOOLEANUTILITIES, LISTUTILITIES, APPLICATIONPROPERTIES, STRINGUTILITIES, VERSIONLISTER - ); + this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, UTILITIES, APPLICATIONPROPERTIES, VERSIONMETA); } else { this.CONFIGUTILITIES = injectedConfigUtilities; } if (injectedCurseCreateModpack == null) { - this.CURSECREATEMODPACK = new CurseCreateModpack( - LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES - ); + this.CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES, CONFIGUTILITIES); } else { this.CURSECREATEMODPACK = injectedCurseCreateModpack; } - if (injectedConfigurationHandler == null) { - this.CONFIGURATIONHANDLER = new ConfigurationHandler( - LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONLISTER, APPLICATIONPROPERTIES, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, SYSTEMUTILITIES, CONFIGUTILITIES - ); - } else { - this.CONFIGURATIONHANDLER = injectedConfigurationHandler; - } - if (injectedPluginManager == null) { this.APPLICATIONPLUGINS = new ApplicationPlugins(); } else { this.APPLICATIONPLUGINS = injectedPluginManager; } - } /** @@ -244,7 +202,6 @@ public class ServerPackHandler { new File(destination).exists()) { LOG.info(LOCALIZATIONMANAGER.getLocalizedString("createserverpack.log.info.overwrite")); - return true; } else { @@ -256,17 +213,17 @@ public class ServerPackHandler { } - if (APPLICATIONPLUGINS.PLUGINS_SERVERPACKSTART.size() > 0) { + if (!APPLICATIONPLUGINS.pluginsPreGenExtension().isEmpty()) { LOG_ADDONS.info("Executing PreGenExtension addons"); - for (PreGenExtension start : APPLICATIONPLUGINS.PLUGINS_SERVERPACKSTART) { - LOG_ADDONS.info("Executing plugin " + start.getName()); + APPLICATIONPLUGINS.pluginsPreGenExtension().forEach(plugin -> { + LOG_ADDONS.info("Executing plugin " + plugin.getName()); try { - start.run(APPLICATIONPROPERTIES, configurationModel, destination); + plugin.run(APPLICATIONPROPERTIES, configurationModel, destination); } catch (Exception ex) { - LOG_ADDONS.error(start.getName() + " encountered an error.", ex); + LOG_ADDONS.error(plugin.getName() + " encountered an error.", ex); } - } + }); } else { LOG.info("No PreGenExtension addons to execute."); } @@ -306,17 +263,17 @@ public class ServerPackHandler { LOG.info(LOCALIZATIONMANAGER.getLocalizedString("main.log.info.runincli.properties")); } - if (APPLICATIONPLUGINS.PLUGINS_SERVERPACKCREATED.size() > 0) { + if (!APPLICATIONPLUGINS.pluginsPreZipExtension().isEmpty()) { LOG_ADDONS.info("Executing PreZipExtension addons"); - for (PreZipExtension created : APPLICATIONPLUGINS.PLUGINS_SERVERPACKCREATED) { - LOG_ADDONS.info("Executing plugin " + created.getName()); + APPLICATIONPLUGINS.pluginsPreZipExtension().forEach(plugin -> { + LOG_ADDONS.info("Executing plugin " + plugin.getName()); try { - created.run(APPLICATIONPROPERTIES, configurationModel, destination); + plugin.run(APPLICATIONPROPERTIES, configurationModel, destination); } catch (Exception ex) { - LOG_ADDONS.error(created.getName() + " encountered an error.", ex); + LOG_ADDONS.error(plugin.getName() + " encountered an error.", ex); } - } + }); } else { LOG.info("No PreZipExtension addons to execute."); } @@ -336,23 +293,23 @@ public class ServerPackHandler { LOG.info(String.format(LOCALIZATIONMANAGER.getLocalizedString("main.log.info.runincli.archive"), destination)); LOG.info(LOCALIZATIONMANAGER.getLocalizedString("main.log.info.runincli.finish")); - if (APPLICATIONPLUGINS.PLUGINS_SERVERPACKARCHIVECREATED.size() > 0) { + if (!APPLICATIONPLUGINS.pluginsPostGenExtension().isEmpty()) { LOG_ADDONS.info("Executing PostGenExtension addons"); - for (PostGenExtension archive : APPLICATIONPLUGINS.PLUGINS_SERVERPACKARCHIVECREATED) { - LOG_ADDONS.info("Executing plugin " + archive.getName()); + APPLICATIONPLUGINS.pluginsPostGenExtension().forEach(plugin -> { + LOG_ADDONS.info("Executing plugin " + plugin.getName()); try { - archive.run(APPLICATIONPROPERTIES, configurationModel, destination); + plugin.run(APPLICATIONPROPERTIES, configurationModel, destination); } catch (Exception ex) { - LOG_ADDONS.error(archive.getName() + " encountered an error.", ex); + LOG_ADDONS.error(plugin.getName() + " encountered an error.", ex); } - } + }); } else { LOG.info("No PostGenExtension addons to execute."); } - return true; } + return true; } @@ -360,21 +317,15 @@ public class ServerPackHandler { * Download and provide the improved Fabric Server Launcher, if it is available for the given Minecraft and Fabric version. * @author Griefed * @param minecraftVersion String. The Minecraft version the modpack uses and the Fabric Server Launcher should be downloaded for. - * @param modLoaderVersion String. The modloader version the modpack uses and the Fabric Server Launcher should be downloaded for. + * @param fabricVersion String. The modloader version the modpack uses and the Fabric Server Launcher should be downloaded for. * @param destination String. The destination of the server pack. */ - private void provideImprovedFabricServerLauncher(String minecraftVersion, String modLoaderVersion, String destination) { + private void provideImprovedFabricServerLauncher(String minecraftVersion, String fabricVersion, String destination) { URL downloadUrl; String fileDestination = String.format("%s/fabric-server-launcher.jar", destination); - try { - downloadUrl = new URL(String.format("https://meta.fabricmc.net/v2/versions/loader/%s/%s/%s/server/jar", minecraftVersion, modLoaderVersion, VERSIONLISTER.getFabricReleaseInstallerVersion())); - } catch (Exception ex) { - LOG.error("Couldn't create Fabric Server Launcher URL.",ex); - downloadUrl = null; - } - - if (downloadUrl != null && SYSTEMUTILITIES.downloadFile(fileDestination, downloadUrl)) { + if (VERSIONMETA.fabric().improvedLauncherUrl(minecraftVersion, fabricVersion).isPresent() && + UTILITIES.WebUtils().downloadFile(fileDestination, VERSIONMETA.fabric().improvedLauncherUrl(minecraftVersion, fabricVersion).get())) { LOG.info(LOCALIZATIONMANAGER.getLocalizedString("createserverpack.log.info.fabric.improved")); @@ -506,7 +457,7 @@ public class ServerPackHandler { writer.write("JAVA=\"java\"\n"); writer.write("MINECRAFT=\"" + minecraftVersion + "\"\n"); writer.write("FABRIC=\"" + modloaderVersion + "\"\n"); - writer.write("INSTALLER=\"" + VERSIONLISTER.getFabricReleaseInstallerVersion() + "\"\n"); + writer.write("INSTALLER=\"" + VERSIONMETA.fabric().releaseInstallerVersion() + "\"\n"); writer.write("ARGS=\"" + javaArguments + "\"\n"); writer.write("OTHERARGS=\"-Dlog4j2.formatMsgNoLookups=true\"\n"); writer.write("\n"); @@ -536,7 +487,7 @@ public class ServerPackHandler { writer.write("\n"); writer.write("if [[ ! -s \"server.jar\" ]];then\n"); writer.write(" echo \"Minecraft Server JAR-file not found. Downloading...\";\n"); - writer.write(" wget -O server.jar " + getMinecraftServerJarUrl(minecraftVersion) + ";\n"); + writer.write(" wget -O server.jar " + VERSIONMETA.minecraft().getServer(minecraftVersion).get().url() + ";\n"); writer.write("else\n"); writer.write(" echo \"server.jar present. Moving on...\";\n"); writer.write("fi\n"); @@ -602,7 +553,7 @@ public class ServerPackHandler { writer.write("SET JAVA=\"java\"\n"); writer.write("SET MINECRAFT=\"" + minecraftVersion + "\"\n"); writer.write("SET FABRIC=\"" + modloaderVersion + "\"\n"); - writer.write("SET INSTALLER=\"" + VERSIONLISTER.getFabricReleaseInstallerVersion() + "\"\n"); + writer.write("SET INSTALLER=\"" + VERSIONMETA.fabric().releaseInstallerVersion() + "\"\n"); writer.write("SET ARGS=" + javaArguments + "\n"); writer.write("SET OTHERARGS=\"-Dlog4j2.formatMsgNoLookups=true\"\n"); writer.write("\n"); @@ -634,7 +585,7 @@ public class ServerPackHandler { writer.write("\n"); writer.write("IF NOT EXIST server.jar (\n"); writer.write(" ECHO Minecraft Server JAR-file not found. Downloading...\n"); - writer.write(" powershell -Command \"(New-Object Net.WebClient).DownloadFile('" + getMinecraftServerJarUrl(minecraftVersion) + "', 'server.jar')\"\n"); + writer.write(" powershell -Command \"(New-Object Net.WebClient).DownloadFile('" + VERSIONMETA.minecraft().getServer(minecraftVersion).get().url() + "', 'server.jar')\"\n"); writer.write(") ELSE (\n"); writer.write(" ECHO server.jar present. Moving on...\n"); writer.write(")\n"); @@ -768,7 +719,7 @@ public class ServerPackHandler { writer.write("\n"); writer.write("if [[ ! -s \"libraries/net/minecraft/server/$MINECRAFT/server-$MINECRAFT.jar\" ]];then\n"); writer.write(" echo \"Minecraft Server JAR-file not found. Downloading...\";\n"); - writer.write(" wget -O libraries/net/minecraft/server/$MINECRAFT/server-$MINECRAFT.jar " + getMinecraftServerJarUrl(minecraftVersion) + ";\n"); + writer.write(" wget -O libraries/net/minecraft/server/$MINECRAFT/server-$MINECRAFT.jar " + VERSIONMETA.minecraft().getServer(minecraftVersion).get().url() + ";\n"); writer.write("else\n"); writer.write(" echo \"Minecraft server present. Moving on...\"\n"); writer.write("fi\n"); @@ -884,7 +835,7 @@ public class ServerPackHandler { writer.write("\n"); writer.write("IF NOT EXIST libraries/net/minecraft/server/%MINECRAFT%/server-%MINECRAFT%.jar (\n"); writer.write(" ECHO Minecraft Server JAR-file not found. Downloading...\n"); - writer.write(" powershell -Command \"(New-Object Net.WebClient).DownloadFile('" + getMinecraftServerJarUrl(minecraftVersion) + "', 'libraries/net/minecraft/server/%MINECRAFT%/server-%MINECRAFT%.jar')\"\n"); + writer.write(" powershell -Command \"(New-Object Net.WebClient).DownloadFile('" + VERSIONMETA.minecraft().getServer(minecraftVersion).get().url() + "', 'libraries/net/minecraft/server/%MINECRAFT%/server-%MINECRAFT%.jar')\"\n"); writer.write(") ELSE (\n"); writer.write(" ECHO Minecraft server present. Moving on...\n"); writer.write(")\n"); @@ -1001,7 +952,7 @@ public class ServerPackHandler { writer.write("\n"); writer.write("if [[ ! -s \"minecraft_server.$MINECRAFT.jar\" ]];then\n"); writer.write(" echo \"Minecraft Server JAR-file not found. Downloading...\";\n"); - writer.write(" wget -O minecraft_server.$MINECRAFT.jar " + getMinecraftServerJarUrl(minecraftVersion) + ";\n"); + writer.write(" wget -O minecraft_server.$MINECRAFT.jar " + VERSIONMETA.minecraft().getServer(minecraftVersion).get().url() + ";\n"); writer.write("else\n"); writer.write(" echo \"minecraft_server.$MINECRAFT.jar present. Moving on...\"\n"); writer.write("fi\n"); @@ -1104,7 +1055,7 @@ public class ServerPackHandler { writer.write("\n"); writer.write("IF NOT EXIST minecraft_server.%MINECRAFT%.jar (\n"); writer.write(" ECHO Minecraft Server JAR-file not found. Downloading...\n"); - writer.write(" powershell -Command \"(New-Object Net.WebClient).DownloadFile('" + getMinecraftServerJarUrl(minecraftVersion) + "', 'minecraft_server.%MINECRAFT%.jar')\"\n"); + writer.write(" powershell -Command \"(New-Object Net.WebClient).DownloadFile('" + VERSIONMETA.minecraft().getServer(minecraftVersion).get().url() + "', 'minecraft_server.%MINECRAFT%.jar')\"\n"); writer.write(") ELSE (\n"); writer.write(" ECHO minecraft_server.%MINECRAFT%.jar present. Moving on...\n"); writer.write(")\n"); @@ -1167,9 +1118,6 @@ public class ServerPackHandler { LOG.error(String.format("Failed to create directory %s", destination)); } - // Note to self: What is this? How does this exclude files? What did I do here? - directoriesToCopy.removeIf(n -> n.startsWith("!")); - if (directoriesToCopy.size() == 1 && directoriesToCopy.get(0).equals("lazy_mode")) { LOG.warn(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.warn.checkconfig.copydirs.lazymode0")); @@ -1190,6 +1138,15 @@ public class ServerPackHandler { } } else { + + List<String> exclusions = APPLICATIONPROPERTIES.getListOfDirectoriesToExclude(); + directoriesToCopy.forEach(entry -> { + if (entry.startsWith("!")) { + exclusions.add(entry.substring(1)); + } + }); + directoriesToCopy.removeIf(n -> n.startsWith("!")); + for (String directory : directoriesToCopy) { String clientDir = String.format("%s/%s", modpackDir, directory); @@ -1275,7 +1232,7 @@ public class ServerPackHandler { * If the entry starts with mods, we need to run our checks for clientside-only mods as well as exclude any * user-specified clientside-only mods from the list of mods in the mods-directory. */ - } else if (directory.startsWith("mods") && clientMods.size() > 0) { + } else if (directory.startsWith("mods")) { List<String> listOfFiles = excludeClientMods(clientDir, clientMods, minecraftVersion); @@ -1286,21 +1243,31 @@ public class ServerPackHandler { } for (String file : listOfFiles) { - try { - Files.copy( - Paths.get(file), - Paths.get(String.format("%s/%s", serverDir, new File(file).getName())), - REPLACE_EXISTING - ); + if (excludeFileOrDirectory(file.replace("\\","/"), exclusions)) { - LOG.debug(String.format("Copying: %s", file)); + LOG.info("Excluding " + file + " from server pack"); - } catch (IOException ex) { - if (!ex.toString().startsWith("java.nio.file.DirectoryNotEmptyException")) { - LOG.error("An error occurred copying files to the serverpack.", ex); + } else { + + try { + + Files.copy( + Paths.get(file), + Paths.get(String.format("%s/%s", serverDir, new File(file).getName())), + REPLACE_EXISTING + ); + + LOG.debug(String.format("Copying: %s", file)); + + } catch (IOException ex) { + if (!ex.toString().startsWith("java.nio.file.DirectoryNotEmptyException")) { + LOG.error("An error occurred copying files to the serverpack.", ex); + } } + } + } } else if (new File(directory).isFile() && !new File(directory).isDirectory()) { @@ -1319,9 +1286,9 @@ public class ServerPackHandler { try (Stream<Path> files = Files.walk(Paths.get(clientDir))) { files.forEach(file -> { - if (excludeFileOrDirectory(file.toString().replace("\\","/"))) { + if (excludeFileOrDirectory(file.toString().replace("\\","/"), exclusions)) { - LOG.debug("Excluding " + file + " from server pack"); + LOG.info("Excluding " + file + " from server pack"); } else { try { @@ -1399,7 +1366,7 @@ public class ServerPackHandler { // Exclude user-specified mods from copying. - if (!userSpecifiedClientMods.get(0).equals("")) { + if (userSpecifiedClientMods.size() > 0) { for (int m = 0; m < userSpecifiedClientMods.size(); m++) { int i = m; @@ -1432,9 +1399,9 @@ public class ServerPackHandler { * @param fileToCheckFor String. The string to check for. * @return Boolean. Returns true if the file is found in the list of directories to exclude, false if not. */ - private boolean excludeFileOrDirectory(String fileToCheckFor) { + private boolean excludeFileOrDirectory(String fileToCheckFor, List<String> exclusions) { boolean isPresentInList = false; - for (String entry : APPLICATIONPROPERTIES.getListOfDirectoriesToExclude()) { + for (String entry : exclusions) { if (fileToCheckFor.contains(entry)) { isPresentInList = true; break; @@ -1454,7 +1421,7 @@ public class ServerPackHandler { /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(LOCALIZATIONMANAGER.getLocalizedString("createserverpack.log.info.copyicon")); - File defaultIcon = new File(String.format("%s/%s", destination, APPLICATIONPROPERTIES.FILE_SERVER_ICON)); + File iconFile = new File(String.format("%s/%s", destination, APPLICATIONPROPERTIES.FILE_SERVER_ICON)); if (new File(pathToServerIcon).exists()) { @@ -1469,12 +1436,16 @@ public class ServerPackHandler { } if (originalImage != null) { + + // Scale our image to 64x64 scaledImage = originalImage.getScaledInstance(64, 64, Image.SCALE_SMOOTH); BufferedImage outputImage = new BufferedImage(scaledImage.getWidth(null), scaledImage.getHeight(null), BufferedImage.TYPE_INT_ARGB); outputImage.getGraphics().drawImage(scaledImage, 0, 0, null); + + // Save our scaled image to disk. try { - ImageIO.write(outputImage, "png", defaultIcon); + ImageIO.write(outputImage, "png", iconFile); } catch (IOException ex) { LOG.error("Error scaling image.", ex); LOG.error("Using default icon as fallback."); @@ -1483,7 +1454,7 @@ public class ServerPackHandler { FileUtils.copyFile( new File(String.format("server_files/%s", APPLICATIONPROPERTIES.FILE_SERVER_ICON)), - defaultIcon + iconFile ); } catch (IOException e) { @@ -1502,7 +1473,7 @@ public class ServerPackHandler { FileUtils.copyFile( new File(String.format("server_files/%s", APPLICATIONPROPERTIES.FILE_SERVER_ICON)), - defaultIcon + iconFile ); } catch (IOException ex) { @@ -1560,7 +1531,7 @@ public class ServerPackHandler { * @param modLoader String. The modloader for which to install the server software. Either Forge or Fabric. * @param minecraftVersion String. The Minecraft version for which to install the modloader and Minecraft server. * @param modLoaderVersion String. The modloader version for which to install the modloader and Minecraft server. - * @param javaPath String. The path to the Java executable/binary which is needed to execute the Forge/Fabric installers. + * @param javaPath String. The path to the Java executable/binary which is needed to execute the Forge/Fabric installersList. * @param destination String. The destination where the modloader server should be installed into. */ private void installServer(String modLoader, String minecraftVersion, String modLoaderVersion, String javaPath, String destination) { @@ -1569,7 +1540,6 @@ public class ServerPackHandler { Process process = null; BufferedReader bufferedReader = null; - URL downloadUrl = null; String fileDestination; if (modLoader.equalsIgnoreCase("Fabric")) { @@ -1577,15 +1547,9 @@ public class ServerPackHandler { /* This log is meant to be read by the user, therefore we allow translation. */ LOG_INSTALLER.info(LOCALIZATIONMANAGER.getLocalizedString("createserverpack.log.info.installserver.fabric.enter")); - try { - downloadUrl = new URL(String.format("https://maven.fabricmc.net/net/fabricmc/fabric-installer/%s/fabric-installer-%s.jar", VERSIONLISTER.getFabricReleaseInstallerVersion(), VERSIONLISTER.getFabricReleaseInstallerVersion())); - } catch (MalformedURLException ex) { - LOG.error("Couldn't create Fabric URL.", ex); - } - fileDestination = String.format("%s/fabric-installer.jar", destination); - if (downloadUrl!= null && SYSTEMUTILITIES.downloadFile(fileDestination, downloadUrl)) { + if (UTILITIES.WebUtils().downloadFile(fileDestination, VERSIONMETA.fabric().releaseInstallerUrl())) { /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(LOCALIZATIONMANAGER.getLocalizedString("createserverpack.log.info.installserver.fabric.download")); @@ -1609,15 +1573,11 @@ public class ServerPackHandler { /* This log is meant to be read by the user, therefore we allow translation. */ LOG_INSTALLER.info(LOCALIZATIONMANAGER.getLocalizedString("createserverpack.log.info.installserver.forge.enter")); - try { - downloadUrl = new URL(String.format("https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s-%s/forge-%s-%s-installer.jar", minecraftVersion, modLoaderVersion, minecraftVersion, modLoaderVersion)); - } catch (MalformedURLException ex) { - LOG.error("Couldn't create Forge URL.",ex); - } - fileDestination = String.format("%s/forge-installer.jar", destination); - if (downloadUrl != null && SYSTEMUTILITIES.downloadFile(fileDestination, downloadUrl)) { + if (VERSIONMETA.forge().getForgeInstance(minecraftVersion, modLoaderVersion).isPresent() && + UTILITIES.WebUtils().downloadFile(fileDestination, VERSIONMETA.forge().getForgeInstance(minecraftVersion, modLoaderVersion).get().installerUrl())) { + /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(LOCALIZATIONMANAGER.getLocalizedString("createserverpack.log.info.installserver.forge.download")); commandArguments.add(javaPath); @@ -1745,43 +1705,6 @@ public class ServerPackHandler { LOG.info(LOCALIZATIONMANAGER.getLocalizedString("createserverpack.log.info.zipbuilder.finish")); } - /** - * Retrieves the URL to the Minecraft server for the specified Minecraft version. - * @author Griefed - * @param minecraftVersion String. The Minecraft version for which to retrieve the URL for the server-jar. - * @return String. The URL to the server-jar of the specified Minecraft version as a string. - */ - private String getMinecraftServerJarUrl(String minecraftVersion) { - String minecraftVersionJarUrl = null; - - try { - JsonNode minecraftJson = getObjectMapper().readTree(Files.readAllBytes(new File("./work/minecraft-manifest.json").toPath())); - - JsonNode versions = minecraftJson.get("versions"); - - for (JsonNode version : versions) { - try { - if (version.get("id").asText().equals(minecraftVersion)) { - - try (InputStream inputStream = new URL(version.get("url").asText()).openStream()) { - JsonNode serverNode = getObjectMapper().readTree(inputStream); - - minecraftVersionJarUrl = serverNode.get("downloads").get("server").get("url").asText(); - } - - } - } catch (NullPointerException ignored) { - - } - } - - } catch (IOException ex) { - LOG.error("Couldn't read Minecraft manifest.", ex); - } - - return minecraftVersionJarUrl; - } - /** * Cleans up the server_pack directory by deleting left-over files from modloader installations and version checking. * @author Griefed diff --git a/backend/main/java/de/griefed/serverpackcreator/VersionLister.java b/backend/main/java/de/griefed/serverpackcreator/VersionLister.java deleted file mode 100644 index 97c7ee58fbf24a0f4762fab2339ca8f36c8b157c..0000000000000000000000000000000000000000 --- a/backend/main/java/de/griefed/serverpackcreator/VersionLister.java +++ /dev/null @@ -1,473 +0,0 @@ -/* Copyright (C) 2022 Griefed - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - * - * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE - */ -package de.griefed.serverpackcreator; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.Lists; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.*; - -/** - * Create lists of versions for Minecraft, Fabric and Forge. Provides getters for retrieving Minecraft and Fabric version - * lists and {@link #getForgeVersionsList(String)} to retrieve a list of available Forge versions for a given Minecraft - * version. Instantiating this class automatically creates the Minecraft and Fabric lists, for immediate access through - * {@link #getMinecraftReleaseVersions()} and {@link #getFabricVersions()} respectively. Also provides getters for retrieving - * the <code>latest</code> or <code>release</code> versions of Fabric. - * @author Griefed - */ -@Component -public class VersionLister { - - private static final Logger LOG = LogManager.getLogger(VersionLister.class); - - private final ApplicationProperties APPLICATIONPROPERTIES; - - private String minecraftReleaseVersion; - private List<String> minecraftReleaseVersions; - - private String minecraftSnapshotVersion; - private List<String> minecraftSnapshotVersions; - - private List<String> fabricVersions; - private String fabricLatestVersion; - private String fabricReleaseVersion; - - private String fabricLatestInstallerVersion; - private String fabricReleaseInstallerVersion; - - private HashMap<String, String[]> forgeMeta; - - /** - * Creates the Minecraft and Fabric version lists as well as Fabric-Latest and Fabric-Release versions. - * @author Griefed - * @param injectedApplicationProperties Instance of {@link Properties} required for various different things. - */ - @Autowired - public VersionLister(ApplicationProperties injectedApplicationProperties) { - if (injectedApplicationProperties == null) { - this.APPLICATIONPROPERTIES = new ApplicationProperties(); - } else { - this.APPLICATIONPROPERTIES = injectedApplicationProperties; - } - - this.minecraftReleaseVersion = setMinecraftSpecificVersion("release"); - this.minecraftReleaseVersions = getMinecraftVersionsList("release"); - - this.minecraftSnapshotVersion = setMinecraftSpecificVersion("snapshot"); - this.minecraftSnapshotVersions = getMinecraftVersionsList("snapshot"); - - this.fabricVersions = setFabricVersionList(); - this.fabricLatestVersion = setFabricSpecificVersion("latest", getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC)); - this.fabricReleaseVersion = setFabricSpecificVersion("release", getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC)); - - this.fabricLatestInstallerVersion = setFabricSpecificVersion("latest", getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC_INSTALLER)); - this.fabricReleaseInstallerVersion = setFabricSpecificVersion("release", getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC_INSTALLER)); - - this.forgeMeta = setForgeMeta(); - } - - /** - * Refresh all Minecraft, Forge and Fabric versions, so we can work with up-to-date values. - * @author Griefed - */ - public void refreshVersions() { - this.minecraftReleaseVersion = setMinecraftSpecificVersion("release"); - this.minecraftReleaseVersions = getMinecraftVersionsList("release"); - - this.minecraftSnapshotVersion = setMinecraftSpecificVersion("snapshot"); - this.minecraftSnapshotVersions = getMinecraftVersionsList("snapshot"); - - this.fabricVersions = setFabricVersionList(); - this.fabricLatestVersion = setFabricSpecificVersion("latest", getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC)); - this.fabricReleaseVersion = setFabricSpecificVersion("release", getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC)); - - this.fabricLatestInstallerVersion = setFabricSpecificVersion("latest", getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC_INSTALLER)); - this.fabricReleaseInstallerVersion = setFabricSpecificVersion("release", getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC_INSTALLER)); - - this.forgeMeta = setForgeMeta(); - } - - /** - * Getter for the latest release version of Minecraft. - * @author Griefed - * @return String. Returns the latest release version of Minecraft. - */ - public String getMinecraftReleaseVersion() { - return minecraftReleaseVersion; - } - - /** - * Getter for the list of available Minecraft versions of type <code>release</code> - * @author Griefed - * @return List String. Returns the list of available Minecraft versions. - */ - public List<String> getMinecraftReleaseVersions() { - return minecraftReleaseVersions; - } - - /** - * Getter for the latest Snapshot version of Minecraft. - * @author Griefed - * @return String. Returns the latest snapshot version of Minecraft. - */ - public String getMinecraftSnapshotVersion() { - return minecraftSnapshotVersion; - } - - /** - * Getter for the list of all available Snapshot version for Minecraft. - * @author Griefed - * @return List String. Returns a list of all available Snapshot versions for Minecraft. - */ - public List<String> getMinecraftSnapshotVersions() { - return minecraftSnapshotVersions; - } - - /** - * Getter for the list of available Fabric versions. - * @author Griefed - * @return List String. Returns the list of available Fabric versions. - */ - public List<String> getFabricVersions() { - return fabricVersions; - } - - /** - * Getter for the latest Fabric version. - * @author Griefed - * @return String. Returns the latest Fabric version. - */ - public String getFabricLatestVersion() { - return fabricLatestVersion; - } - - /** - * Getter for the latest release version of Fabric. - * @author Griefed - * @return String. Returns the latest release version of Fabric. - */ - public String getFabricReleaseVersion() { - return fabricReleaseVersion; - } - - /** - * Getter for the Forge version meta in convenient HashMap format. Keys are Minecraft versions, values are String arrays - * containing all available Forge versions, or <code>None</code> if Forge is not available for a given Minecraft version. - * @author Griefed - * @return HashMap String, String Array. Returns the HashMap with all Minecraft versions as keys and the Forge versions - * as values, in arrays. - */ - public HashMap<String, String[]> getForgeMeta() { - return forgeMeta; - } - - /** - * Create a HashMap of all Minecraft versions and their available Forge versions. - * @author Griefed - * @return HashMap String, String Array. Returns the HashMap with all Minecraft versions as keys and the Forge versions - * as values, in arrays. - */ - private HashMap<String, String[]> setForgeMeta() { - HashMap<String, String[]> hashMap = new HashMap<>(); - - for (String version : minecraftReleaseVersions) { - hashMap.put(version, reverseOrderArray(getForgeVersionsAsArray(version))); - } - - return hashMap; - } - - /** - * Getter for the release version of the Fabric installer. - * @author Griefed - * @return String. Returns the latest installer version for Fabric. - */ - public String getFabricLatestInstallerVersion() { - return fabricLatestInstallerVersion; - } - - /** - * Getter for the release version of the Fabric installer. - * @author Griefed - * @return String. Returns the release installer version for Fabric. - */ - public String getFabricReleaseInstallerVersion() { - return fabricReleaseInstallerVersion; - } - - /** - * Reverses the order of a passed String List. - * @author Griefed - * @param listToReverse The String List to reverse. - * @return String List. The passed String List in reverse. - */ - public List<String> reverseOrderList(List<String> listToReverse) { - return Lists.reverse(listToReverse); - } - - /** - * Reverses the order of a passed String array. - * @author Griefed - * @param arrayToReverse The String array to reverseOrderArray-order. - * @return String Array. The passed String array in reverseOrderArray-order. - */ - public String[] reverseOrderArray(String[] arrayToReverse) { - int arrayLength = arrayToReverse.length; - String entry; - for (int i = 0; i < arrayLength / 2; i++) { - entry = arrayToReverse[i]; - arrayToReverse[i] = arrayToReverse[arrayLength - i - 1]; - arrayToReverse[arrayLength - i - 1] = entry; - } - return arrayToReverse; - } - - /** - * Getter for the list of Minecraft release versions as an array. - * @author Griefed - * @return String Array. Returns the list of Minecraft release versions as an array. - */ - public String[] getMinecraftReleaseVersionsAsArray() { - String[] array = new String[this.minecraftReleaseVersions.size()]; - array = this.minecraftReleaseVersions.toArray(array); - return array; - } - - /** - * Getter for the list of Fabric versions as an array. - * @author Griefed - * @return String Array. Returns the list of Fabric versions as an array. - */ - public String[] getFabricVersionsAsArray() { - String[] array = new String[this.fabricVersions.size()]; - array = this.fabricVersions.toArray(array); - return array; - } - - /** - * Getter for the list of Forge versions for the specified Minecraft version as an array. - * @author Griefed - * @param selectedMinecraftVersion The Minecraft version for which to check for Forge versions. - * @return String Array. Returns the list of Forge versions for the specified Minecraft versions as an array. - */ - public String[] getForgeVersionsAsArray(String selectedMinecraftVersion) { - String[] array = new String[getForgeVersionsList(selectedMinecraftVersion).size()]; - array = getForgeVersionsList(selectedMinecraftVersion).toArray(array); - return array; - } - - /** - * Getter for the list of FOrge versions for the specified Minecraft version as a String List. - * @author Griefed - * @param selectedMinecraftVersion String. The Minecraft version for which to check for Forge versions. - * @return String List. A list of all available Forge versions for the passed Minecraft version. - */ - public List<String> getForgeVersionsAsList(String selectedMinecraftVersion) { - List<String> versions = new ArrayList<>(1000); - versions.addAll(Arrays.asList(getForgeVersionsAsArray(selectedMinecraftVersion))); - return versions; - } - - /** - * Helper method for {@link #getMinecraftVersionsList(String)} and {@link #setMinecraftSpecificVersion(String)}. - * Reads the passed manifest-file into a byte array and returns a JsonNode containing said byte array. - * @author Griefed - * @param manifestFile The file to read into the byte array. - * @return JsonNode. Returns the JsonNode of the passed manifest-file. - * @throws IOException Throws an exception when the passed file could not be found/read/parsed etc. - */ - private JsonNode getJson(File manifestFile) throws IOException { - byte[] jsonData = Files.readAllBytes(manifestFile.toPath()); - return getObjectMapper().readTree(jsonData); - } - - /** - * Getter for the object-mapper used for working with JSON-data. - * @author Griefed - * @return ObjectMapper. Returns the object-mapper used for working with JSON-data. - */ - private ObjectMapper getObjectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); - return objectMapper; - } - - /** - * Helper method for {@link #setFabricVersionList()} and {@link #setFabricSpecificVersion(String, Document)}. Reads the Fabric - * manifest-file into a {@link Document} and {@link Document#normalize()} it. - * @author Griefed - * @param manifest The xml-file to parse into a Document. - * @return Document. Returns the file parsed into a Document. - */ - @NotNull - private Document getXml(File manifest) { - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder documentBuilder = null; - Document xml = null; - try { - documentBuilder = documentBuilderFactory.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } - try { - assert documentBuilder != null; - xml = documentBuilder.parse(manifest); - } catch (SAXException | IOException e) { - e.printStackTrace(); - } - assert xml != null; - xml.normalize(); - return xml; - } - - /** - * Parses the Minecraft manifest-file to retrieve a list of all available Minecraft versions for a specified release-type. - * @author Griefed - * @param type Release type which determines which version get added to the list returned. Can be <code>release, snapshot, old_beta, old_alpha</code> - * @return List String. Returns a list of all available Minecraft versions for the specified type. - */ - private List<String> getMinecraftVersionsList(String type) { - - List<String> minecraftReleases = new ArrayList<>(); - - try { - JsonNode minecraftJson = getJson(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_MINECRAFT); - - JsonNode versions = minecraftJson.get("versions"); - - for (JsonNode version : versions) { - try { - if (version.get("type").asText().equals(type)) { - minecraftReleases.add(version.get("id").asText()); - } - } catch (NullPointerException ignored) { - - } - } - - } catch (IOException ex) { - LOG.error("Couldn't read Minecraft manifest.", ex); - } - - return minecraftReleases; - } - - /** - * Retrieve the Minecraft version for the specified release-type. - * @author Griefed - * @param type String. Release-type which specifies which Fabric version is retrieved. Can be <code>release, snapshot</code> - * @return String. Returns the Minecraft version for the specified release-type. - */ - private String setMinecraftSpecificVersion(String type) { - - String minecraftVersion = null; - - try { - JsonNode minecraftJson = getJson(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_MINECRAFT); - - minecraftVersion = minecraftJson.get("latest").get(type).asText(); - - } catch (IOException ex) { - LOG.error("Couldn't read Minecraft manifest.", ex); - } - - return minecraftVersion; - } - - /** - * Retrieve a list of available Forge versions for the specified Minecraft version. If Forge is not available for a - * given Minecraft version, <code>"None"</code> is returned as the sole content of the list. - * @author Griefed - * @param selectedMinecraftVersion String. The Minecraft version for which to search for available Forge version. - * @return List String. Returns a list of available Forge versions for the specified Minecraft version. - */ - private List<String> getForgeVersionsList(String selectedMinecraftVersion) { - - List<String> forgeReleases = new ArrayList<>(); - - try { - JsonNode forgeJson = getJson(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FORGE); - - try { - JsonNode versions = forgeJson.get(selectedMinecraftVersion); - - for (JsonNode version : versions) { - forgeReleases.add(version.asText().replace(selectedMinecraftVersion + "-", "")); - } - } catch (NullPointerException ignored) { - forgeReleases.add("None"); - } - - } catch (IOException ex) { - LOG.error("Couldn't read Forge manifest.", ex); - } - - return forgeReleases; - } - - /** - * Retrieve a list of all available Fabric versions from the Fabric manifest-file. - * @author Griefed - * @return List String. Returns a list of all available Fabric versions. - */ - private List<String> setFabricVersionList() { - - List<String> fabricReleases = new ArrayList<>(); - - Document fabricXml = getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC); - - NodeList versions = fabricXml.getElementsByTagName("version"); - - for (int i = 0; i < versions.getLength(); i++) { - fabricReleases.add(versions.item(i).getChildNodes().item(0).getNodeValue()); - } - - LOG.debug("Fabric versions: " + fabricReleases); - - return fabricReleases; - } - - /** - * Retrieve the Fabric version for the specified release-type. - * @author Griefed - * @param versionSpecifier String. Release-type which specifies which Fabric version is retrieved. Can be <code>latest, release</code> - * @param manifest Document. The document from which to gather information from. - * @return String. Returns the Fabric version for the specified release-type. - */ - private String setFabricSpecificVersion(String versionSpecifier, Document manifest) { - return manifest.getElementsByTagName(versionSpecifier).item(0).getChildNodes().item(0).getNodeValue(); - } -} diff --git a/backend/main/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpack.java b/backend/main/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpack.java index f2cd1f33977a9930bab2e31349df54e5645e8bd9..73cb923ace2a7d211229a99c5826914f8ce6d963 100644 --- a/backend/main/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpack.java +++ b/backend/main/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpack.java @@ -27,7 +27,8 @@ import de.griefed.serverpackcreator.ConfigurationModel; import de.griefed.serverpackcreator.i18n.LocalizationManager; import de.griefed.serverpackcreator.ApplicationProperties; import de.griefed.serverpackcreator.utilities.*; -import de.griefed.serverpackcreator.VersionLister; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -64,13 +65,8 @@ public class CurseCreateModpack { private final LocalizationManager LOCALIZATIONMANAGER; private final ApplicationProperties APPLICATIONPROPERTIES; - private final VersionLister VERSIONLISTER; - private final BooleanUtilities BOOLEANUTILITIES; - private final ListUtilities LISTUTILITIES; - private final StringUtilities STRINGUTILITIES; + private final Utilities UTILITIES; private final ConfigUtilities CONFIGUTILITIES; - private final SystemUtilities SYSTEMUTILITIES; - private final ReticulatingSplines reticulatingSplines = new ReticulatingSplines(); private final Random randInt = new Random(); @@ -83,18 +79,14 @@ public class CurseCreateModpack { * @author Griefed * @param injectedLocalizationManager Instance of {@link LocalizationManager} required for localized log messages. * @param injectedApplicationProperties Instance of {@link Properties} required for various different things. - * @param injectedBooleanUtilities Instance of {@link BooleanUtilities}. - * @param injectedListUtilities Instance of {@link ListUtilities}. - * @param injectedStringUtilities Instance of {@link StringUtilities}. - * @param injectedConfigUtilities Instance of {@link ConfigUtilities}. - * @param injectedVersionLister Instance of {@link VersionLister}. - * @param injectedSystemUtilities Instance of {@link SystemUtilities}. + * @param injectedVersionMeta Instance of {@link VersionMeta}. + * @param injectedUtilities Instance of {@link Utilities}. + * @param injectedConfigUtilities Instance {@link ConfigUtilities} + * @throws IOException if the {@link VersionMeta} could not be instantiated. */ @Autowired public CurseCreateModpack(LocalizationManager injectedLocalizationManager, ApplicationProperties injectedApplicationProperties, - VersionLister injectedVersionLister, BooleanUtilities injectedBooleanUtilities, - ListUtilities injectedListUtilities, StringUtilities injectedStringUtilities, ConfigUtilities injectedConfigUtilities, - SystemUtilities injectedSystemUtilities) { + VersionMeta injectedVersionMeta, Utilities injectedUtilities, ConfigUtilities injectedConfigUtilities) throws IOException { if (injectedApplicationProperties == null) { this.APPLICATIONPROPERTIES = new ApplicationProperties(); @@ -108,41 +100,24 @@ public class CurseCreateModpack { this.LOCALIZATIONMANAGER = injectedLocalizationManager; } - if (injectedVersionLister == null) { - this.VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); - } else { - this.VERSIONLISTER = injectedVersionLister; - } - - if (injectedBooleanUtilities == null) { - this.BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - } else { - this.BOOLEANUTILITIES = injectedBooleanUtilities; - } - - if (injectedListUtilities == null) { - this.LISTUTILITIES = new ListUtilities(); + VersionMeta VERSIONMETA; + if (injectedVersionMeta == null) { + VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); } else { - this.LISTUTILITIES = injectedListUtilities; + VERSIONMETA = injectedVersionMeta; } - if (injectedStringUtilities == null) { - this.STRINGUTILITIES = new StringUtilities(); + if (injectedUtilities == null) { + this.UTILITIES = new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); } else { - this.STRINGUTILITIES = injectedStringUtilities; + this.UTILITIES = injectedUtilities; } if (injectedConfigUtilities == null) { - this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, BOOLEANUTILITIES, LISTUTILITIES, APPLICATIONPROPERTIES, STRINGUTILITIES, VERSIONLISTER); + this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, UTILITIES, APPLICATIONPROPERTIES, VERSIONMETA); } else { this.CONFIGUTILITIES = injectedConfigUtilities; } - - if (injectedSystemUtilities == null) { - this.SYSTEMUTILITIES = new SystemUtilities(); - } else { - this.SYSTEMUTILITIES = injectedSystemUtilities; - } } /** @@ -314,7 +289,7 @@ public class CurseCreateModpack { CurseAPI.downloadFileToDirectory(projectID, fileID, Paths.get(modpackDir)); - SYSTEMUTILITIES.unzipArchive(CurseAPI.downloadFileToDirectory(projectID, fileID, Paths.get(modpackDir)).orElseThrow(NullPointerException::new).toString(), modpackDir); + UTILITIES.FileUtils().unzipArchive(CurseAPI.downloadFileToDirectory(projectID, fileID, Paths.get(modpackDir)).orElseThrow(NullPointerException::new).toString(), modpackDir); } catch (NullPointerException | CurseException cex) { LOG.error(String.format("Error: Could not download file %s for project %s to directory %s.", configurationModel.getFileName(), configurationModel.getProjectName(), modpackDir)); diff --git a/backend/main/java/de/griefed/serverpackcreator/plugins/ApplicationPlugins.java b/backend/main/java/de/griefed/serverpackcreator/plugins/ApplicationPlugins.java new file mode 100644 index 0000000000000000000000000000000000000000..d6d9025a86cc58777961d62a19a9c77936bc132e --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/plugins/ApplicationPlugins.java @@ -0,0 +1,175 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.plugins; + +import de.griefed.serverpackcreator.plugins.serverpackhandler.PostGenExtension; +import de.griefed.serverpackcreator.plugins.serverpackhandler.PreZipExtension; +import de.griefed.serverpackcreator.plugins.serverpackhandler.PreGenExtension; +import de.griefed.serverpackcreator.plugins.swinggui.TabExtension; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.pf4j.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.File; +import java.util.List; + +/** + * Manager for ServerPackCreator plugins. In itself it doesn't do much. It gathers lists of all available extensions for + * {@link TabExtension},{@link PreGenExtension},{@link PreZipExtension} and {@link PostGenExtension} so they can then be + * run during server pack generation and during initialization of the GUI. + * @author Griefed + */ +@Component +public class ApplicationPlugins extends JarPluginManager { + + private static final Logger LOG = LogManager.getLogger(ApplicationPlugins.class); + + private final List<PreGenExtension> PLUGINS_PreGenExtension; + private final List<PreZipExtension> PLUGINS_PreZipExtension; + private final List<PostGenExtension> PLUGINS_PostGenExtension; + private final List<TabExtension> PLUGINS_TabExtension; + + /** + * Constructor + * @author Griefed + */ + @Autowired + public ApplicationPlugins() { + + LOG.info("Plugins directory: " + new File(System.getProperty("pf4j.pluginsDir", "plugins")).getAbsolutePath()); + + loadPlugins(); + startPlugins(); + + this.PLUGINS_PreGenExtension = getExtensions(PreGenExtension.class); + this.PLUGINS_PreZipExtension = getExtensions(PreZipExtension.class); + this.PLUGINS_PostGenExtension = getExtensions(PostGenExtension.class); + this.PLUGINS_TabExtension = getExtensions(TabExtension.class); + + availablePluginsAndExtensions(); + } + + @Override + protected ExtensionFactory createExtensionFactory() { + return new SingletonExtensionFactory(); + } + + /** + * Print information about available plugins to our logs. + * @author Griefed + */ + private void availablePluginsAndExtensions() { + + if (PLUGINS_PreGenExtension.isEmpty() && + PLUGINS_PreZipExtension.isEmpty() && + PLUGINS_PostGenExtension.isEmpty() && + PLUGINS_TabExtension.isEmpty()) { + + LOG.info("No plugins installed."); + return; + } + + if (!PLUGINS_PreGenExtension.isEmpty()) { + LOG.info("Available PreGenExtension plugins:"); + PLUGINS_PreGenExtension.forEach(plugin -> { + LOG.info("Name: " + plugin.getName()); + LOG.info("Description:" + plugin.getDescription()); + LOG.info("Version: " + plugin.getVersion()); + LOG.info("Author: " + plugin.getAuthor()); + }); + } else { + LOG.info("No PreGenExtensions installed."); + } + + if (!PLUGINS_PreZipExtension.isEmpty()) { + LOG.info("Available PreZipExtension plugins:"); + PLUGINS_PreZipExtension.forEach(plugin -> { + LOG.info("Name: " + plugin.getName()); + LOG.info("Description:" + plugin.getDescription()); + LOG.info("Version: " + plugin.getVersion()); + LOG.info("Author: " + plugin.getAuthor()); + }); + } else { + LOG.info("No PreZipExtension installed."); + } + + if (!PLUGINS_PostGenExtension.isEmpty()) { + LOG.info("Available PostGenExtension plugins:"); + PLUGINS_PostGenExtension.forEach(plugin -> { + LOG.info("Name: " + plugin.getName()); + LOG.info("Description:" + plugin.getDescription()); + LOG.info("Version: " + plugin.getVersion()); + LOG.info("Author: " + plugin.getAuthor()); + }); + } else { + LOG.info("No PostGenExtension installed."); + } + + if (!PLUGINS_TabExtension.isEmpty()) { + LOG.info("Available TabExtension plugins:"); + PLUGINS_TabExtension.forEach(plugin -> { + LOG.info("Name: " + plugin.getName()); + LOG.info("Description:" + plugin.getDescription()); + LOG.info("Version: " + plugin.getVersion()); + LOG.info("Author: " + plugin.getAuthor()); + }); + } else { + LOG.info("No TabExtension installed."); + } + } + + /** + * List of available {@link PreGenExtension}-plugins. + * @author Griefed + * @return List of available {@link PreGenExtension}-plugins. + */ + public List<PreGenExtension> pluginsPreGenExtension() { + return PLUGINS_PreGenExtension; + } + + /** + * List of available {@link PreZipExtension}-plugins. + * @author Griefed + * @return List of available {@link PreZipExtension}-plugins. + */ + public List<PreZipExtension> pluginsPreZipExtension() { + return PLUGINS_PreZipExtension; + } + + /** + * List of available {@link PostGenExtension}-plugins. + * @author Griefed + * @return List of available {@link PostGenExtension}-plugins. + */ + public List<PostGenExtension> pluginsPostGenExtension() { + return PLUGINS_PostGenExtension; + } + + /** + * List of available {@link TabExtension}-plugins. + * @author Griefed + * @return List of available {@link TabExtension}-plugins. + */ + public List<TabExtension> pluginsTabExtension() { + return PLUGINS_TabExtension; + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/spring/ApplicationPropertiesController.java b/backend/main/java/de/griefed/serverpackcreator/spring/ApplicationPropertiesController.java index dbcffb1c7bdbcb2ee88aaba656c38f94e71d4daf..4fcc3a8639b073a54217c715898f143d805723d7 100644 --- a/backend/main/java/de/griefed/serverpackcreator/spring/ApplicationPropertiesController.java +++ b/backend/main/java/de/griefed/serverpackcreator/spring/ApplicationPropertiesController.java @@ -20,7 +20,7 @@ package de.griefed.serverpackcreator.spring; import de.griefed.serverpackcreator.ApplicationProperties; -import de.griefed.serverpackcreator.utilities.ListUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -41,21 +41,21 @@ public class ApplicationPropertiesController { private static final Logger LOG = LogManager.getLogger(ApplicationPropertiesController.class); private final ApplicationProperties APPLICATIONPROPERTIES; - private final ListUtilities LISTUTILITIES; + private final Utilities UTILITIES; /** * Constructor for DI. * @author Griefed * @param injectedApplicationProperties Instance of {@link ApplicationProperties} with the configuration of this ServerPackCreator * instance. - * @param injectedListUtilities Instance of {@link ListUtilities}. + * @param injectedUtilities Instance of {@link Utilities}. */ @Autowired public ApplicationPropertiesController(ApplicationProperties injectedApplicationProperties, - ListUtilities injectedListUtilities) { + Utilities injectedUtilities) { this.APPLICATIONPROPERTIES = injectedApplicationProperties; - this.LISTUTILITIES = injectedListUtilities; + this.UTILITIES = injectedUtilities; } @GetMapping(produces = "application/json") @@ -92,8 +92,8 @@ public class ApplicationPropertiesController { "\"isCurseForgeActivated\": " + APPLICATIONPROPERTIES.isCurseForgeActivated() + "" + "}";*/ return "{" + - "\"listFallbackMods\":" + LISTUTILITIES.encapsulateListElements(APPLICATIONPROPERTIES.getListFallbackMods()) + "," + - "\"listDirectoriesExclude\":" + LISTUTILITIES.encapsulateListElements(APPLICATIONPROPERTIES.getListOfDirectoriesToExclude()) + "," + + "\"listFallbackMods\":" + UTILITIES.ListUtils().encapsulateListElements(APPLICATIONPROPERTIES.getListFallbackMods()) + "," + + "\"listDirectoriesExclude\":" + UTILITIES.ListUtils().encapsulateListElements(APPLICATIONPROPERTIES.getListOfDirectoriesToExclude()) + "," + "\"curseControllerRegenerationEnabled\": " + APPLICATIONPROPERTIES.getCurseControllerRegenerationEnabled() + "," + "\"serverPackCreatorVersion\":\"" + APPLICATIONPROPERTIES.getServerPackCreatorVersion() + "\"," + "\"isCurseForgeActivated\": " + APPLICATIONPROPERTIES.isCurseForgeActivated() + "" + diff --git a/backend/main/java/de/griefed/serverpackcreator/spring/Schedules.java b/backend/main/java/de/griefed/serverpackcreator/spring/Schedules.java index c306272cc88c6133f96c3a754698fd6c5d7a259a..4078acc483e5b2fbf469b68b2c3c1370fb7660df 100644 --- a/backend/main/java/de/griefed/serverpackcreator/spring/Schedules.java +++ b/backend/main/java/de/griefed/serverpackcreator/spring/Schedules.java @@ -21,9 +21,9 @@ package de.griefed.serverpackcreator.spring; import de.griefed.serverpackcreator.ApplicationProperties; import de.griefed.serverpackcreator.DefaultFiles; -import de.griefed.serverpackcreator.VersionLister; import de.griefed.serverpackcreator.spring.serverpack.ServerPackModel; import de.griefed.serverpackcreator.spring.serverpack.ServerPackService; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -32,6 +32,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.io.File; +import java.io.IOException; import java.sql.Timestamp; import java.util.Date; @@ -47,7 +48,7 @@ public class Schedules { private final ApplicationProperties APPLICATIONPROPERTIES; private final ServerPackService SERVERPACKSERVICE; private final DefaultFiles DEFAULTFILES; - private final VersionLister VERSIONLISTER; + private final VersionMeta VERSIONMETA; /** * Constructor for DI. @@ -55,16 +56,16 @@ public class Schedules { * @param injectedApplicationProperties Instance of {@link ApplicationProperties}. * @param injectedServerPackService Instance of {@link ServerPackService}. * @param injectedDefaultFiles Instance of {@link DefaultFiles}. - * @param injectedVersionLister Instance of {@link VersionLister}. + * @param injectedVersionMeta Instance of {@link VersionMeta}. */ @Autowired public Schedules(ApplicationProperties injectedApplicationProperties, ServerPackService injectedServerPackService, - DefaultFiles injectedDefaultFiles, VersionLister injectedVersionLister) { + DefaultFiles injectedDefaultFiles, VersionMeta injectedVersionMeta) { this.APPLICATIONPROPERTIES = injectedApplicationProperties; this.SERVERPACKSERVICE = injectedServerPackService; this.DEFAULTFILES = injectedDefaultFiles; - this.VERSIONLISTER = injectedVersionLister; + this.VERSIONMETA = injectedVersionMeta; } private void deletePack(ServerPackModel pack) { @@ -155,6 +156,10 @@ public class Schedules { DEFAULTFILES.refreshManifestFile(DEFAULTFILES.getFabricManifestUrl(), APPLICATIONPROPERTIES.FILE_MANIFEST_FABRIC); DEFAULTFILES.refreshManifestFile(DEFAULTFILES.getFabricInstallerManifestUrl(), APPLICATIONPROPERTIES.FILE_MANIFEST_FABRIC_INSTALLER); - VERSIONLISTER.refreshVersions(); + try { + VERSIONMETA.update(); + } catch (IOException e) { + e.printStackTrace(); + } } } diff --git a/backend/main/java/de/griefed/serverpackcreator/spring/VersionsController.java b/backend/main/java/de/griefed/serverpackcreator/spring/VersionsController.java index f1b9e92c22f7977b38a4ec66f13389ed2e62fda5..729b8d85979d256579b2b27f88b999a89380fa4d 100644 --- a/backend/main/java/de/griefed/serverpackcreator/spring/VersionsController.java +++ b/backend/main/java/de/griefed/serverpackcreator/spring/VersionsController.java @@ -19,10 +19,8 @@ */ package de.griefed.serverpackcreator.spring; -import de.griefed.serverpackcreator.VersionLister; -import de.griefed.serverpackcreator.utilities.ListUtilities; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -36,21 +34,19 @@ import org.springframework.web.bind.annotation.*; @RequestMapping("/api/v1/versions") public class VersionsController { - private static final Logger LOG = LogManager.getLogger(VersionsController.class); - - private final VersionLister VERSIONLISTER; - private final ListUtilities LISTUTILITIES; + private final VersionMeta VERSIONMETA; + private final Utilities UTILITIES; /** * Constructor for DI. * @author Griefed - * @param injectedVersionLister Instance of {@link VersionLister} for version acquisition. - * @param injectedListUtilities Instance of {@link ListUtilities}. + * @param injectedVersionMeta Instance of {@link VersionMeta} for version acquisition. + * @param injectedUtilities Instance of {@link Utilities}. */ @Autowired - public VersionsController(VersionLister injectedVersionLister, ListUtilities injectedListUtilities) { - this.VERSIONLISTER = injectedVersionLister; - this.LISTUTILITIES = injectedListUtilities; + public VersionsController(VersionMeta injectedVersionMeta, Utilities injectedUtilities) { + this.VERSIONMETA = injectedVersionMeta; + this.UTILITIES = injectedUtilities; } /** @@ -68,8 +64,9 @@ public class VersionsController { "application/json" ).body( "{\"minecraft\":" + - LISTUTILITIES.encapsulateListElements(VERSIONLISTER.getMinecraftReleaseVersions()) + - "}" + UTILITIES.ListUtils().encapsulateListElements( + VERSIONMETA.minecraft().releaseVersionsDescending() + ) + "}" ); } @@ -89,10 +86,7 @@ public class VersionsController { "application/json" ).body( "{\"forge\":" + - LISTUTILITIES.encapsulateListElements( - VERSIONLISTER.reverseOrderList( - VERSIONLISTER.getForgeVersionsAsList(minecraftVersion) - ) + UTILITIES.ListUtils().encapsulateListElements(VERSIONMETA.forge().forgeVersionsDescending() ) + "}" ); @@ -114,10 +108,7 @@ public class VersionsController { "application/json" ).body( "{\"fabric\":" + - LISTUTILITIES.encapsulateListElements( - VERSIONLISTER.reverseOrderList( - VERSIONLISTER.getFabricVersions() - ) + UTILITIES.ListUtils().encapsulateListElements(VERSIONMETA.fabric().loaderVersionsDescending() ) + "}" ); @@ -138,8 +129,8 @@ public class VersionsController { "application/json" ).body( "{" + - "\"release\":\"" + VERSIONLISTER.getFabricReleaseInstallerVersion() + "\"," + - "\"latest\":\"" + VERSIONLISTER.getFabricLatestInstallerVersion() + "\"" + + "\"release\":\"" + VERSIONMETA.fabric().releaseInstallerVersion() + "\"," + + "\"latest\":\"" + VERSIONMETA.fabric().releaseInstallerVersion() + "\"" + "}" ); } diff --git a/backend/main/java/de/griefed/serverpackcreator/spring/serverpack/ServerPackService.java b/backend/main/java/de/griefed/serverpackcreator/spring/serverpack/ServerPackService.java index 0b6f2ed37e7d8d8e58cd72a4d9c41653d4ea6e22..70cfd92c127bbadeeebe599682577b517a92c41e 100644 --- a/backend/main/java/de/griefed/serverpackcreator/spring/serverpack/ServerPackService.java +++ b/backend/main/java/de/griefed/serverpackcreator/spring/serverpack/ServerPackService.java @@ -19,7 +19,6 @@ */ package de.griefed.serverpackcreator.spring.serverpack; -import de.griefed.serverpackcreator.ApplicationProperties; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -48,18 +47,15 @@ public class ServerPackService { private static final Logger LOG = LogManager.getLogger(ServerPackService.class); - private final ApplicationProperties APPLICATIONPROPERTIES; private final ServerPackRepository SERVERPACKREPOSITORY; /** * Constructor responsible for our DI. * @author Griefed - * @param injectedApplicationProperties Instance of {@link ApplicationProperties}. * @param injectedServerPackRepository Instance of {@link ServerPackRepository}. */ @Autowired - public ServerPackService(ApplicationProperties injectedApplicationProperties, ServerPackRepository injectedServerPackRepository) { - this.APPLICATIONPROPERTIES = injectedApplicationProperties; + public ServerPackService(ServerPackRepository injectedServerPackRepository) { this.SERVERPACKREPOSITORY = injectedServerPackRepository; } @@ -201,8 +197,8 @@ public class ServerPackService { /** * Update a server pack database entry with the given database id. * @author Griefed - * @param id Integer. The database id of the server pack to update. - * @param serverPackModel Instance of {@link ServerPackModel} with which to update the entry in the database. + * @param id Integer. The database id of the server pack to initialize. + * @param serverPackModel Instance of {@link ServerPackModel} with which to initialize the entry in the database. */ public void updateServerPackByID(int id, ServerPackModel serverPackModel) { if (SERVERPACKREPOSITORY.findById(id).isPresent()) { @@ -255,7 +251,7 @@ public class ServerPackService { * @author Griefed * @param projectID The CurseForge project ID. * @param fileID The CurseForge file ID. - * @param serverPackModel The server pack with which to update the entry in the database. + * @param serverPackModel The server pack with which to initialize the entry in the database. */ public void updateServerPackByProjectIDAndFileID(int projectID, int fileID, ServerPackModel serverPackModel) { if (SERVERPACKREPOSITORY.findByProjectIDAndFileID(projectID, fileID).isPresent()) { diff --git a/backend/main/java/de/griefed/serverpackcreator/spring/zip/ZipService.java b/backend/main/java/de/griefed/serverpackcreator/spring/zip/ZipService.java index 9cd726ad38d3c335b2b3e65357421ca4b1fc80f0..d742928fae3c041b4494af4b672a7ebccb15469b 100644 --- a/backend/main/java/de/griefed/serverpackcreator/spring/zip/ZipService.java +++ b/backend/main/java/de/griefed/serverpackcreator/spring/zip/ZipService.java @@ -23,6 +23,8 @@ import de.griefed.serverpackcreator.ConfigurationHandler; import de.griefed.serverpackcreator.spring.NotificationResponse; import de.griefed.serverpackcreator.spring.task.TaskSubmitter; import de.griefed.serverpackcreator.utilities.ConfigUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -46,25 +48,32 @@ public class ZipService { private final TaskSubmitter TASKSUBMITTER; private final ConfigurationHandler CONFIGURATIONHANDLER; - private final ConfigUtilities CONFIGUTILITIES; + private final Utilities UTILITIES; private final NotificationResponse NOTIFICATIONRESPONSE; + private final VersionMeta VERSIONMETA; + private final ConfigUtilities CONFIGUTILITIES; /** * Constructor responsible for DI. * @author Griefed * @param injectedTaskSubmitter Instance of {@link TaskSubmitter}. * @param injectedConfigurationHandler Instance of {@link ConfigurationHandler}. - * @param injectedConfigUtilities Instance of {@link ConfigUtilities}. + * @param injectedUtilities Instance of {@link Utilities}. * @param injectedNotificationResponse Instance of {@link NotificationResponse}. + * @param injectedVersionMeta Instance of {@link VersionMeta}. + * @param injectedConfigUtilities Instance of {@link ConfigUtilities}. */ @Autowired public ZipService(TaskSubmitter injectedTaskSubmitter, ConfigurationHandler injectedConfigurationHandler, - ConfigUtilities injectedConfigUtilities, NotificationResponse injectedNotificationResponse) { + Utilities injectedUtilities, NotificationResponse injectedNotificationResponse, + VersionMeta injectedVersionMeta, ConfigUtilities injectedConfigUtilities) { this.TASKSUBMITTER = injectedTaskSubmitter; this.CONFIGURATIONHANDLER = injectedConfigurationHandler; - this.CONFIGUTILITIES = injectedConfigUtilities; + this.UTILITIES = injectedUtilities; this.NOTIFICATIONRESPONSE = injectedNotificationResponse; + this.VERSIONMETA = injectedVersionMeta; + this.CONFIGUTILITIES = injectedConfigUtilities; } /** @@ -125,7 +134,7 @@ public class ZipService { } // Check the Minecraft version - if (!CONFIGURATIONHANDLER.isMinecraftVersionCorrect(parameters[2])) { + if (!VERSIONMETA.minecraft().checkMinecraftVersion(parameters[2])) { LOG.info("Minecraft version " + parameters[2] + " incorrect."); return NOTIFICATIONRESPONSE.zipResponse( @@ -144,7 +153,7 @@ public class ZipService { // Check Forge if (CONFIGUTILITIES.getModLoaderCase(parameters[3]).equals("Forge")) { - if (!CONFIGURATIONHANDLER.isForgeVersionCorrect(parameters[4],parameters[2])) { + if (!VERSIONMETA.forge().checkForgeAndMinecraftVersion(parameters[2],parameters[4])) { LOG.info(parameters[3] + " version " + parameters[2] + "-" + parameters[4] + " incorrect."); return NOTIFICATIONRESPONSE.zipResponse( "Incorrect Forge version: " + parameters[2], @@ -159,7 +168,7 @@ public class ZipService { // Check Fabric } else { - if (!CONFIGURATIONHANDLER.isFabricVersionCorrect(parameters[4])) { + if (!VERSIONMETA.fabric().checkFabricVersion(parameters[4])) { LOG.info(parameters[3] + " version " + parameters[4] + " incorrect."); return NOTIFICATIONRESPONSE.zipResponse( "Incorrect Fabric version: " + parameters[4], diff --git a/backend/main/java/de/griefed/serverpackcreator/swing/MenuBar.java b/backend/main/java/de/griefed/serverpackcreator/swing/MenuBar.java index a69af693de0ae04fb9d3d452d3290ab1994cd6cf..c85579b1c89ff6656c77ce4519c4eeab6612db9d 100644 --- a/backend/main/java/de/griefed/serverpackcreator/swing/MenuBar.java +++ b/backend/main/java/de/griefed/serverpackcreator/swing/MenuBar.java @@ -47,6 +47,7 @@ import java.net.ProtocolException; import java.net.URI; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Objects; import java.util.Properties; @@ -85,14 +86,12 @@ public class MenuBar extends Component { private final Dimension JAVAARGSDIMENSION = new Dimension(750,25); private final Dimension ABOUTDIMENSION = new Dimension(925,520); private final Dimension FILETOOLARGEDIMENSION = new Dimension(200,10); - private final Dimension HELPDIMENSION = new Dimension(750,300); private final ImageIcon HELPICON = new ImageIcon(Objects.requireNonNull(SwingGuiInitializer.class.getResource("/de/griefed/resources/gui/help.png"))); private final ImageIcon ICON_HASTEBIN = new ImageIcon(Objects.requireNonNull(SwingGuiInitializer.class.getResource("/de/griefed/resources/gui/hastebin.png"))); private final JMenuBar MENUBAR = new JMenuBar(); - private final String HELPWINDOWTEXT; private final String ABOUTWINDOWTEXT; private final String FILETOOLARGETEXT; private final String FILETOOLARGETITLE; @@ -100,24 +99,19 @@ public class MenuBar extends Component { private final String[] JAVAARGSOPTIONS = new String[4]; private final String[] JAVAARGSSELECTIONS = new String[2]; private final String[] HASTEOPTIONS = new String[3]; - private final String[] HELPTEXTS = new String[13]; - private final String[] HELPSELECTIONS = new String[13]; private final JTextField JAVAARGS = new JTextField(); - private final StyledDocument HELPWINDOWDOCUMENT = new DefaultStyledDocument(); private final StyledDocument ABOUTWINDOWDOCUMENT = new DefaultStyledDocument(); private final StyledDocument CONFIGWINDOWDOCUMENT = new DefaultStyledDocument(); private final StyledDocument SPCLOGWINDOWDOCUMENT = new DefaultStyledDocument(); private final StyledDocument FILETOOLARGEWINDOWDOCUMENT = new DefaultStyledDocument(); private final SimpleAttributeSet ABOUTATTRIBUTESET = new SimpleAttributeSet(); - private final SimpleAttributeSet HELPATTRIBUTESET = new SimpleAttributeSet(); private final SimpleAttributeSet CONFIGATTRIBUTESET = new SimpleAttributeSet(); private final SimpleAttributeSet SPCLOGATTRIBUTESET = new SimpleAttributeSet(); private final SimpleAttributeSet FILETOOLARGEATTRIBUTESET = new SimpleAttributeSet(); - private final JTextPane HELPWINDOWTEXTPANE = new JTextPane(HELPWINDOWDOCUMENT); private final JTextPane ABOUTWINDOWTEXTPANE = new JTextPane(ABOUTWINDOWDOCUMENT); private final JTextPane CONFIGWINDOWTEXTPANE = new JTextPane(CONFIGWINDOWDOCUMENT); private final JTextPane SPCLOGWINDOWTEXTPANE = new JTextPane(SPCLOGWINDOWDOCUMENT); @@ -127,10 +121,6 @@ public class MenuBar extends Component { private final MaterialTextFieldUI MATERIALTEXTFIELDUI = new MaterialTextFieldUI(); private final MaterialComboBoxUI MATERIALCOMBOBOXUI = new MaterialComboBoxUI(); - private final JTextArea HELPTEXTAREA = new JTextArea(); - - private final JPanel HELPPANEL = new JPanel(); - private boolean isDarkTheme; private JMenu fileMenu; @@ -145,6 +135,7 @@ public class MenuBar extends Component { private JMenuItem file_UploadConfigurationToHasteBin; private JMenuItem file_UploadServerPackCreatorLogToHasteBin; private JMenuItem file_ExitConfigMenuItem; + private JMenuItem file_UpdateFallbackModslist; private JMenuItem edit_SwitchTheme; private JMenuItem edit_ChangeJavaArgs; @@ -163,14 +154,11 @@ public class MenuBar extends Component { private JMenuItem about_OpenDonationsPageMenuItem; private JMenuItem about_OpenReleasesPageMenuItem; private JMenuItem about_OpenDiscordLinkMenuItem; - - private JMenuItem help_OpenHelpWindowMenuItem; + private JMenuItem about_OpenWikiHelpMenuItem; + private JMenuItem about_OpenWikiHowToMenuItem; private JFileChooser configChooser; - private DefaultComboBoxModel<String> helpComboBoxModel; - private JComboBox<String> helpComboBox; - private File lastLoadedConfigurationFile = null; /** @@ -246,42 +234,6 @@ public class MenuBar extends Component { } }); - HELPWINDOWTEXT = String.format( - "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s", - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.modpackdir"), - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.clientsidemods"), - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.directories"), - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.pathtojava"), - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.minecraftversion"), - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.modloader"), - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.modloaderversion"), - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.installserver"), - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.copypropertires"), - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.copyicon"), - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.createzip") - ); - HELPWINDOWTEXTPANE.setEditable(false); - HELPWINDOWTEXTPANE.setOpaque(false); - StyleConstants.setBold(HELPATTRIBUTESET, true); - StyleConstants.setFontSize(HELPATTRIBUTESET, 14); - HELPWINDOWTEXTPANE.setCharacterAttributes(HELPATTRIBUTESET, true); - StyleConstants.setAlignment(HELPATTRIBUTESET, StyleConstants.ALIGN_LEFT); - HELPWINDOWDOCUMENT.setParagraphAttributes(0, HELPWINDOWDOCUMENT.getLength(), HELPATTRIBUTESET, false); - try { - HELPWINDOWDOCUMENT.insertString(0, HELPWINDOWTEXT, HELPATTRIBUTESET); - } catch (BadLocationException ex) { - LOG.error("Error inserting text into aboutDocument.", ex); - } - HELPWINDOWTEXTPANE.addHierarchyListener(e1 -> { - Window window = SwingUtilities.getWindowAncestor(HELPWINDOWTEXTPANE); - if (window instanceof Dialog) { - Dialog dialog = (Dialog) window; - if (!dialog.isResizable()) { - dialog.setResizable(true); - } - } - }); - HASTEOPTIONS[0] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.about.hastebin.dialog.yes"); HASTEOPTIONS[1] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.about.hastebin.dialog.clipboard"); HASTEOPTIONS[2] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.about.hastebin.dialog.no"); @@ -364,37 +316,6 @@ public class MenuBar extends Component { JAVAARGS.setMaximumSize(JAVAARGSDIMENSION); JAVAARGS.setPreferredSize(JAVAARGSDIMENSION); - HELPTEXTS[0] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.modpackdir"); - HELPTEXTS[1] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.clientsidemods"); - HELPTEXTS[2] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.directories"); - HELPTEXTS[3] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.pathtojava"); - HELPTEXTS[4] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.minecraftversion"); - HELPTEXTS[5] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.modloader"); - HELPTEXTS[6] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.modloaderversion"); - HELPTEXTS[7] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.installserver"); - HELPTEXTS[8] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.copypropertires"); - HELPTEXTS[9] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.copyicon"); - HELPTEXTS[10] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.createzip"); - HELPTEXTS[11] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.javaargs"); - - HELPSELECTIONS[0] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.labelmodpackdir"); - HELPSELECTIONS[1] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.labelclientmods"); - HELPSELECTIONS[2] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.labelcopydirs"); - HELPSELECTIONS[3] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.labeljavapath"); - HELPSELECTIONS[4] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.labelminecraft"); - HELPSELECTIONS[5] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.labelmodloader"); - HELPSELECTIONS[6] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.labelmodloaderversion"); - HELPSELECTIONS[7] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.checkboxserver"); - HELPSELECTIONS[8] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.checkboxproperties"); - HELPSELECTIONS[9] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.checkboxicon"); - HELPSELECTIONS[10] = LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.checkboxzip"); - HELPSELECTIONS[11] = LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.javaargs"); - - HELPTEXTAREA.setEditable(false); - HELPPANEL.setLayout(new BoxLayout(HELPPANEL, BoxLayout.Y_AXIS)); - HELPPANEL.setMinimumSize(HELPDIMENSION); - HELPPANEL.setPreferredSize(HELPDIMENSION); - HELPPANEL.setMaximumSize(HELPDIMENSION); } /** @@ -409,7 +330,6 @@ public class MenuBar extends Component { editMenu = new JMenu(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menu.edit")); viewMenu = new JMenu(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menu.view")); aboutMenu = new JMenu(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menu.about")); - help_OpenHelpWindowMenuItem = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menu.help")); // create menu items file_NewConfigurationMenuItem = new JMenuItem("New configuration"); @@ -418,6 +338,7 @@ public class MenuBar extends Component { file_SaveAsConfigMenuItem = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.saveas")); file_UploadConfigurationToHasteBin = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.uploadconfig")); file_UploadServerPackCreatorLogToHasteBin = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.uploadlog")); + file_UpdateFallbackModslist = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.updatefallback")); file_ExitConfigMenuItem = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.exit")); edit_SwitchTheme = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.theme")); @@ -437,6 +358,8 @@ public class MenuBar extends Component { about_OpenReleasesPageMenuItem = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.releases")); about_OpenDiscordLinkMenuItem = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.discord")); about_OpenDonationsPageMenuItem = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.donate")); + about_OpenWikiHelpMenuItem = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.wiki.help")); + about_OpenWikiHowToMenuItem = new JMenuItem(LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.wiki.howto")); // create action listeners for items file_NewConfigurationMenuItem.addActionListener(this::actionEventNewConfiguration); @@ -445,6 +368,7 @@ public class MenuBar extends Component { file_SaveAsConfigMenuItem.addActionListener(this::actionEventSaveAsConfigToFileMenuItem); file_UploadConfigurationToHasteBin.addActionListener(this::actionEventUploadConfigurationToHasteBinMenuItem); file_UploadServerPackCreatorLogToHasteBin.addActionListener(this::actionEventUploadServerPackCreatorLogToHasteBinMenuItem); + file_UpdateFallbackModslist.addActionListener(this::actionEventUpdateFallbackModslist); file_ExitConfigMenuItem.addActionListener(this::actionEventExitMenuItem); edit_SwitchTheme.addActionListener(this::actionEventSwitchThemeMenuItem); @@ -464,19 +388,8 @@ public class MenuBar extends Component { about_OpenReleasesPageMenuItem.addActionListener(this::actionEventOpenReleaseMenuItem); about_OpenDiscordLinkMenuItem.addActionListener(this::actionEventOpenDiscordLinkMenuItem); about_OpenDonationsPageMenuItem.addActionListener(this::actionEventOpenDonateMenuItem); - - help_OpenHelpWindowMenuItem.addActionListener(this::actionEventOpenHelpMenuItem); - - helpComboBoxModel = new DefaultComboBoxModel<>(HELPSELECTIONS); - helpComboBox = new JComboBox<>(helpComboBoxModel); - - helpComboBox.setSelectedIndex(0); - HELPTEXTAREA.setText(HELPTEXTS[0]); - - HELPPANEL.add(HELPTEXTAREA); - HELPPANEL.add(helpComboBox); - - helpComboBox.addActionListener(this::actionEventSetHelpText); + about_OpenWikiHelpMenuItem.addActionListener(this::actionEventOpenWikiHelpMenuItem); + about_OpenWikiHowToMenuItem.addActionListener(this::actionEventOpenWikiHowToMenuItem); // add items to menus fileMenu.add(file_NewConfigurationMenuItem); @@ -488,6 +401,8 @@ public class MenuBar extends Component { fileMenu.add(file_UploadConfigurationToHasteBin); fileMenu.add(file_UploadServerPackCreatorLogToHasteBin); fileMenu.add(new JSeparator()); + fileMenu.add(file_UpdateFallbackModslist); + fileMenu.add(new JSeparator()); fileMenu.add(file_ExitConfigMenuItem); editMenu.add(edit_ChangeJavaArgs); @@ -506,6 +421,9 @@ public class MenuBar extends Component { aboutMenu.add(about_OpenAboutWindowMenuItem); aboutMenu.add(new JSeparator()); + aboutMenu.add(about_OpenWikiHelpMenuItem); + aboutMenu.add(about_OpenWikiHowToMenuItem); + aboutMenu.add(new JSeparator()); aboutMenu.add(about_OpenGitHubPageMenuItem); aboutMenu.add(about_OpenGitHubIssuesPageMenuItem); aboutMenu.add(about_OpenReleasesPageMenuItem); @@ -519,11 +437,66 @@ public class MenuBar extends Component { MENUBAR.add(editMenu); MENUBAR.add(viewMenu); MENUBAR.add(aboutMenu); - MENUBAR.add(help_OpenHelpWindowMenuItem); return MENUBAR; } + private void actionEventUpdateFallbackModslist(ActionEvent actionEvent) { + LOG.debug("Running update check for fallback modslist..."); + if (APPLICATIONPROPERTIES.updateFallback()) { + JOptionPane.showMessageDialog( + FRAME_SERVERPACKCREATOR, + LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.updatefallback.updated"), + LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.updatefallback.title"), + JOptionPane.INFORMATION_MESSAGE + ); + } else { + JOptionPane.showMessageDialog( + FRAME_SERVERPACKCREATOR, + LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.updatefallback.nochange"), + LOCALIZATIONMANAGER.getLocalizedString("menubar.gui.menuitem.updatefallback.title"), + JOptionPane.INFORMATION_MESSAGE + ); + } + } + + /** + * Open the given url in a browser. + * @author Griefed + * @param uri {@link URI} the URI to the website you want to open. + */ + private void openLinkInBrowser(URI uri) { + try { + if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { + Desktop.getDesktop().browse(uri); + } + } catch (IOException ex) { + LOG.error("Error opening browser with link " + uri + ".", ex); + } + } + + /** + * Open the Help-section of the wiki in a browser. + * @author Griefed + * @param actionEvent The event which triggers this method. + */ + private void actionEventOpenWikiHelpMenuItem(ActionEvent actionEvent) { + LOG.debug("Clicked Help."); + + openLinkInBrowser(URI.create("https://wiki.griefed.de/en/Documentation/ServerPackCreator/ServerPackCreator-Help")); + } + + /** + * Open the HowTo-section of the wiki in a browser. + * @author Griefed + * @param actionEvent The event which triggers this method. + */ + private void actionEventOpenWikiHowToMenuItem(ActionEvent actionEvent) { + LOG.debug("Clicked Getting started."); + + openLinkInBrowser(URI.create("https://wiki.griefed.de/en/Documentation/ServerPackCreator/ServerPackCreator-HowTo")); + } + /** * Upon button-press, load default values for textfields so the user can start with a new configuration. Just as if ServerPackCreator * was started without a serverpackcreator.conf being present. @@ -544,13 +517,7 @@ public class MenuBar extends Component { private void actionEventOpenDiscordLinkMenuItem(ActionEvent actionEvent) { LOG.debug("Clicked Join Discord."); - try { - if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - Desktop.getDesktop().browse(URI.create("https://discord.griefed.de")); - } - } catch (IOException ex) { - LOG.error("Error opening browser.", ex); - } + openLinkInBrowser(URI.create("https://discord.griefed.de")); } /** @@ -561,13 +528,7 @@ public class MenuBar extends Component { private void actionEventOpenIssuesMenuItem(ActionEvent actionEvent) { LOG.debug("Clicked Open Issues page on GitHub."); - try { - if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - Desktop.getDesktop().browse(URI.create("https://github.com/Griefed/ServerPackCreator/issues")); - } - } catch (IOException ex) { - LOG.error("Error opening browser.", ex); - } + openLinkInBrowser(URI.create("https://github.com/Griefed/ServerPackCreator/issues")); } /** @@ -604,13 +565,8 @@ public class MenuBar extends Component { case 0: - try { - if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - Desktop.getDesktop().browse(URI.create(urltoHasteBin)); - } - } catch (IOException ex) { - LOG.error("Error opening browser.", ex); - } + openLinkInBrowser(URI.create(urltoHasteBin)); + break; case 1: @@ -660,13 +616,8 @@ public class MenuBar extends Component { case 0: - try { - if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - Desktop.getDesktop().browse(URI.create(urltoHasteBin)); - } - } catch (IOException ex) { - LOG.error("Error opening browser.", ex); - } + openLinkInBrowser(URI.create(urltoHasteBin)); + break; case 1: @@ -798,10 +749,8 @@ public class MenuBar extends Component { JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, - JAVAARGSOPTIONS, - JAVAARGSOPTIONS[3] - ) - ) { + JAVAARGSOPTIONS,JAVAARGSOPTIONS[3] + )) { case 0: if (JAVAARGS.getText().equals("")) { @@ -906,7 +855,7 @@ public class MenuBar extends Component { isDarkTheme = true; - try (OutputStream outputStream = new FileOutputStream(APPLICATIONPROPERTIES.FILE_SERVERPACKCREATOR_PROPERTIES)) { + try (OutputStream outputStream = Files.newOutputStream(APPLICATIONPROPERTIES.FILE_SERVERPACKCREATOR_PROPERTIES.toPath())) { APPLICATIONPROPERTIES.setProperty("de.griefed.serverpackcreator.gui.darkmode", String.valueOf(true)); APPLICATIONPROPERTIES.store(outputStream, null); @@ -929,7 +878,7 @@ public class MenuBar extends Component { isDarkTheme = false; - try (OutputStream outputStream = new FileOutputStream(APPLICATIONPROPERTIES.FILE_SERVERPACKCREATOR_PROPERTIES)) { + try (OutputStream outputStream = Files.newOutputStream(APPLICATIONPROPERTIES.FILE_SERVERPACKCREATOR_PROPERTIES.toPath())) { APPLICATIONPROPERTIES.setProperty("de.griefed.serverpackcreator.gui.darkmode", String.valueOf(false)); APPLICATIONPROPERTIES.store(outputStream, null); @@ -1014,13 +963,7 @@ public class MenuBar extends Component { private void actionEventViewExampleAddonMenuItem(ActionEvent actionEvent) { LOG.debug("Clicked view example addon"); - try { - if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - Desktop.getDesktop().browse(URI.create("https://github.com/Griefed/ServerPackCreatorExampleAddon")); - } - } catch (IOException ex) { - LOG.error("Error opening browser for example-addon repository.", ex); - } + openLinkInBrowser(URI.create("https://github.com/Griefed/ServerPackCreatorExampleAddon")); } /** @@ -1103,33 +1046,6 @@ public class MenuBar extends Component { ); } - /** - * Upon button-press, open an info-window containing information/help about how to configure ServerPackCreator. - * @author Griefed - * @param actionEvent The event which triggers this method. - */ - private void actionEventOpenHelpMenuItem(ActionEvent actionEvent) { - LOG.debug("Clicked open help window."); - - MATERIALCOMBOBOXUI.installUI(helpComboBox); - //materialPanelUI.installUI(helpPanel); - MATERIALTEXTFIELDUI.installUI(HELPTEXTAREA); - //materialTextPaneUI.installUI(helpWindowTextPane); - - JOptionPane.showMessageDialog( - FRAME_SERVERPACKCREATOR, - HELPPANEL, - LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createserverpack.help.title"), - JOptionPane.INFORMATION_MESSAGE, - HELPICON - ); - } - - private void actionEventSetHelpText(ActionEvent actionEvent) { - LOG.debug("Selected helpItem: " + helpComboBox.getSelectedIndex()); - HELPTEXTAREA.setText(HELPTEXTS[helpComboBox.getSelectedIndex()]); - } - /** * Upon button-press, open the ServerPackCreator repository GitHub page in the users default-browser. * @author Griefed @@ -1138,13 +1054,7 @@ public class MenuBar extends Component { private void actionEventOpenGitHubMenuItem(ActionEvent actionEvent) { LOG.debug("Clicked open GitHub repository link."); - try { - if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - Desktop.getDesktop().browse(URI.create("https://github.com/Griefed/ServerPackCreator")); - } - } catch (IOException ex) { - LOG.error("Error opening browser for ServerPackCreator GitHub repository.", ex); - } + openLinkInBrowser(URI.create("https://github.com/Griefed/ServerPackCreator")); } /** @@ -1155,13 +1065,7 @@ public class MenuBar extends Component { private void actionEventOpenDonateMenuItem(ActionEvent actionEvent) { LOG.debug("Clicked open donations link."); - try { - if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - Desktop.getDesktop().browse(URI.create("https://github.com/sponsors/Griefed")); - } - } catch (IOException ex) { - LOG.error("Error opening browser for donations page.", ex); - } + openLinkInBrowser(URI.create("https://github.com/sponsors/Griefed")); } /** @@ -1172,13 +1076,7 @@ public class MenuBar extends Component { private void actionEventOpenReleaseMenuItem(ActionEvent actionEvent) { LOG.debug("Clicked open releases link"); - try { - if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - Desktop.getDesktop().browse(URI.create("https://github.com/Griefed/ServerPackCreator/releases")); - } - } catch (IOException ex) { - LOG.error("Error opening browser for releases page.", ex); - } + openLinkInBrowser(URI.create("https://github.com/Griefed/ServerPackCreator/releases")); } /** diff --git a/backend/main/java/de/griefed/serverpackcreator/swing/SwingGuiInitializer.java b/backend/main/java/de/griefed/serverpackcreator/swing/SwingGuiInitializer.java index 8a6013f3b4599f09b2d493aca4632aecf482892d..180017c4a78a4d61ac5916ec4b31090ba7691eaa 100644 --- a/backend/main/java/de/griefed/serverpackcreator/swing/SwingGuiInitializer.java +++ b/backend/main/java/de/griefed/serverpackcreator/swing/SwingGuiInitializer.java @@ -22,12 +22,14 @@ package de.griefed.serverpackcreator.swing; import de.griefed.serverpackcreator.*; import de.griefed.serverpackcreator.curseforge.CurseCreateModpack; import de.griefed.serverpackcreator.i18n.LocalizationManager; -import de.griefed.serverpackcreator.plugins.swinggui.TabExtension; +import de.griefed.serverpackcreator.plugins.ApplicationPlugins; import de.griefed.serverpackcreator.swing.themes.DarkTheme; import de.griefed.serverpackcreator.swing.utilities.BackgroundPanel; import de.griefed.serverpackcreator.swing.themes.LightTheme; import de.griefed.serverpackcreator.utilities.*; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; import de.griefed.serverpackcreator.utilities.misc.Generated; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import mdlaf.MaterialLookAndFeel; import mdlaf.components.textpane.MaterialTextPaneUI; import org.apache.logging.log4j.LogManager; @@ -66,15 +68,12 @@ public class SwingGuiInitializer extends JPanel { private final ConfigurationHandler CONFIGURATIONHANDLER; private final CurseCreateModpack CURSECREATEMODPACK; private final ServerPackHandler CREATESERVERPACK; - private final VersionLister VERSIONLISTER; - private final BooleanUtilities BOOLEANUTILITIES; - private final ListUtilities LISTUTILITIES; - private final StringUtilities STRINGUTILITIES; - private final ConfigUtilities CONFIGUTILITIES; - private final SystemUtilities SYSTEMUTILITIES; + private final VersionMeta VERSIONMETA; + private final Utilities UTILITIES; private final ApplicationProperties APPLICATIONPROPERTIES; private final ApplicationPlugins APPLICATIONPLUGINS; private final UpdateChecker UPDATECHECKER; + private final ConfigUtilities CONFIGUTILITIES; private final LightTheme LIGHTTHEME = new LightTheme(); private final DarkTheme DARKTHEME = new DarkTheme(); @@ -113,21 +112,18 @@ public class SwingGuiInitializer extends JPanel { * CurseForge projectID and fileID, from which to <em>then</em> create the server pack. * @param injectedServerPackHandler Instance of {@link ServerPackHandler} required for the generation of server packs. * @param injectedApplicationProperties Instance of {@link Properties} required for various different things. - * @param injectedVersionLister Instance of {@link VersionLister} required for everything version related in the GUI. - * @param injectedBooleanUtilities Instance of {@link BooleanUtilities}. - * @param injectedListUtilities Instance of {@link ListUtilities}. - * @param injectedStringUtilities Instance of {@link StringUtilities}. - * @param injectedConfigUtilities Instance of {@link ConfigUtilities}. - * @param injectedSystemUtilities Instance of {@link SystemUtilities}. + * @param injectedVersionMeta Instance of {@link VersionMeta} required for everything version related in the GUI. + * @param injectedUtilities Instance of {@link Utilities}. * @param injectedUpdateChecker Instance of {@link UpdateChecker}. * @param injectedPluginManager Instance of {@link ApplicationPlugins}. + * @param injectedConfigUtilities Instance of {@link ConfigUtilities}. + * @throws IOException if the {@link VersionMeta} could not be instantiated. */ public SwingGuiInitializer(LocalizationManager injectedLocalizationManager, ConfigurationHandler injectedConfigurationHandler, CurseCreateModpack injectedCurseCreateModpack, ServerPackHandler injectedServerPackHandler, - ApplicationProperties injectedApplicationProperties, VersionLister injectedVersionLister, - BooleanUtilities injectedBooleanUtilities, ListUtilities injectedListUtilities, - StringUtilities injectedStringUtilities, ConfigUtilities injectedConfigUtilities, SystemUtilities injectedSystemUtilities, - UpdateChecker injectedUpdateChecker, ApplicationPlugins injectedPluginManager) { + ApplicationProperties injectedApplicationProperties, VersionMeta injectedVersionMeta, + Utilities injectedUtilities, UpdateChecker injectedUpdateChecker, ApplicationPlugins injectedPluginManager, + ConfigUtilities injectedConfigUtilities) throws IOException { super(new GridLayout(1, 1)); @@ -142,53 +138,34 @@ public class SwingGuiInitializer extends JPanel { this.LOCALIZATIONMANAGER = injectedLocalizationManager; } - if (injectedVersionLister == null) { - this.VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); - } else { - this.VERSIONLISTER = injectedVersionLister; - } - - if (injectedBooleanUtilities == null) { - this.BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + if (injectedVersionMeta == null) { + this.VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); } else { - this.BOOLEANUTILITIES = injectedBooleanUtilities; + this.VERSIONMETA = injectedVersionMeta; } - if (injectedListUtilities == null) { - this.LISTUTILITIES = new ListUtilities(); + if (injectedUtilities == null) { + this.UTILITIES = new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); } else { - this.LISTUTILITIES = injectedListUtilities; - } - - if (injectedStringUtilities == null) { - this.STRINGUTILITIES = new StringUtilities(); - } else { - this.STRINGUTILITIES = injectedStringUtilities; - } - - if (injectedSystemUtilities == null) { - this.SYSTEMUTILITIES = new SystemUtilities(); - } else { - this.SYSTEMUTILITIES = injectedSystemUtilities; + this.UTILITIES = injectedUtilities; } if (injectedConfigUtilities == null) { - this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, BOOLEANUTILITIES, LISTUTILITIES, - APPLICATIONPROPERTIES, STRINGUTILITIES, VERSIONLISTER); + this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, UTILITIES, APPLICATIONPROPERTIES, VERSIONMETA); } else { this.CONFIGUTILITIES = injectedConfigUtilities; } if (injectedConfigurationHandler == null) { - this.CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONLISTER, - BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES); + this.CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONMETA, + UTILITIES, CONFIGUTILITIES); } else { this.CURSECREATEMODPACK = injectedCurseCreateModpack; } if (injectedConfigurationHandler == null) { - this.CONFIGURATIONHANDLER = new ConfigurationHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONLISTER, - APPLICATIONPROPERTIES, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, SYSTEMUTILITIES, CONFIGUTILITIES); + this.CONFIGURATIONHANDLER = new ConfigurationHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONMETA, + APPLICATIONPROPERTIES, UTILITIES, CONFIGUTILITIES); } else { this.CONFIGURATIONHANDLER = injectedConfigurationHandler; } @@ -200,9 +177,8 @@ public class SwingGuiInitializer extends JPanel { } if (injectedServerPackHandler == null) { - this.CREATESERVERPACK = new ServerPackHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, CONFIGURATIONHANDLER, - APPLICATIONPROPERTIES, VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, SYSTEMUTILITIES, - CONFIGUTILITIES, APPLICATIONPLUGINS); + this.CREATESERVERPACK = new ServerPackHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, + APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES, APPLICATIONPLUGINS, CONFIGUTILITIES); } else { this.CREATESERVERPACK = injectedServerPackHandler; } @@ -222,9 +198,8 @@ public class SwingGuiInitializer extends JPanel { this.FRAME_SERVERPACKCREATOR = new JFrame(LOCALIZATIONMANAGER.getLocalizedString("createserverpack.gui.createandshowgui") + " - " + APPLICATIONPROPERTIES.getServerPackCreatorVersion()); this.TAB_CREATESERVERPACK = new TabCreateServerPack( - LOCALIZATIONMANAGER, CONFIGURATIONHANDLER, CURSECREATEMODPACK, CREATESERVERPACK, VERSIONLISTER, APPLICATIONPROPERTIES, - FRAME_SERVERPACKCREATOR, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES, - APPLICATIONPLUGINS + LOCALIZATIONMANAGER, CONFIGURATIONHANDLER, CURSECREATEMODPACK, CREATESERVERPACK, VERSIONMETA, APPLICATIONPROPERTIES, + FRAME_SERVERPACKCREATOR, UTILITIES, APPLICATIONPLUGINS, CONFIGUTILITIES ); this.TAB_LOG_SERVERPACKCREATOR = new TabServerPackCreatorLog( @@ -275,15 +250,15 @@ public class SwingGuiInitializer extends JPanel { TABBEDPANE.setMnemonicAt(3, KeyEvent.VK_4); - if (APPLICATIONPLUGINS.PLUGINS_TABBEDPANE.size() > 0) { - for (TabExtension pane : APPLICATIONPLUGINS.PLUGINS_TABBEDPANE) { - TABBEDPANE.addTab( - pane.getTabTitle(), - pane.getTabIcon(), - pane.getTab(), - pane.getTabTooltip() - ); - } + if (!APPLICATIONPLUGINS.pluginsTabExtension().isEmpty()) { + APPLICATIONPLUGINS.pluginsTabExtension().forEach(plugin -> + TABBEDPANE.addTab( + plugin.getTabTitle(), + plugin.getTabIcon(), + plugin.getTab(), + plugin.getTabTooltip() + ) + ); } else { LOG.info("No TabbedPane addons to add."); } @@ -365,7 +340,7 @@ public class SwingGuiInitializer extends JPanel { FRAME_SERVERPACKCREATOR.pack(); /* - * I know this looks stupid. Why update the tree if it isn't even visible yet? + * I know this looks stupid. Why initialize the tree if it isn't even visible yet? * Because otherwise, when switching from light to dark-theme, the inset for tabs of the tabbed pane suddenly * changes, which looks ugly. Calling this does the same, but before the GUI is visible. Dirty hack? Maybe. * Does it work? Yeah. @@ -380,7 +355,7 @@ public class SwingGuiInitializer extends JPanel { } /** - * If an update is available for ServerPackCreator, display a dialog asking the user whether + * If an initialize is available for ServerPackCreator, display a dialog asking the user whether * @author Griefed */ private void displayUpdateDialog() { diff --git a/backend/main/java/de/griefed/serverpackcreator/swing/TabCreateServerPack.java b/backend/main/java/de/griefed/serverpackcreator/swing/TabCreateServerPack.java index a0af142dc093465cda12f1351f1d2744f1206e3a..d15bd968a780b539d0ebd9872c8106b825436a2e 100644 --- a/backend/main/java/de/griefed/serverpackcreator/swing/TabCreateServerPack.java +++ b/backend/main/java/de/griefed/serverpackcreator/swing/TabCreateServerPack.java @@ -23,8 +23,12 @@ import com.electronwill.nightconfig.core.file.FileConfig; import de.griefed.serverpackcreator.*; import de.griefed.serverpackcreator.curseforge.CurseCreateModpack; import de.griefed.serverpackcreator.i18n.LocalizationManager; +import de.griefed.serverpackcreator.utilities.ConfigUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; +import de.griefed.serverpackcreator.plugins.ApplicationPlugins; import de.griefed.serverpackcreator.utilities.*; import de.griefed.serverpackcreator.utilities.misc.Generated; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import mdlaf.components.textpane.MaterialTextPaneUI; import org.apache.commons.io.FileUtils; import org.apache.commons.io.input.Tailer; @@ -70,14 +74,11 @@ public class TabCreateServerPack extends JComponent { private final LocalizationManager LOCALIZATIONMANAGER; private final ServerPackHandler CREATESERVERPACK; private final CurseCreateModpack CURSECREATEMODPACK; - private final VersionLister VERSIONLISTER; - private final BooleanUtilities BOOLEANUTILITIES; - private final ListUtilities LISTUTILITIES; - private final StringUtilities STRINGUTILITIES; - private final ConfigUtilities CONFIGUTILITIES; - private final SystemUtilities SYSTEMUTILITIES; + private final VersionMeta VERSIONMETA; + private final Utilities UTILITIES; private final ApplicationProperties APPLICATIONPROPERTIES; private final ApplicationPlugins APPLICATIONPLUGINS; + private final ConfigUtilities CONFIGUTILITIES; private final StyledDocument SERVERPACKGENERATEDDOCUMENT = new DefaultStyledDocument(); private final SimpleAttributeSet SERVERPACKGENERATEDATTRIBUTESET = new SimpleAttributeSet(); @@ -180,22 +181,19 @@ public class TabCreateServerPack extends JComponent { * @param injectedCurseCreateModpack Instance of {@link CurseCreateModpack} in case the modpack has to be created from a combination of * CurseForge projectID and fileID, from which to <em>then</em> create the server pack. * @param injectedServerPackHandler Instance of {@link ServerPackHandler} required for the generation of server packs. - * @param injectedVersionLister Instance of {@link VersionLister} required for setting/changing comboboxes. + * @param injectedVersionMeta Instance of {@link VersionMeta} required for setting/changing comboboxes. * @param injectedApplicationProperties Instance of {@link Properties} required for various different things. * @param injectedServerPackCreatorFrame Our parent frame which contains all of ServerPackCreator. - * @param injectedBooleanUtilities Instance of {@link BooleanUtilities}. - * @param injectedListUtilities Instance of {@link ListUtilities}. - * @param injectedStringUtilities Instance of {@link StringUtilities}. - * @param injectedConfigUtilities Instance of {@link ConfigUtilities}. - * @param injectedSystemUtilities Instance of {@link SystemUtilities}. + * @param injectedUtilities Instance of {@link Utilities}. * @param injectedPluginManager Instance of {@link ApplicationPlugins}. + * @param injectedConfigUtilities Instance of {@link ConfigUtilities}. + * @throws IOException if the {@link VersionMeta} could not be instantiated. */ public TabCreateServerPack(LocalizationManager injectedLocalizationManager, ConfigurationHandler injectedConfigurationHandler, CurseCreateModpack injectedCurseCreateModpack, ServerPackHandler injectedServerPackHandler, - VersionLister injectedVersionLister, ApplicationProperties injectedApplicationProperties, - JFrame injectedServerPackCreatorFrame, BooleanUtilities injectedBooleanUtilities, ListUtilities injectedListUtilities, - StringUtilities injectedStringUtilities, ConfigUtilities injectedConfigUtilities, SystemUtilities injectedSystemUtilities, - ApplicationPlugins injectedPluginManager) { + VersionMeta injectedVersionMeta, ApplicationProperties injectedApplicationProperties, + JFrame injectedServerPackCreatorFrame, Utilities injectedUtilities, ApplicationPlugins injectedPluginManager, + ConfigUtilities injectedConfigUtilities) throws IOException { if (injectedApplicationProperties == null) { this.APPLICATIONPROPERTIES = new ApplicationProperties(); @@ -209,28 +207,16 @@ public class TabCreateServerPack extends JComponent { this.LOCALIZATIONMANAGER = injectedLocalizationManager; } - if (injectedBooleanUtilities == null) { - this.BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + if (injectedVersionMeta == null) { + this.VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); } else { - this.BOOLEANUTILITIES = injectedBooleanUtilities; + this.VERSIONMETA = injectedVersionMeta; } - if (injectedListUtilities == null) { - this.LISTUTILITIES = new ListUtilities(); + if (injectedUtilities == null) { + this.UTILITIES = new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); } else { - this.LISTUTILITIES = injectedListUtilities; - } - - if (injectedStringUtilities == null) { - this.STRINGUTILITIES = new StringUtilities(); - } else { - this.STRINGUTILITIES = injectedStringUtilities; - } - - if (injectedSystemUtilities == null) { - this.SYSTEMUTILITIES = new SystemUtilities(); - } else { - this.SYSTEMUTILITIES = injectedSystemUtilities; + this.UTILITIES = injectedUtilities; } if (injectedPluginManager == null) { @@ -239,32 +225,26 @@ public class TabCreateServerPack extends JComponent { this.APPLICATIONPLUGINS = injectedPluginManager; } - if (injectedVersionLister == null) { - this.VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); - } else { - this.VERSIONLISTER = injectedVersionLister; - } - if (injectedConfigUtilities == null) { - this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, BOOLEANUTILITIES, LISTUTILITIES, APPLICATIONPROPERTIES, STRINGUTILITIES, VERSIONLISTER); + this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, UTILITIES, APPLICATIONPROPERTIES, VERSIONMETA); } else { this.CONFIGUTILITIES = injectedConfigUtilities; } if (injectedCurseCreateModpack == null) { - this.CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES); + this.CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES, CONFIGUTILITIES); } else { this.CURSECREATEMODPACK = injectedCurseCreateModpack; } if (injectedConfigurationHandler == null) { - this.CONFIGURATIONHANDLER = new ConfigurationHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONLISTER, APPLICATIONPROPERTIES, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, SYSTEMUTILITIES, CONFIGUTILITIES); + this.CONFIGURATIONHANDLER = new ConfigurationHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONMETA, APPLICATIONPROPERTIES, UTILITIES, CONFIGUTILITIES); } else { this.CONFIGURATIONHANDLER = injectedConfigurationHandler; } if (injectedServerPackHandler == null) { - this.CREATESERVERPACK = new ServerPackHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, CONFIGURATIONHANDLER, APPLICATIONPROPERTIES, VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, SYSTEMUTILITIES, CONFIGUTILITIES, APPLICATIONPLUGINS); + this.CREATESERVERPACK = new ServerPackHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES, APPLICATIONPLUGINS, CONFIGUTILITIES); } else { this.CREATESERVERPACK = injectedServerPackHandler; } @@ -543,7 +523,7 @@ public class TabCreateServerPack extends JComponent { CREATESERVERPACKPANEL.add(labelMinecraftVersion, GRIDBAGCONSTRAINTS); - COMBOBOX_MINECRAFTVERSIONS.setModel(new DefaultComboBoxModel<>(VERSIONLISTER.getMinecraftReleaseVersionsAsArray())); + COMBOBOX_MINECRAFTVERSIONS.setModel(new DefaultComboBoxModel<>(VERSIONMETA.minecraft().releaseVersionsArrayDescending())); COMBOBOX_MINECRAFTVERSIONS.setSelectedIndex(0); COMBOBOX_MINECRAFTVERSIONS.addActionListener(this::actionEventComboBoxMinecraftVersion); @@ -602,12 +582,12 @@ public class TabCreateServerPack extends JComponent { CREATESERVERPACKPANEL.add(labelModloaderVersion, GRIDBAGCONSTRAINTS); - COMBOBOX_FABRICVERSIONS.setModel(new DefaultComboBoxModel<>(VERSIONLISTER.reverseOrderArray(VERSIONLISTER.getFabricVersionsAsArray()))); + COMBOBOX_FABRICVERSIONS.setModel(new DefaultComboBoxModel<>(VERSIONMETA.fabric().loaderVersionsArrayDescending())); COMBOBOX_FABRICVERSIONS.setSelectedIndex(0); COMBOBOX_FABRICVERSIONS.addActionListener(this::actionEventComboBoxFabricVersions); COMBOBOX_FABRICVERSIONS.setVisible(false); - forgeComboBoxModel = new DefaultComboBoxModel<>(VERSIONLISTER.getForgeMeta().get(Objects.requireNonNull(COMBOBOX_MINECRAFTVERSIONS.getSelectedItem()).toString())); + forgeComboBoxModel = new DefaultComboBoxModel<>(VERSIONMETA.forge().availableForgeVersionsArrayDescending(COMBOBOX_MINECRAFTVERSIONS.getSelectedItem().toString()).get()); COMBOBOX_FORGEVERSIONS.setModel(forgeComboBoxModel); COMBOBOX_FORGEVERSIONS.setSelectedIndex(0); @@ -865,7 +845,7 @@ public class TabCreateServerPack extends JComponent { */ void changeForgeVersionListDependingOnMinecraftVersion(String chosenMinecraftVersion) { - forgeComboBoxModel = new DefaultComboBoxModel<>(VERSIONLISTER.getForgeMeta().get(chosenMinecraftVersion)); + forgeComboBoxModel = new DefaultComboBoxModel<>(VERSIONMETA.forge().availableForgeVersionsArrayDescending(chosenMinecraftVersion).get()); COMBOBOX_FORGEVERSIONS.setModel(forgeComboBoxModel); COMBOBOX_FORGEVERSIONS.setSelectedIndex(0); @@ -1098,7 +1078,7 @@ public class TabCreateServerPack extends JComponent { } TEXTFIELD_CLIENTSIDEMODS.setText( - STRINGUTILITIES.buildString( + UTILITIES.StringUtils().buildString( Arrays.toString( clientModsFilenames.toArray(new String[0]))) ); @@ -1139,7 +1119,7 @@ public class TabCreateServerPack extends JComponent { copyDirsNames.add(directory.getName()); } - TEXTFIELD_COPYDIRECTORIES.setText(STRINGUTILITIES.buildString(Arrays.toString(copyDirsNames.toArray(new String[0])))); + TEXTFIELD_COPYDIRECTORIES.setText(UTILITIES.StringUtils().buildString(Arrays.toString(copyDirsNames.toArray(new String[0])))); LOG.debug("Selected directories: " + copyDirsNames); } @@ -1355,8 +1335,8 @@ public class TabCreateServerPack extends JComponent { javaArgs = "empty"; } - List<String> tempClientMods = LISTUTILITIES.cleanList(new ArrayList<>(Arrays.asList(TEXTFIELD_CLIENTSIDEMODS.getText().replace(", ", ",").split(",")))); - List<String> tempCopyDirs = LISTUTILITIES.cleanList(new ArrayList<>(Arrays.asList(TEXTFIELD_COPYDIRECTORIES.getText().replace(", ", ",").split(",")))); + List<String> tempClientMods = UTILITIES.ListUtils().cleanList(new ArrayList<>(Arrays.asList(TEXTFIELD_CLIENTSIDEMODS.getText().replace(", ", ",").split(",")))); + List<String> tempCopyDirs = UTILITIES.ListUtils().cleanList(new ArrayList<>(Arrays.asList(TEXTFIELD_COPYDIRECTORIES.getText().replace(", ", ",").split(",")))); CONFIGUTILITIES.writeConfigToFile( TEXTFIELD_MODPACKDIRECTORY.getText().replace("\\","/"), @@ -1373,7 +1353,7 @@ public class TabCreateServerPack extends JComponent { checkBoxProperties.isSelected(), checkBoxZIP.isSelected(), getJavaArgs(), - STRINGUTILITIES.pathSecureText(TEXTFIELD_SERVERPACKSUFFIX.getText()), + UTILITIES.StringUtils().pathSecureText(TEXTFIELD_SERVERPACKSUFFIX.getText()), configFile ); } @@ -1402,16 +1382,16 @@ public class TabCreateServerPack extends JComponent { if (config.getOrElse("clientMods", APPLICATIONPROPERTIES.getListFallbackMods()).isEmpty()) { - TEXTFIELD_CLIENTSIDEMODS.setText(STRINGUTILITIES.buildString(APPLICATIONPROPERTIES.getListFallbackMods().toString())); + TEXTFIELD_CLIENTSIDEMODS.setText(UTILITIES.StringUtils().buildString(APPLICATIONPROPERTIES.getListFallbackMods().toString())); LOG.debug("Set clientMods with fallback list."); } else { try { - TEXTFIELD_CLIENTSIDEMODS.setText(STRINGUTILITIES.buildString(config.get("clientMods").toString())); + TEXTFIELD_CLIENTSIDEMODS.setText(UTILITIES.StringUtils().buildString(config.get("clientMods").toString())); } catch (Exception ex) { LOG.error("Couldn't parse clientMods. Using fallback.",ex); - TEXTFIELD_CLIENTSIDEMODS.setText(STRINGUTILITIES.buildString(APPLICATIONPROPERTIES.getListFallbackMods().toString())); + TEXTFIELD_CLIENTSIDEMODS.setText(UTILITIES.StringUtils().buildString(APPLICATIONPROPERTIES.getListFallbackMods().toString())); } } @@ -1423,7 +1403,7 @@ public class TabCreateServerPack extends JComponent { } else { try { - TEXTFIELD_COPYDIRECTORIES.setText(STRINGUTILITIES.buildString(config.get("copyDirs").toString().replace("\\", "/"))); + TEXTFIELD_COPYDIRECTORIES.setText(UTILITIES.StringUtils().buildString(config.get("copyDirs").toString().replace("\\", "/"))); } catch (Exception ex) { LOG.error("Couldn't parse copyDirs. Using fallback.",ex); TEXTFIELD_COPYDIRECTORIES.setText("config, mods"); @@ -1435,7 +1415,7 @@ public class TabCreateServerPack extends JComponent { TEXTFIELD_SERVERPROPERTIESPATH.setText(config.getOrElse("serverPropertiesPath","").replace("\\","/")); - TEXTFIELD_JAVAPATH.setText(SYSTEMUTILITIES.acquireJavaPathFromSystem()); + TEXTFIELD_JAVAPATH.setText(UTILITIES.SystemUtils().acquireJavaPathFromSystem()); try { @@ -1443,18 +1423,16 @@ public class TabCreateServerPack extends JComponent { if (!config.getOrElse("minecraftVersion","").equals("")) { chosenMinecraftVersion = config.get("minecraftVersion"); } else { - chosenMinecraftVersion = VERSIONLISTER.getMinecraftReleaseVersion(); + chosenMinecraftVersion = VERSIONMETA.minecraft().latestRelease().version(); } } catch (NullPointerException ignored) { - chosenMinecraftVersion = VERSIONLISTER.getMinecraftReleaseVersion(); + chosenMinecraftVersion = VERSIONMETA.minecraft().latestRelease().version(); } - String[] mcver = VERSIONLISTER.getMinecraftReleaseVersionsAsArray(); + for (int i = 0; i < VERSIONMETA.minecraft().releaseVersionsArrayDescending().length; i++) { - for (int i = 0; i < mcver.length; i++) { - - if (mcver[i].equals(chosenMinecraftVersion)) { + if (VERSIONMETA.minecraft().releaseVersionsArrayDescending()[i].equals(chosenMinecraftVersion)) { COMBOBOX_MINECRAFTVERSIONS.setSelectedIndex(i); break; @@ -1463,29 +1441,29 @@ public class TabCreateServerPack extends JComponent { } catch (NullPointerException ex) { LOG.error("Error parsing minecraft-version from configfile: " + configFile, ex); - chosenMinecraftVersion = VERSIONLISTER.getMinecraftReleaseVersion(); + chosenMinecraftVersion = VERSIONMETA.minecraft().latestRelease().version(); } // Set modloader and modloader version try { + String modloaderVersion = config.getOrElse("modLoaderVersion",""); + // Check for Fabric if (config.getOrElse("modLoader","Forge").equalsIgnoreCase("Fabric")) { - String[] fabricver = VERSIONLISTER.reverseOrderArray(VERSIONLISTER.getFabricVersionsAsArray()); - updateModloaderGuiComponents(true, false, "Fabric"); - if (!config.getOrElse("modLoaderVersion","").equals("")) { + if (!modloaderVersion.equals("")) { // Go through all Fabric versions and check if specified version matches official version list - for (int i = 0; i < fabricver.length; i++) { + for (int i = 0; i < VERSIONMETA.fabric().loaderVersionsArrayDescending().length; i++) { // If match is found, set selected version - if (fabricver[i].equals(config.get("modLoaderVersion").toString())) { + if (VERSIONMETA.fabric().loaderVersionsArrayDescending()[i].equals(modloaderVersion)) { COMBOBOX_FABRICVERSIONS.setSelectedIndex(i); - chosenFabricVersion = config.get("modLoaderVersion").toString(); + chosenFabricVersion = modloaderVersion; } @@ -1496,20 +1474,20 @@ public class TabCreateServerPack extends JComponent { // If not Fabric, then assume Forge } else { - String[] forgever = VERSIONLISTER.getForgeMeta().get(chosenMinecraftVersion); + String[] forgever = VERSIONMETA.forge().availableForgeVersionsArrayDescending(chosenMinecraftVersion).get(); changeForgeVersionListDependingOnMinecraftVersion(chosenMinecraftVersion); updateModloaderGuiComponents(false, true, "Forge"); - if (!config.getOrElse("modLoaderVersion","").equals("")) { + if (!modloaderVersion.equals("")) { for (int i = 0; i < forgever.length; i++) { - if (forgever[i].equals(config.get("modLoaderVersion").toString())) { + if (forgever[i].equals(modloaderVersion)) { COMBOBOX_FORGEVERSIONS.setSelectedIndex(i); - chosenForgeVersion = config.get("modLoaderVersion").toString(); + chosenForgeVersion = modloaderVersion; } } @@ -1526,17 +1504,17 @@ public class TabCreateServerPack extends JComponent { changeForgeVersionListDependingOnMinecraftVersion(Objects.requireNonNull(COMBOBOX_MINECRAFTVERSIONS.getSelectedItem()).toString()); } - checkBoxServer.setSelected(BOOLEANUTILITIES.convertToBoolean(String.valueOf(config.getOrElse("includeServerInstallation","False")))); + checkBoxServer.setSelected(UTILITIES.BooleanUtils().convertToBoolean(String.valueOf(config.getOrElse("includeServerInstallation","False")))); - checkBoxIcon.setSelected(BOOLEANUTILITIES.convertToBoolean(String.valueOf(config.getOrElse("includeServerIcon", "False")))); + checkBoxIcon.setSelected(UTILITIES.BooleanUtils().convertToBoolean(String.valueOf(config.getOrElse("includeServerIcon", "False")))); - checkBoxProperties.setSelected(BOOLEANUTILITIES.convertToBoolean(String.valueOf(config.getOrElse("includeServerProperties", "False")))); + checkBoxProperties.setSelected(UTILITIES.BooleanUtils().convertToBoolean(String.valueOf(config.getOrElse("includeServerProperties", "False")))); - checkBoxZIP.setSelected(BOOLEANUTILITIES.convertToBoolean(String.valueOf(config.getOrElse("includeZipCreation","False")))); + checkBoxZIP.setSelected(UTILITIES.BooleanUtils().convertToBoolean(String.valueOf(config.getOrElse("includeZipCreation","False")))); setJavaArgs(config.getOrElse("javaArgs","empty")); - TEXTFIELD_SERVERPACKSUFFIX.setText(STRINGUTILITIES.pathSecureText(config.getOrElse("serverPackSuffix",""))); + TEXTFIELD_SERVERPACKSUFFIX.setText(UTILITIES.StringUtils().pathSecureText(config.getOrElse("serverPackSuffix",""))); } catch (NullPointerException ex) { @@ -1570,16 +1548,16 @@ public class TabCreateServerPack extends JComponent { protected void clearInterface() { TEXTFIELD_MODPACKDIRECTORY.setText(""); TEXTFIELD_SERVERPACKSUFFIX.setText(""); - TEXTFIELD_CLIENTSIDEMODS.setText(STRINGUTILITIES.buildString(APPLICATIONPROPERTIES.getListFallbackMods().toString())); + TEXTFIELD_CLIENTSIDEMODS.setText(UTILITIES.StringUtils().buildString(APPLICATIONPROPERTIES.getListFallbackMods().toString())); TEXTFIELD_COPYDIRECTORIES.setText(""); TEXTFIELD_SERVERICONPATH.setText(""); TEXTFIELD_SERVERPROPERTIESPATH.setText(""); - TEXTFIELD_JAVAPATH.setText(SYSTEMUTILITIES.acquireJavaPathFromSystem()); + TEXTFIELD_JAVAPATH.setText(UTILITIES.SystemUtils().acquireJavaPathFromSystem()); + + String minecraftVersion = VERSIONMETA.minecraft().latestRelease().version(); - String minecraftVersion = VERSIONLISTER.getMinecraftReleaseVersion(); - String[] mcver = VERSIONLISTER.getMinecraftReleaseVersionsAsArray(); - for (int i = 0; i < mcver.length; i++) { - if (mcver[i].equals(minecraftVersion)) { + for (int i = 0; i < VERSIONMETA.minecraft().releaseVersionsArrayDescending().length; i++) { + if (VERSIONMETA.minecraft().releaseVersionsArrayDescending()[i].equals(minecraftVersion)) { COMBOBOX_MINECRAFTVERSIONS.setSelectedIndex(i); chosenMinecraftVersion = minecraftVersion; } diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/ConfigUtilities.java b/backend/main/java/de/griefed/serverpackcreator/utilities/ConfigUtilities.java index 6f0d1150a59f66854ed52abc2c1690df1d1f92d9..3ee58cca3df2e2cba28134f15c3603d547f89a78 100644 --- a/backend/main/java/de/griefed/serverpackcreator/utilities/ConfigUtilities.java +++ b/backend/main/java/de/griefed/serverpackcreator/utilities/ConfigUtilities.java @@ -24,8 +24,12 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import de.griefed.serverpackcreator.ApplicationProperties; import de.griefed.serverpackcreator.ConfigurationModel; -import de.griefed.serverpackcreator.VersionLister; import de.griefed.serverpackcreator.i18n.LocalizationManager; +import de.griefed.serverpackcreator.utilities.commonutilities.BooleanUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.ListUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.StringUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -48,16 +52,13 @@ public class ConfigUtilities { private static final Logger LOG = LogManager.getLogger(ConfigUtilities.class); private final LocalizationManager LOCALIZATIONMANAGER; - private final BooleanUtilities BOOLEANUTILITIES; - private final ListUtilities LISTUTILITIES; - private final StringUtilities STRINGUTILITIES; + private final Utilities UTILITIES; private final ApplicationProperties APPLICATIONPROPERTIES; - private final VersionLister VERSIONLISTER; + private final VersionMeta VERSIONMETA; @Autowired - public ConfigUtilities(LocalizationManager injectedLocalizationManager, BooleanUtilities injectedBooleanUtilities, - ListUtilities injectedListUtilities, ApplicationProperties injectedApplicationProperties, - StringUtilities injectedStringUtilities, VersionLister injectedVersionLister) { + public ConfigUtilities(LocalizationManager injectedLocalizationManager, Utilities injectedUtilities, ApplicationProperties injectedApplicationProperties, + VersionMeta injectedVersionMeta) throws IOException { if (injectedApplicationProperties == null) { this.APPLICATIONPROPERTIES = new ApplicationProperties(); @@ -71,28 +72,16 @@ public class ConfigUtilities { this.LOCALIZATIONMANAGER = injectedLocalizationManager; } - if (injectedBooleanUtilities == null) { - this.BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + if (injectedUtilities == null) { + this.UTILITIES = new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); } else { - this.BOOLEANUTILITIES = injectedBooleanUtilities; + this.UTILITIES = injectedUtilities; } - if (injectedListUtilities == null) { - this.LISTUTILITIES = new ListUtilities(); + if (injectedVersionMeta == null) { + this.VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); } else { - this.LISTUTILITIES = injectedListUtilities; - } - - if (injectedStringUtilities == null) { - this.STRINGUTILITIES = new StringUtilities(); - } else { - this.STRINGUTILITIES = injectedStringUtilities; - } - - if (injectedVersionLister == null) { - this.VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); - } else { - this.VERSIONLISTER = injectedVersionLister; + this.VERSIONMETA = injectedVersionMeta; } } @@ -220,8 +209,8 @@ public class ConfigUtilities { "%s\njavaArgs = \"%s\"\n\n" + "%s\nserverPackSuffix = \"%s\"", LOCALIZATIONMANAGER.getLocalizedString("configuration.writeconfigtofile.modpackdir"), modpackDir.replace("\\","/"), - LOCALIZATIONMANAGER.getLocalizedString("configuration.writeconfigtofile.clientmods"), LISTUTILITIES.encapsulateListElements(LISTUTILITIES.cleanList(clientMods)), - LOCALIZATIONMANAGER.getLocalizedString("configuration.writeconfigtofile.copydirs"), LISTUTILITIES.encapsulateListElements(LISTUTILITIES.cleanList(copyDirs)), + LOCALIZATIONMANAGER.getLocalizedString("configuration.writeconfigtofile.clientmods"), UTILITIES.ListUtils().encapsulateListElements(UTILITIES.ListUtils().cleanList(clientMods)), + LOCALIZATIONMANAGER.getLocalizedString("configuration.writeconfigtofile.copydirs"), UTILITIES.ListUtils().encapsulateListElements(UTILITIES.ListUtils().cleanList(copyDirs)), LOCALIZATIONMANAGER.getLocalizedString("configuration.writeconfigtofile.custom.icon"), serverIconPath, LOCALIZATIONMANAGER.getLocalizedString("configuration.writeconfigtofile.custom.properties"), serverPropertiesPath, LOCALIZATIONMANAGER.getLocalizedString("configuration.writeconfigtofile.includeserverinstallation"), includeServer, @@ -279,8 +268,8 @@ public class ConfigUtilities { List<String> configurationAsList = new ArrayList<>(100); configurationAsList.add(configurationModel.getModpackDir()); - configurationAsList.add(STRINGUTILITIES.buildString(configurationModel.getClientMods().toString())); - configurationAsList.add(STRINGUTILITIES.buildString(configurationModel.getCopyDirs().toString())); + configurationAsList.add(UTILITIES.StringUtils().buildString(configurationModel.getClientMods().toString())); + configurationAsList.add(UTILITIES.StringUtils().buildString(configurationModel.getCopyDirs().toString())); configurationAsList.add(configurationModel.getJavaPath()); configurationAsList.add(configurationModel.getMinecraftVersion()); configurationAsList.add(configurationModel.getModLoader()); @@ -437,7 +426,7 @@ public class ConfigUtilities { LOG.debug(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.debug.modloader.forge")); configurationModel.setModLoader("Fabric"); - configurationModel.setModLoaderVersion(VERSIONLISTER.getFabricReleaseVersion()); + configurationModel.setModLoaderVersion(VERSIONMETA.fabric().releaseLoaderVersion()); } @@ -705,8 +694,10 @@ public class ConfigUtilities { if (directories.isEmpty()) { - ZipFile zipFile = new ZipFile(zipURI.toString()); - Enumeration<? extends ZipEntry> entries = zipFile.entries(); + Enumeration<? extends ZipEntry> entries; + try (ZipFile zipFile = new ZipFile(zipURI.toString())) { + entries = zipFile.entries(); + } while(entries.hasMoreElements()) { ZipEntry zipEntry = entries.nextElement(); diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/ConfigurationCreator.java b/backend/main/java/de/griefed/serverpackcreator/utilities/ConfigurationCreator.java index bfe6730cf730df1210b5d1407956cd8533cd621d..b890c7b48190a6525c4e80ab5956e8ec51591c8a 100644 --- a/backend/main/java/de/griefed/serverpackcreator/utilities/ConfigurationCreator.java +++ b/backend/main/java/de/griefed/serverpackcreator/utilities/ConfigurationCreator.java @@ -21,14 +21,16 @@ package de.griefed.serverpackcreator.utilities; import de.griefed.serverpackcreator.ApplicationProperties; import de.griefed.serverpackcreator.ConfigurationHandler; -import de.griefed.serverpackcreator.VersionLister; import de.griefed.serverpackcreator.curseforge.CurseCreateModpack; import de.griefed.serverpackcreator.i18n.LocalizationManager; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; import de.griefed.serverpackcreator.utilities.misc.Generated; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.File; +import java.io.IOException; import java.util.*; /** @@ -42,20 +44,14 @@ public class ConfigurationCreator { private final LocalizationManager LOCALIZATIONMANAGER; private final ConfigurationHandler CONFIGURATIONHANDLER; - private final BooleanUtilities BOOLEANUTILITIES; private final ApplicationProperties APPLICATIONPROPERTIES; - private final ListUtilities LISTUTILITIES; - private final StringUtilities STRINGUTILITIES; + private final VersionMeta VERSIONMETA; + private final Utilities UTILITIES; private final ConfigUtilities CONFIGUTILITIES; - private final SystemUtilities SYSTEMUTILITIES; - private final CurseCreateModpack CURSECREATEMODPACK; - private final VersionLister VERSIONLISTER; public ConfigurationCreator(LocalizationManager injectedLocalizationManager, ConfigurationHandler injectedConfigurationHandler, - BooleanUtilities injectedBooleanUtilities, ApplicationProperties injectedApplicationProperties, - ListUtilities injectedListUtilities, StringUtilities injectedStringUtilities, ConfigUtilities injectedConfigUtilities, - SystemUtilities injectedSystemUtilities, CurseCreateModpack injectedCurseCreateModpack, - VersionLister injectedVersionLister) { + ApplicationProperties injectedApplicationProperties, Utilities injectedUtilities, CurseCreateModpack injectedCurseCreateModpack, + VersionMeta injectedVersionMeta, ConfigUtilities injectedConfigUtilities) throws IOException { if (injectedApplicationProperties == null) { this.APPLICATIONPROPERTIES = new ApplicationProperties(); @@ -69,50 +65,33 @@ public class ConfigurationCreator { this.LOCALIZATIONMANAGER = injectedLocalizationManager; } - if (injectedBooleanUtilities == null) { - this.BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + if (injectedVersionMeta == null) { + this.VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); } else { - this.BOOLEANUTILITIES = injectedBooleanUtilities; + this.VERSIONMETA = injectedVersionMeta; } - if (injectedListUtilities == null) { - this.LISTUTILITIES = new ListUtilities(); + if (injectedUtilities == null) { + this.UTILITIES = new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); } else { - this.LISTUTILITIES = injectedListUtilities; - } - - if (injectedStringUtilities == null) { - this.STRINGUTILITIES = new StringUtilities(); - } else { - this.STRINGUTILITIES = injectedStringUtilities; - } - - if (injectedSystemUtilities == null) { - this.SYSTEMUTILITIES = new SystemUtilities(); - } else { - this.SYSTEMUTILITIES = injectedSystemUtilities; - } - - if (injectedVersionLister == null) { - this.VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); - } else { - this.VERSIONLISTER = injectedVersionLister; + this.UTILITIES = injectedUtilities; } if (injectedConfigUtilities == null) { - this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, BOOLEANUTILITIES, LISTUTILITIES, APPLICATIONPROPERTIES, STRINGUTILITIES, VERSIONLISTER); + this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, UTILITIES, APPLICATIONPROPERTIES, VERSIONMETA); } else { this.CONFIGUTILITIES = injectedConfigUtilities; } + CurseCreateModpack CURSECREATEMODPACK; if (injectedCurseCreateModpack == null) { - this.CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES); + CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES, CONFIGUTILITIES); } else { - this.CURSECREATEMODPACK = injectedCurseCreateModpack; + CURSECREATEMODPACK = injectedCurseCreateModpack; } if (injectedConfigurationHandler == null) { - this.CONFIGURATIONHANDLER = new ConfigurationHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONLISTER, APPLICATIONPROPERTIES, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, SYSTEMUTILITIES, CONFIGUTILITIES); + this.CONFIGURATIONHANDLER = new ConfigurationHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONMETA, APPLICATIONPROPERTIES, UTILITIES, CONFIGUTILITIES); } else { this.CONFIGURATIONHANDLER = injectedConfigurationHandler; } @@ -183,7 +162,7 @@ public class ConfigurationCreator { System.out.print(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.answer") + " "); - } while (!BOOLEANUTILITIES.readBoolean()); + } while (!UTILITIES.BooleanUtils().readBoolean()); modpackDir = tmpModpackDir.replace("\\", "/"); /* This log is meant to be read by the user, therefore we allow translation. */ @@ -196,7 +175,7 @@ public class ConfigurationCreator { do { clientMods.clear(); - clientMods.addAll(LISTUTILITIES.readStringArray()); + clientMods.addAll(UTILITIES.ListUtils().readStringArray()); /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(String.format(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.checkreturn"), clientMods)); @@ -217,7 +196,7 @@ public class ConfigurationCreator { System.out.print(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.answer") + " "); - } while (!BOOLEANUTILITIES.readBoolean()); + } while (!UTILITIES.BooleanUtils().readBoolean()); /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(String.format(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.checkreturn"), clientMods)); @@ -240,7 +219,7 @@ public class ConfigurationCreator { copyDirs.clear(); /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.copydirs.specify")); - copyDirs.addAll(LISTUTILITIES.readStringArray()); + copyDirs.addAll(UTILITIES.ListUtils().readStringArray()); } while (!CONFIGURATIONHANDLER.checkCopyDirs(copyDirs, modpackDir, encounteredErrors)); @@ -250,7 +229,7 @@ public class ConfigurationCreator { System.out.print(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.answer") + " "); - } while (!BOOLEANUTILITIES.readBoolean()); + } while (!UTILITIES.BooleanUtils().readBoolean()); /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(String.format(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.checkreturn"), copyDirs)); @@ -279,7 +258,7 @@ public class ConfigurationCreator { System.out.print(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.answer") + " "); - } while (!BOOLEANUTILITIES.readBoolean()); + } while (!UTILITIES.BooleanUtils().readBoolean()); serverIconPath = tmpServerIcon.replace("\\", "/"); /* This log is meant to be read by the user, therefore we allow translation. */ @@ -304,7 +283,7 @@ public class ConfigurationCreator { System.out.print(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.answer") + " "); - } while (!BOOLEANUTILITIES.readBoolean()); + } while (!UTILITIES.BooleanUtils().readBoolean()); serverPropertiesPath = tmpServerProperties.replace("\\", "/"); /* This log is meant to be read by the user, therefore we allow translation. */ @@ -316,7 +295,7 @@ public class ConfigurationCreator { LOG.info(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.server.enter")); System.out.print(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.server.include") + " "); - includeServerInstallation = BOOLEANUTILITIES.readBoolean(); + includeServerInstallation = UTILITIES.BooleanUtils().readBoolean(); /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(String.format(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.checkreturn"), includeServerInstallation)); @@ -329,7 +308,7 @@ public class ConfigurationCreator { System.out.print(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.minecraft.specify") + " "); minecraftVersion = reader.nextLine(); - } while (!CONFIGURATIONHANDLER.isMinecraftVersionCorrect(minecraftVersion)); + } while (!VERSIONMETA.minecraft().checkMinecraftVersion(minecraftVersion)); /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(String.format(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.checkreturn"), minecraftVersion)); @@ -387,7 +366,7 @@ public class ConfigurationCreator { LOG.info(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.icon.enter")); System.out.print(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.icon.cli") + " "); - includeServerIcon = BOOLEANUTILITIES.readBoolean(); + includeServerIcon = UTILITIES.BooleanUtils().readBoolean(); /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(String.format(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.checkreturn"), includeServerIcon)); @@ -398,7 +377,7 @@ public class ConfigurationCreator { LOG.info(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.properties.enter")); System.out.print(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.properties.cli") + " "); - includeServerProperties = BOOLEANUTILITIES.readBoolean(); + includeServerProperties = UTILITIES.BooleanUtils().readBoolean(); /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(String.format(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.checkreturn"), includeServerProperties)); @@ -409,7 +388,7 @@ public class ConfigurationCreator { LOG.info(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.zip.enter")); System.out.print(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.zip.cli") + " "); - includeZipCreation = BOOLEANUTILITIES.readBoolean(); + includeZipCreation = UTILITIES.BooleanUtils().readBoolean(); /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(String.format(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.checkreturn"), includeZipCreation)); @@ -456,7 +435,7 @@ public class ConfigurationCreator { System.out.print(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.answer") + " "); - } while (!BOOLEANUTILITIES.readBoolean()); + } while (!UTILITIES.BooleanUtils().readBoolean()); reader.close(); diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/SystemUtilities.java b/backend/main/java/de/griefed/serverpackcreator/utilities/SystemUtilities.java deleted file mode 100644 index 58b69b62a0f75dcf9dccb0afcd6b47223ed00675..0000000000000000000000000000000000000000 --- a/backend/main/java/de/griefed/serverpackcreator/utilities/SystemUtilities.java +++ /dev/null @@ -1,193 +0,0 @@ -/* Copyright (C) 2022 Griefed - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - * - * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE - */ -package de.griefed.serverpackcreator.utilities; - -import net.lingala.zip4j.ZipFile; -import net.lingala.zip4j.exception.ZipException; -import org.apache.commons.io.FileUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.FileChannel; -import java.nio.channels.ReadableByteChannel; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Utility-class revolving around the system we are running on. - * @author Griefed - */ -@Component -public class SystemUtilities { - - private static final Logger LOG = LogManager.getLogger(SystemUtilities.class); - - private final List<String> DRIVES = new ArrayList<>(Arrays.asList( - "A:","B:","C:","D:","E:","F:","G:","H:","I:","J:","K:","L:","M:","N:","O:","P:","Q:","R:","S:","T:","U:","V:","W:","X:","Y:","Z:" - )); - - @Autowired - public SystemUtilities() { - - } - - /** - * Automatically acquire the path to the systems default Java installation. - * @author Griefed - * @return String. The path to the systems default Java installation. - */ - public String acquireJavaPathFromSystem() { - - LOG.debug("Acquiring path to Java installation from system properties..."); - - String javaPath = "Couldn't acquire JavaPath"; - - if (new File(System.getProperty("java.home")).exists()) { - javaPath = String.format("%s/bin/java",System.getProperty("java.home").replace("\\", "/")); - - if (!javaPath.startsWith("/")) { - for (String letter : DRIVES) { - if (javaPath.startsWith(letter)) { - - LOG.debug("We're running on Windows. Ensuring javaPath ends with .exe"); - javaPath = String.format("%s.exe", javaPath); - } - } - } - } - - return javaPath; - } - - /** - * Download the file from the specified URL to the specified destination. The destination should end in a valid filename. - * Any directories up to the specified file will be created. - * @author Griefed - * @param fileDestination String. The destination where the file should be stored. Must include the filename as well. - * Examples:<br>/tmp/some_folder/foo.bar<br>C:/temp/some_folder/bar.foo - * @param downloadURL URL. The URL to the file you want to download. - * @return Boolean. Returns true if the file could be found on the hosts filesystem. - */ - public boolean downloadFile(String fileDestination, URL downloadURL) { - - try { - FileUtils.createParentDirectories(new File(fileDestination)); - } catch (IOException ignored) { - - } - - ReadableByteChannel readableByteChannel = null; - FileOutputStream fileOutputStream = null; - FileChannel fileChannel = null; - - try { - - readableByteChannel = Channels.newChannel(downloadURL.openStream()); - - fileOutputStream = new FileOutputStream(fileDestination.replace("\\","/")); - - fileChannel = fileOutputStream.getChannel(); - - fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE); - - } catch (IOException ex) { - LOG.error("An error occurred downloading " + fileDestination.replace("\\","/") + ".", ex); - FileUtils.deleteQuietly(new File(fileDestination.replace("\\","/"))); - } finally { - - try { - //noinspection ConstantConditions - fileOutputStream.flush(); - } catch (Exception ignored) { - - } - - try { - fileOutputStream.close(); - } catch (Exception ignored) { - - } - - try { - //noinspection ConstantConditions - readableByteChannel.close(); - } catch (Exception ignored) { - - } - - try { - //noinspection ConstantConditions - fileChannel.close(); - } catch (Exception ignored) { - - } - - } - - return new File(fileDestination).exists(); - } - - /** - * Move a file from source to destination, and replace the destination file if it exists. - * @author Griefed - * @param sourceFile The source file. - * @param destinationFile The destination file to be replaced by the source file. - * @return Boolean. Returns true if the file was sucessfully replaced. - * @throws IOException Thrown if an error occurs when the file is moved. - */ - public boolean replaceFile(File sourceFile, File destinationFile) throws IOException { - - if (sourceFile.exists() && destinationFile.delete()) { - - FileUtils.moveFile(sourceFile, destinationFile); - return true; - - } - - LOG.error("Source file not found."); - - return false; - } - - /** - * Unzips the downloaded modpack ZIP-archive to the specified directory. - * @author Griefed - * @param zipFile String. The path to the ZIP-archive which we want to unzip. - * @param destinationDirectory The directory into which the ZIP-archive will be unzipped into. - */ - public void unzipArchive(String zipFile, String destinationDirectory) { - /* This log is meant to be read by the user, therefore we allow translation. */ - LOG.info("Extracting ZIP-file: " + zipFile); - try { - new ZipFile(zipFile).extractAll(destinationDirectory); - } catch (ZipException ex) { - LOG.error("Error: There was an error extracting the archive " + zipFile, ex); - } - } - -} \ No newline at end of file diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/UpdateChecker.java b/backend/main/java/de/griefed/serverpackcreator/utilities/UpdateChecker.java index 9752725e68b704210310ac6d399ddf6c8813f8b3..5559e21e7fd8d13332c4d39a2595eb71f43eb3fb 100644 --- a/backend/main/java/de/griefed/serverpackcreator/utilities/UpdateChecker.java +++ b/backend/main/java/de/griefed/serverpackcreator/utilities/UpdateChecker.java @@ -149,7 +149,7 @@ public class UpdateChecker { * Check our GitLab, GitGriefed and GitHub instances for updates, sequentially, and then return the update. * @author Griefed * @param version {@link String} The version for which to check for updates. - * @param preReleaseCheck {@link Boolean} Whether to check pre-releases as well. Use <code>true</code> to check pre-releases + * @param preReleaseCheck {@link Boolean} Whether to check pre-releasesDescending as well. Use <code>true</code> to check pre-releasesDescending * as well, <Code>false</Code> to only check with regular releases. * @return {@link String} The update, if available, as well as the download URL. */ diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/BooleanUtilities.java b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/BooleanUtilities.java similarity index 96% rename from backend/main/java/de/griefed/serverpackcreator/utilities/BooleanUtilities.java rename to backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/BooleanUtilities.java index ae6f230a81bdd3d70093cb0ae3a9725d8bf11086..02e7db9882ee6a0e1163873d2f23aa12f413df62 100644 --- a/backend/main/java/de/griefed/serverpackcreator/utilities/BooleanUtilities.java +++ b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/BooleanUtilities.java @@ -17,31 +17,25 @@ * * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE */ -package de.griefed.serverpackcreator.utilities; +package de.griefed.serverpackcreator.utilities.commonutilities; import de.griefed.serverpackcreator.ApplicationProperties; import de.griefed.serverpackcreator.i18n.LocalizationManager; import de.griefed.serverpackcreator.utilities.misc.Generated; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - import java.util.Scanner; /** * Utility-class revolving around Booleans. * @author Griefed */ -@Component public class BooleanUtilities { private static final Logger LOG = LogManager.getLogger(BooleanUtilities.class); - private final LocalizationManager LOCALIZATIONMANAGER; private final ApplicationProperties APPLICATIONPROPERTIES; - @Autowired public BooleanUtilities(LocalizationManager injectedLocalizationManager, ApplicationProperties injectedApplicationProperties) { if (injectedApplicationProperties == null) { diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/FileUtilities.java b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/FileUtilities.java new file mode 100644 index 0000000000000000000000000000000000000000..92187865b88a4cee58b414b81a87cd45c15653d4 --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/FileUtilities.java @@ -0,0 +1,62 @@ +package de.griefed.serverpackcreator.utilities.commonutilities; + +import net.lingala.zip4j.ZipFile; +import net.lingala.zip4j.exception.ZipException; +import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.File; +import java.io.IOException; + +/** + * Utility-class revolving around various file-interactions. + * @author Griefed + */ +public class FileUtilities { + + private static final Logger LOG = LogManager.getLogger(FileUtilities.class); + + public FileUtilities() { + + } + + + /** + * Move a file from source to destination, and replace the destination file if it exists. + * @author Griefed + * @param sourceFile The source file. + * @param destinationFile The destination file to be replaced by the source file. + * @return Boolean. Returns true if the file was sucessfully replaced. + * @throws IOException Thrown if an error occurs when the file is moved. + */ + public boolean replaceFile(File sourceFile, File destinationFile) throws IOException { + + if (sourceFile.exists() && destinationFile.delete()) { + + FileUtils.moveFile(sourceFile, destinationFile); + return true; + + } + + LOG.error("Source file not found."); + + return false; + } + + /** + * Unzips the downloaded modpack ZIP-archive to the specified directory. + * @author Griefed + * @param zipFile String. The path to the ZIP-archive which we want to unzip. + * @param destinationDirectory The directory into which the ZIP-archive will be unzipped into. + */ + public void unzipArchive(String zipFile, String destinationDirectory) { + /* This log is meant to be read by the user, therefore we allow translation. */ + LOG.info("Extracting ZIP-file: " + zipFile); + try { + new ZipFile(zipFile).extractAll(destinationDirectory); + } catch (ZipException ex) { + LOG.error("Error: There was an error extracting the archive " + zipFile, ex); + } + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/JarUtilities.java b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/JarUtilities.java similarity index 99% rename from backend/main/java/de/griefed/serverpackcreator/utilities/JarUtilities.java rename to backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/JarUtilities.java index e9ffbcb2589baa6debecebcc91c2a15b50a166a7..77746276e4a8088a2500803cbdfa9c3ec0620767 100644 --- a/backend/main/java/de/griefed/serverpackcreator/utilities/JarUtilities.java +++ b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/JarUtilities.java @@ -17,14 +17,13 @@ * * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE */ -package de.griefed.serverpackcreator.utilities; +package de.griefed.serverpackcreator.utilities.commonutilities; import de.griefed.serverpackcreator.Main; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.boot.system.ApplicationHome; -import org.springframework.stereotype.Component; import java.io.*; import java.net.URISyntaxException; @@ -38,7 +37,6 @@ import java.util.jar.JarFile; * Some utilities used across ServerPackCreator, revolving around interacting with JAR-files. * @author Griefed */ -@Component public class JarUtilities { private static final Logger LOG = LogManager.getLogger(JarUtilities.class); diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/ListUtilities.java b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/ListUtilities.java similarity index 94% rename from backend/main/java/de/griefed/serverpackcreator/utilities/ListUtilities.java rename to backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/ListUtilities.java index 3599c8e05f99b1e8ae015b2be5c1d2b2dec8fcf0..1d5d36a8f25eaab9399418ff65d54fd0816d89e4 100644 --- a/backend/main/java/de/griefed/serverpackcreator/utilities/ListUtilities.java +++ b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/ListUtilities.java @@ -17,11 +17,9 @@ * * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE */ -package de.griefed.serverpackcreator.utilities; +package de.griefed.serverpackcreator.utilities.commonutilities; import de.griefed.serverpackcreator.utilities.misc.Generated; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; @@ -31,10 +29,8 @@ import java.util.Scanner; * Utility-class revolving around Lists. * @author Griefed */ -@Component public class ListUtilities { - @Autowired public ListUtilities() { } diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/StringUtilities.java b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/StringUtilities.java similarity index 95% rename from backend/main/java/de/griefed/serverpackcreator/utilities/StringUtilities.java rename to backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/StringUtilities.java index 42c23313d5fd5f9d215a9c27536b32f99468dfa1..3023edca53d20d8fc3d43c3951ce20349f4f703f 100644 --- a/backend/main/java/de/griefed/serverpackcreator/utilities/StringUtilities.java +++ b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/StringUtilities.java @@ -17,10 +17,7 @@ * * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE */ -package de.griefed.serverpackcreator.utilities; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +package de.griefed.serverpackcreator.utilities.commonutilities; import java.util.Arrays; @@ -28,10 +25,8 @@ import java.util.Arrays; * Utility-class revolving around Strings. * @author Griefed */ -@Component public class StringUtilities { - @Autowired public StringUtilities() { } diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/SystemUtilities.java b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/SystemUtilities.java new file mode 100644 index 0000000000000000000000000000000000000000..c3e2a2ba01779b85e1d9aece58eb9f252ed9eecf --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/SystemUtilities.java @@ -0,0 +1,73 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.utilities.commonutilities; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Utility-class revolving around the system we are running on. + * @author Griefed + */ +public class SystemUtilities { + + private static final Logger LOG = LogManager.getLogger(SystemUtilities.class); + + private final List<String> DRIVES = new ArrayList<>(Arrays.asList( + "A:","B:","C:","D:","E:","F:","G:","H:","I:","J:","K:","L:","M:","N:","O:","P:","Q:","R:","S:","T:","U:","V:","W:","X:","Y:","Z:" + )); + + public SystemUtilities() { + + } + + /** + * Automatically acquire the path to the systems default Java installation. + * @author Griefed + * @return String. The path to the systems default Java installation. + */ + public String acquireJavaPathFromSystem() { + + LOG.debug("Acquiring path to Java installation from system properties..."); + + String javaPath = "Couldn't acquire JavaPath"; + + if (new File(System.getProperty("java.home")).exists()) { + javaPath = String.format("%s/bin/java",System.getProperty("java.home").replace("\\", "/")); + + if (!javaPath.startsWith("/")) { + for (String letter : DRIVES) { + if (javaPath.startsWith(letter)) { + + LOG.debug("We're running on Windows. Ensuring javaPath ends with .exe"); + javaPath = String.format("%s.exe", javaPath); + } + } + } + } + + return javaPath; + } +} \ No newline at end of file diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/Utilities.java b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/Utilities.java new file mode 100644 index 0000000000000000000000000000000000000000..beb8870eb759663afdfedfcecd5cc2252a994b0e --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/Utilities.java @@ -0,0 +1,64 @@ +package de.griefed.serverpackcreator.utilities.commonutilities; + +import de.griefed.serverpackcreator.ApplicationProperties; +import de.griefed.serverpackcreator.i18n.LocalizationManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +/** + * Parent-class for all utilities, giving access to any and all utility-classes we may have. + * @author Griefed + */ +@Component +public class Utilities { + + private final BooleanUtilities BOOLEAN_UTILITIES; + + private final FileUtilities FILE_UTILITIES; + private final JarUtilities JAR_UTILITIES; + private final ListUtilities LIST_UTILITIES; + private final StringUtilities STRING_UTILITIES; + private final SystemUtilities SYSTEM_UTILITIES; + private final WebUtilities WEB_UTILITIES; + + @Autowired + public Utilities(LocalizationManager injectedLocalizationManager, ApplicationProperties injectedApplicationProperties) { + + this.BOOLEAN_UTILITIES = new BooleanUtilities(injectedLocalizationManager, injectedApplicationProperties); + this.FILE_UTILITIES = new FileUtilities(); + this.JAR_UTILITIES = new JarUtilities(); + this.LIST_UTILITIES = new ListUtilities(); + this.STRING_UTILITIES = new StringUtilities(); + this.SYSTEM_UTILITIES = new SystemUtilities(); + this.WEB_UTILITIES = new WebUtilities(); + } + + public BooleanUtilities BooleanUtils() { + return BOOLEAN_UTILITIES; + } + + public FileUtilities FileUtils() { + return FILE_UTILITIES; + } + + public JarUtilities JarUtils() { + return JAR_UTILITIES; + } + + public ListUtilities ListUtils() { + return LIST_UTILITIES; + } + + public StringUtilities StringUtils() { + return STRING_UTILITIES; + } + + public SystemUtilities SystemUtils() { + return SYSTEM_UTILITIES; + } + + public WebUtilities WebUtils() { + return WEB_UTILITIES; + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/WebUtilities.java b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/WebUtilities.java new file mode 100644 index 0000000000000000000000000000000000000000..f886432b552575bd3e623b82381a4a24186fe649 --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/utilities/commonutilities/WebUtilities.java @@ -0,0 +1,132 @@ +package de.griefed.serverpackcreator.utilities.commonutilities; + +import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.FileChannel; +import java.nio.channels.ReadableByteChannel; + +/** + * Utility-class revolving around interactions with web-resources. + * @author Griefed + */ +public class WebUtilities { + + private static final Logger LOG = LogManager.getLogger(WebUtilities.class); + + public WebUtilities() { + + } + + /** + * Download the file from the specified URL to the specified destination, replacing the file if it already exists. + * The destination should end in a valid filename. Any directories up to the specified file will be created. + * @author Griefed + * @param destinationFile File. The file to store the web-resource in. Examples:<br>/tmp/some_folder/foo.bar<br>C:/temp/some_folder/bar.foo + * @param downloadURL URL. The URL to the file you want to download. + * @return Boolean. Returns true if the file could be found on the hosts filesystem. + */ + public boolean downloadAndReplaceFile(File destinationFile, URL downloadURL) { + return downloadAndReplaceFile(destinationFile.getAbsoluteFile().toString().replace("\\","/"),downloadURL); + } + + /** + * Download the file from the specified URL to the specified destination, replacing the file if it already exists. + * The destination should end in a valid filename. Any directories up to the specified file will be created. + * @author Griefed + * @param fileDestination String. The file to store the web-resource in. Examples:<br>/tmp/some_folder/foo.bar<br>C:/temp/some_folder/bar.foo + * @param downloadURL URL. The URL to the file you want to download. + * @return Boolean. Returns true if the file could be found on the hosts filesystem. + */ + public boolean downloadAndReplaceFile(String fileDestination, URL downloadURL) { + FileUtils.deleteQuietly(new File(fileDestination)); + return downloadFile(fileDestination, downloadURL); + } + + /** + * Download the file from the specified URL to the specified destination. The destination should end in a valid filename. + * Any directories up to the specified file will be created. + * @author Griefed + * @param destinationFile File. The file to store the web-resource in. Examples:<br>/tmp/some_folder/foo.bar<br>C:/temp/some_folder/bar.foo + * @param downloadURL URL. The URL to the file you want to download. + * @return Boolean. Returns true if the file could be found on the hosts filesystem. + */ + public boolean downloadFile(File destinationFile, URL downloadURL) { + return downloadFile(destinationFile.getAbsoluteFile().toString().replace("\\","/"),downloadURL); + } + + /** + * Download the file from the specified URL to the specified destination. The destination should end in a valid filename. + * Any directories up to the specified file will be created. + * @author Griefed + * @param fileDestination String. The destination where the file should be stored. Must include the filename as well. + * Examples:<br>/tmp/some_folder/foo.bar<br>C:/temp/some_folder/bar.foo + * @param downloadURL URL. The URL to the file you want to download. + * @return Boolean. Returns true if the file could be found on the hosts filesystem. + */ + public boolean downloadFile(String fileDestination, URL downloadURL) { + + try { + FileUtils.createParentDirectories(new File(fileDestination)); + } catch (IOException ignored) { + + } + + ReadableByteChannel readableByteChannel = null; + FileOutputStream fileOutputStream = null; + FileChannel fileChannel = null; + + try { + + readableByteChannel = Channels.newChannel(downloadURL.openStream()); + + fileOutputStream = new FileOutputStream(fileDestination.replace("\\","/")); + + fileChannel = fileOutputStream.getChannel(); + + fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE); + + } catch (IOException ex) { + LOG.error("An error occurred downloading " + fileDestination.replace("\\","/") + ".", ex); + FileUtils.deleteQuietly(new File(fileDestination.replace("\\","/"))); + } finally { + + try { + //noinspection ConstantConditions + fileOutputStream.flush(); + } catch (Exception ignored) { + + } + + try { + fileOutputStream.close(); + } catch (Exception ignored) { + + } + + try { + //noinspection ConstantConditions + readableByteChannel.close(); + } catch (Exception ignored) { + + } + + try { + //noinspection ConstantConditions + fileChannel.close(); + } catch (Exception ignored) { + + } + + } + + return new File(fileDestination).exists(); + } + +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/Type.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/Type.java new file mode 100644 index 0000000000000000000000000000000000000000..6f0e2d4683d7a40f18b099996f561daaa12ba9e6 --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/Type.java @@ -0,0 +1,59 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta; + +/** + * Enums for various aspects of the VersionMeta. + * @author Griefed + */ +public enum Type { + + /** + * Indicates that an object is a full release, meaning no snapshot, alpha, or beta. + */ + RELEASE("Release"), + /** + * Indicates that an object is a pre-release, so either a snapshot (duh..), alpha, beta etc. + */ + SNAPSHOT("Snapshot"), + /** + * Minecraft client, so that which a users runs on their gaming machine. + */ + CLIENT("MinecraftClient"), + /** + * Minecraft server, usually run on a dedicated server. + */ + SERVER("MinecraftServer"), + /** + * Sort ascending, small to large. + */ + ASCENDING("Ascending"), + /** + * Sort descending, large to small. + */ + DESCENDING("Descending"); + + public final String type; + + Type(String type) { + this.type = type; + } + +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/VersionMeta.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/VersionMeta.java new file mode 100644 index 0000000000000000000000000000000000000000..1289ed3672e9d1816ca353c137c20daf26516f68 --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/VersionMeta.java @@ -0,0 +1,105 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta; + +import de.griefed.serverpackcreator.ApplicationProperties; +import de.griefed.serverpackcreator.versionmeta.fabric.FabricMeta; +import de.griefed.serverpackcreator.versionmeta.forge.ForgeMeta; +import de.griefed.serverpackcreator.versionmeta.minecraft.MinecraftMeta; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.IOException; + +/** + * VersionMeta containing available versions and important details for Minecraft, Fabric and Forge. + * @author Griefed + */ +@Service +public class VersionMeta { + + private final MinecraftMeta MINECRAFT_META; + private final FabricMeta FABRIC_META; + private final ForgeMeta FORGE_META; + + /** + * Constructor. + * @author Griefed + * @param injectedApplicationProperties Instance of {@link ApplicationProperties}. + * @throws IOException if one of the metas could not be initialized. + */ + @Autowired + public VersionMeta(ApplicationProperties injectedApplicationProperties) throws IOException { + ApplicationProperties APPLICATIONPROPERTIES; + if (injectedApplicationProperties == null) { + APPLICATIONPROPERTIES = new ApplicationProperties(); + } else { + APPLICATIONPROPERTIES = injectedApplicationProperties; + } + + this.FORGE_META = new ForgeMeta(APPLICATIONPROPERTIES); + this.MINECRAFT_META = new MinecraftMeta(APPLICATIONPROPERTIES, this.FORGE_META); + this.FABRIC_META = new FabricMeta(APPLICATIONPROPERTIES); + + this.FORGE_META.initialize(this.MINECRAFT_META); + + update(); + } + + /** + * Update the Minecraft, Forge and Fabric metas. Usually called when the manifest files have been refreshed. + * @author Griefed + * @return Instance of {@link VersionMeta}. + * @throws IOException if any of the metas could not be updated. + */ + public VersionMeta update() throws IOException { + this.MINECRAFT_META.update(); + this.FABRIC_META.update(); + this.FORGE_META.update(); + return this; + } + + /** + * The MinecraftMeta instance for working with Minecraft versions and information about them. + * @author Griefed + * @return Instance of {@link MinecraftMeta}. + */ + public MinecraftMeta minecraft() { + return MINECRAFT_META; + } + + /** + * The FabricMeta instance for working with Fabric versions and information about them. + * @author Griefed + * @return Instance of {@link FabricMeta}. + */ + public FabricMeta fabric() { + return FABRIC_META; + } + + /** + * The ForgeMeta instance for working with Forge versions and information about them. + * @author Griefed + * @return Instance of {@link ForgeMeta}. + */ + public ForgeMeta forge() { + return FORGE_META; + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/fabric/FabricInstaller.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/fabric/FabricInstaller.java new file mode 100644 index 0000000000000000000000000000000000000000..4e3e2f3d230adc4a3c94263c1e5f1d4a2e37feee --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/fabric/FabricInstaller.java @@ -0,0 +1,199 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta.fabric; + +import org.w3c.dom.Document; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; + +/** + * Information about the Fabric installer. + * @author Griefed + */ +public class FabricInstaller { + + private final String URL_TEMPLATE_INSTALLER = "https://maven.fabricmc.net/net/fabricmc/fabric-installer/%s/fabric-installer-%s.jar"; + private final List<String> installers = new ArrayList<>(); + private String latestInstaller; + private String releaseInstaller; + private URL latestInstallerUrl; + private URL releaseInstallerUrl; + private HashMap<String, URL> installerUrlMeta; + + /** + * Constructor + * @author Griefed + * @param installerManifest {@link Document} containing Fabric installer information + */ + protected FabricInstaller(Document installerManifest) { + this.latestInstaller = installerManifest.getElementsByTagName("latest").item(0).getChildNodes().item(0).getNodeValue(); + this.releaseInstaller = installerManifest.getElementsByTagName("release").item(0).getChildNodes().item(0).getNodeValue(); + try { + this.latestInstallerUrl = new URL(String.format(URL_TEMPLATE_INSTALLER, this.latestInstaller, this.latestInstaller)); + } catch (MalformedURLException ignored) { + + } + try { + this.releaseInstallerUrl = new URL(String.format(URL_TEMPLATE_INSTALLER, this.releaseInstaller, this.releaseInstaller)); + } catch (MalformedURLException ignored) { + + } + this.installers.clear(); + for (int i = 0; i < installerManifest.getElementsByTagName("version").getLength(); i++) { + installers.add(installerManifest.getElementsByTagName("version").item(i).getChildNodes().item(0).getNodeValue()); + } + this.installerUrlMeta = new HashMap<>(); + this.installers.forEach(version -> { + try { + this.installerUrlMeta.put(version, installerUrl(version)); + } catch (MalformedURLException ignored) { + + } + }); + } + + /** + * Update this {@link FabricInstaller} with information from the given {@link Document}. + * @author Griefed + * @param installerManifest {@link Document} containing new installer information. + * @return This instance of {@link FabricInstaller}. + */ + protected FabricInstaller update(Document installerManifest) { + this.latestInstaller = installerManifest.getElementsByTagName("latest").item(0).getChildNodes().item(0).getNodeValue(); + this.releaseInstaller = installerManifest.getElementsByTagName("release").item(0).getChildNodes().item(0).getNodeValue(); + try { + this.latestInstallerUrl = new URL(String.format(URL_TEMPLATE_INSTALLER, this.latestInstaller, this.latestInstaller)); + } catch (MalformedURLException ignored) { + + } + try { + this.releaseInstallerUrl = new URL(String.format(URL_TEMPLATE_INSTALLER, this.releaseInstaller, this.releaseInstaller)); + } catch (MalformedURLException ignored) { + + } + this.installers.clear(); + for (int i = 0; i < installerManifest.getElementsByTagName("version").getLength(); i++) { + installers.add(installerManifest.getElementsByTagName("version").item(i).getChildNodes().item(0).getNodeValue()); + } + this.installerUrlMeta = new HashMap<>(); + this.installers.forEach(version -> { + try { + this.installerUrlMeta.put(version, installerUrl(version)); + } catch (MalformedURLException ignored) { + + } + }); + + return this; + } + + /** + * Acquire the URL for the given Fabric version. + * @author Griefed + * @param fabricVersion {@link String} Fabric version. + * @return {@link URL} to the installer for the given Fabric version. + * @throws MalformedURLException if the URL could not be formed. + */ + private URL installerUrl(String fabricVersion) throws MalformedURLException { + return new URL(String.format(URL_TEMPLATE_INSTALLER, fabricVersion, fabricVersion)); + } + + /** + * Get a list of available installer versions for Fabric. + * @author Griefed + * @return {@link String}-list of available Fabric installer versions. + */ + protected List<String> installers() { + return installers; + } + + /** + * Meta for the Fabric-Version-to-Installer-URL.<br> + * key: {@link String} Fabric version.<br> + * value: {@link URL} Fabric installer URL. + * @author Griefed + * @return {@link HashMap} with the Fabric-Version-to-Installer-URL. + */ + protected HashMap<String, URL> meta() { + return installerUrlMeta; + } + + /** + * Get the latest Fabric installer version. + * @author Griefed + * @return {@link String} The latest Fabric installer version. + */ + protected String latestInstallerVersion() { + return latestInstaller; + } + + /** + * Get the release Fabric installer version. + * @author Griefed + * @return {@link String} The release Fabric installer version. + */ + protected String releaseInstallerVersion() { + return releaseInstaller; + } + + /** + * Get the {@link URL} to the latest Fabric installer. + * @author Griefed + * @return {@link URL} to the latest Fabric installer. + */ + protected URL latestInstallerUrl() { + return latestInstallerUrl; + } + + /** + * Get the {@link URL} to the release Fabric installer. + * @author Griefed + * @return {@link URL} to the release Fabric installer. + */ + protected URL releaseInstallerUrl() { + return releaseInstallerUrl; + } + + /** + * Get the {@link URL} to the improved Fabric launcher for the given Minecraft and Fabric versions. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @param fabricVersion {@link String} Fabric version. + * @return {@link URL} to the improved Fabric launcher, wrapped in an {@link Optional}. + */ + protected Optional<URL> improvedLauncherUrl(String minecraftVersion, String fabricVersion) { + try { + return Optional.of(new URL( + String.format("https://meta.fabricmc.net/v2/versions/loader/%s/%s/%s/server/jar", + minecraftVersion, + fabricVersion, + releaseInstaller + ) + )); + } catch (MalformedURLException ex) { + return Optional.empty(); + } + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/fabric/FabricLoader.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/fabric/FabricLoader.java new file mode 100644 index 0000000000000000000000000000000000000000..935dd6f0acda3ce36bd159fb57a83c35460e2e75 --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/fabric/FabricLoader.java @@ -0,0 +1,95 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta.fabric; + +import org.w3c.dom.Document; + +import java.util.ArrayList; +import java.util.List; + +/** + * Information about releases of the Fabric loader. + * @author Griefed + */ +public class FabricLoader { + + private String latest; + private String release; + private final List<String> loaders = new ArrayList<>(); + + /** + * Constructor + * @author Griefed + * @param loaderManifest {@link Document} containing Fabrics manifest. + */ + protected FabricLoader(Document loaderManifest) { + + this.latest = loaderManifest.getElementsByTagName("latest").item(0).getChildNodes().item(0).getNodeValue(); + this.release = loaderManifest.getElementsByTagName("release").item(0).getChildNodes().item(0).getNodeValue(); + this.loaders.clear(); + for (int i = 0; i < loaderManifest.getElementsByTagName("version").getLength(); i++) { + loaders.add(loaderManifest.getElementsByTagName("version").item(i).getChildNodes().item(0).getNodeValue()); + } + } + + /** + * Update the latest, release and releases information. + * @author Griefed + * @param loaderManifest {@link Document} containing Fabrics manifest. + * @return This instance of {@link FabricLoader}. + */ + protected FabricLoader update(Document loaderManifest) { + this.latest = loaderManifest.getElementsByTagName("latest").item(0).getChildNodes().item(0).getNodeValue(); + this.release = loaderManifest.getElementsByTagName("release").item(0).getChildNodes().item(0).getNodeValue(); + this.loaders.clear(); + for (int i = 0; i < loaderManifest.getElementsByTagName("version").getLength(); i++) { + loaders.add(loaderManifest.getElementsByTagName("version").item(i).getChildNodes().item(0).getNodeValue()); + } + + return this; + } + + /** + * Get the latest Fabric loader version. + * @author Griefed + * @return {@link String} The latest Fabric loader version. + */ + protected String latestLoaderVersion() { + return latest; + } + + /** + * Get the release Fabric loader version. + * @author Griefed + * @return {@link String} The release Fabric loader version. + */ + protected String releaseLoaderVersion() { + return release; + } + + /** + * Get the list of available Fabric loader versions. + * @author Griefed + * @return {@link String}-list of the available Fabric loader versions. + */ + protected List<String> loaders() { + return loaders; + } +} \ No newline at end of file diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/fabric/FabricMeta.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/fabric/FabricMeta.java new file mode 100644 index 0000000000000000000000000000000000000000..fdf8da4ad8996659dfe9f2be3a13e291a8f35509 --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/fabric/FabricMeta.java @@ -0,0 +1,267 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta.fabric; + +import com.google.common.collect.Lists; +import de.griefed.serverpackcreator.ApplicationProperties; +import de.griefed.serverpackcreator.versionmeta.Type; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.Optional; + +/** + * Fabric meta containing information about available Fabric releases and installers. + * @author Griefed + */ +public class FabricMeta { + + private final ApplicationProperties APPLICATIONPROPERTIES; + private final FabricLoader fabricLoader; + private final FabricInstaller fabricInstaller; + + /** + * Constructor + * @author Griefed + * @param injectedApplicationProperties instance of {@link ApplicationProperties}. + * @throws MalformedURLException if the meta could not be updated. + */ + public FabricMeta(ApplicationProperties injectedApplicationProperties) throws MalformedURLException { + + if (injectedApplicationProperties == null) { + this.APPLICATIONPROPERTIES = new ApplicationProperties(); + } else { + this.APPLICATIONPROPERTIES = injectedApplicationProperties; + } + + this.fabricLoader = new FabricLoader(getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC)); + this.fabricInstaller = new FabricInstaller(getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC_INSTALLER)); + + } + + /** + * Update the {@link FabricLoader} and {@link FabricInstaller} information. + * @author Griefed + * @return This instance of {@link FabricMeta}. + * @throws MalformedURLException if a URL could not be constructed + */ + public FabricMeta update() throws MalformedURLException { + + this.fabricLoader.update(getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC)); + this.fabricInstaller.update(getXml(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FABRIC_INSTALLER)); + + return this; + } + + private Document getXml(File manifest) { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = null; + Document xml = null; + try { + documentBuilder = documentBuilderFactory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } + try { + assert documentBuilder != null; + xml = documentBuilder.parse(manifest); + } catch (SAXException | IOException e) { + e.printStackTrace(); + } + assert xml != null; + xml.normalize(); + return xml; + } + + /** + * Get the latest Fabric loader version. + * @author Griefed + * @return {@link String} The latest version of the Fabric loader. + */ + public String latestLoaderVersion() { + return fabricLoader.latestLoaderVersion(); + } + + /** + * Get the release Fabric loader version. + * @author Griefed + * @return {@link String} The release version of the Fabric loader. + */ + public String releaseLoaderVersion() { + return fabricLoader.releaseLoaderVersion(); + } + + /** + * Get a list of available Fabric loader versions, in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-list of available Fabric loader versions, in {@link Type#ASCENDING} order. + */ + public List<String> loaderVersionsAscending() { + return fabricLoader.loaders(); + } + + /** + * Get a list of available Fabric loader versions, in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-list of available Fabric loader versions, in {@link Type#DESCENDING} order. + */ + public List<String> loaderVersionsDescending() { + return Lists.reverse(fabricLoader.loaders()); + } + + /** + * Get an array of available Fabric loader versions, in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-array of available Fabric loader versions, in {@link Type#ASCENDING} order. + */ + public String[] loaderVersionsArrayAscending() { + return fabricLoader.loaders().toArray(new String[0]); + } + + /** + * Get an array of available Fabric loader versions, in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-array of available Fabric loader versions, in {@link Type#DESCENDING} order. + */ + public String[] loaderVersionsArrayDescending() { + return Lists.reverse(fabricLoader.loaders()).toArray(new String[0]); + } + + /** + * Get the latest Fabric installer version. + * @author Griefed + * @return {@link String} The latest Fabric installer version. + */ + public String latestInstallerVersion() { + return fabricInstaller.latestInstallerVersion(); + } + + /** + * Get the release Fabric installer version. + * @author Griefed + * @return {@link String} The release Fabric installer version. + */ + public String releaseInstallerVersion() { + return fabricInstaller.releaseInstallerVersion(); + } + + /** + * Get the list of available Fabric installer version, in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-list of available Fabric installer version, in {@link Type#ASCENDING} order. + */ + public List<String> installerVersionsAscending() { + return fabricInstaller.installers(); + } + + /** + * Get the list of available Fabric installer version, in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-list of available Fabric installer version, in {@link Type#DESCENDING} order. + */ + public List<String> installerVersionsDescending() { + return Lists.reverse(fabricInstaller.installers()); + } + + /** + * Get the array of available Fabric installer version, in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-array of available Fabric installer version, in {@link Type#ASCENDING} order. + */ + public String[] installerVersionsArrayAscending() { + return fabricInstaller.installers().toArray(new String[0]); + } + + /** + * Get the array of available Fabric installer version, in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-array of available Fabric installer version, in {@link Type#DESCENDING} order. + */ + public String[] installerVersionsArrayDescending() { + return Lists.reverse(fabricInstaller.installers()).toArray(new String[0]); + } + + /** + * Get the {@link URL} to the latest Fabric installer. + * @author Griefed + * @return {@link URL} to the latest Fabric installer. + */ + public URL latestInstallerUrl() { + return fabricInstaller.latestInstallerUrl(); + } + + /** + * Get the {@link URL} to the release Fabric installer. + * @author Griefed + * @return {@link URL} to the release Fabric installer. + */ + public URL releaseInstallerUrl() { + return fabricInstaller.releaseInstallerUrl(); + } + + /** + * Check whether a {@link URL} to the specified Fabric installer version is available. + * @author Griefed + * @param fabricVersion {@link String} Fabric version. + * @return {@link Boolean} <code>true</code> if a {@link URL} to the specified Fabric installer version is available. + */ + public boolean isInstallerUrlAvailable(String fabricVersion) { + return Optional.ofNullable(fabricInstaller.meta().get(fabricVersion)).isPresent(); + } + + /** + * Get the {@link URL} to the Fabric installer for the specified version. + * @author Griefed + * @param fabricVersion {@link String} Fabric version. + * @return {@link URL} to the Fabric installer for the specified version. + */ + public Optional<URL> installerUrl(String fabricVersion) { + return Optional.ofNullable(fabricInstaller.meta().get(fabricVersion)); + } + + /** + * Get the {@link URL} to the Fabric launcher for the specified Minecraft and Fabric version. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @param fabricVersion {@link String} Fabric version. + * @return {@link URL} to the Fabric launcher for the specified Minecraft and Fabric version. + */ + public Optional<URL> improvedLauncherUrl(String minecraftVersion, String fabricVersion) { + return fabricInstaller.improvedLauncherUrl(minecraftVersion, fabricVersion); + } + + /** + * Check whether the specified Fabric version is available/correct/valid. + * @author Griefed + * @param fabricVersion {@link String} Fabric version. + * @return {@link Boolean} <code>true</code> if the specified version is available/correct/valid. + */ + public boolean checkFabricVersion(String fabricVersion) { + return fabricLoader.loaders().contains(fabricVersion); + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/forge/ForgeInstance.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/forge/ForgeInstance.java new file mode 100644 index 0000000000000000000000000000000000000000..2d5079d1e281dc5d9c09dcd164c829421133f856 --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/forge/ForgeInstance.java @@ -0,0 +1,91 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta.forge; + +import de.griefed.serverpackcreator.versionmeta.minecraft.MinecraftClient; +import de.griefed.serverpackcreator.versionmeta.minecraft.MinecraftMeta; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Optional; + +/** + * An instance of a complete Forge combination, containing a Minecraft version, related Forge version and the URL to the + * server installer. + * @author Griefed + */ +public class ForgeInstance { + + private final String MINECRAFT_VERSION; + private final String FORGE_VERSION; + private final URL INSTALLER_URL; + private final MinecraftMeta MINECRAFT_META; + + /** + * Constructor. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @param forgeVersion {@link String} Forge version. + * @param minecraftMeta {@link MinecraftMeta} The corresponding Minecraft client for this Forge version. + * @throws MalformedURLException if the URL to the download of the Forge server installer could not be created. + */ + public ForgeInstance(String minecraftVersion, String forgeVersion, MinecraftMeta minecraftMeta) throws MalformedURLException { + this.MINECRAFT_VERSION = minecraftVersion; + this.FORGE_VERSION = forgeVersion; + this.INSTALLER_URL = new URL(String.format("https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s-%s/forge-%s-%s-installer.jar", minecraftVersion, forgeVersion, minecraftVersion, forgeVersion)); + this.MINECRAFT_META = minecraftMeta; + } + + /** + * Get the Minecraft version of this Forge instance. + * @author Griefed + * @return {@link String} Minecraft version. + */ + public String minecraftVersion() { + return MINECRAFT_VERSION; + } + + /** + * Get the Forge version of this Forge instance. + * @author Griefed + * @return {@link String} Forge version. + */ + public String forgeVersion() { + return FORGE_VERSION; + } + + /** + * Get the URL to the Forge server installer for this instances Minecraft and Forge version. + * @author Griefed + * @return Download {@link URL} to the Forge server installer JAR-file. + */ + public URL installerUrl() { + return INSTALLER_URL; + } + + /** + * Get this Forge instances corresponding Minecraft client instance, wrapped in an {@link Optional} + * @author Griefed + * @return {@link MinecraftClient} wrapped in an {@link Optional}. + */ + public Optional<MinecraftClient> minecraftClient() { + return MINECRAFT_META.getClient(this.MINECRAFT_VERSION); + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/forge/ForgeLoader.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/forge/ForgeLoader.java new file mode 100644 index 0000000000000000000000000000000000000000..376562cc808ef1f5255fc5a280b80221200a82a0 --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/forge/ForgeLoader.java @@ -0,0 +1,198 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta.forge; + +import com.fasterxml.jackson.databind.JsonNode; +import de.griefed.serverpackcreator.versionmeta.minecraft.MinecraftMeta; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.net.MalformedURLException; +import java.util.*; + +/** + * Information about available Forge loader versions in correlation to Minecraft versions. + * @author Griefed + */ +public class ForgeLoader { + + private static final Logger LOG = LogManager.getLogger(ForgeLoader.class); + + private final MinecraftMeta MINECRAFT_META; + private final List<String> minecraftVersions = new ArrayList<>(); + private final List<String> forgeVersions = new ArrayList<>(); + + /** + * 1-n Minecraft version to Forge versions.<br> + * <code>key</code>: Minecraft version.<br> + * <code>value</code>: List of Forge versions for said Minecraft versions. + */ + private HashMap<String, List<String>> versionMeta; + + /** + * 1-1 Forge version to Minecraft version<br> + * <code>key</code>: Forge version.<br> + * <code>value</code>: Minecraft version for said Forge version. + */ + private HashMap<String, String> forgeToMinecraftMeta; + + /** + * 1-1 Minecraft + Forge version combination to {@link ForgeInstance}<br> + * <code>key</code>: Minecraft version + Forge version. Example: <code>1.18.2-40.0.44</code><br> + * <code>value</code>: The {@link ForgeInstance} for said Minecraft and Forge version combination. + */ + private HashMap<String, ForgeInstance> instanceMeta; + + /** + * Constructor + * @author Griefed + * @param forgemanifest {@link JsonNode} containing information about available Forge versions. + * @param injectedMinecraftMeta {@link MinecraftMeta} for retroactively updating the previously passed meta. + */ + protected ForgeLoader(JsonNode forgemanifest, MinecraftMeta injectedMinecraftMeta) { + this.MINECRAFT_META = injectedMinecraftMeta; + update(forgemanifest); + } + + /** + * Update the available Forge loader information. + * @author Griefed + * @param forgeManifest {@link JsonNode} containing information about available Forge versions. + * @return This instance of {@link ForgeLoader}. + */ + protected ForgeLoader update(JsonNode forgeManifest) { + + minecraftVersions.clear(); + forgeVersions.clear(); + versionMeta = new HashMap<>(); + forgeToMinecraftMeta = new HashMap<>(); + instanceMeta = new HashMap<>(); + + forgeManifest.fieldNames().forEachRemaining(field -> { + + /* + * A field, which represents a supported Minecraft version from the Forge manifest, does NOT necessarily exist + * in Mojang's Minecraft manifest. + * Examples: + * Forge Manifest Minecraft version: 1.7.10_pre4 + * Minecraft Manifest version: 1.7.10-pre4 + * So, if we want to acquire a Forge instance for 1.7.10-pre4, it would fail. + * When retrieving a Forge instance with a Minecraft version from the MinecraftMeta, we need to check for + * 1.7.10_pre4 AND 1.7.10-pre4. + */ + String mcVersion; + if (MINECRAFT_META.getClient(field.replace("_","-")).isPresent()) { + mcVersion = field.replace("_","-"); + minecraftVersions.add(field.replace("_","-")); + } else { + mcVersion = field; + minecraftVersions.add(field); + } + + List<String> forgeVersionsForMCVer = new ArrayList<>(); + + forgeManifest.get(field).forEach(forge -> { + + /* + * substring of length of Minecraft version plus 1, so entries like "1.18.2-40.0.17" get their + * Minecraft version portion removed and result in "40.0.17". The +1 removes the "-", too. :) + */ + forgeVersions.add(forge.asText().substring(mcVersion.length() + 1)); + forgeVersionsForMCVer.add(forge.asText().substring(mcVersion.length() + 1)); + + try { + + ForgeInstance forgeInstance = new ForgeInstance( + mcVersion, + forge.asText().substring(mcVersion.length() + 1), + MINECRAFT_META + ); + + instanceMeta.put( + mcVersion + forge.asText().substring(mcVersion.length()), + forgeInstance + ); + + forgeToMinecraftMeta.put(forge.asText().substring(mcVersion.length() + 1), mcVersion); + + } catch (MalformedURLException | NoSuchElementException ex) { + + // Well, in THEORY this should never be throws, so we don't need to bother with a thorough error message + LOG.debug("Could not create Forge instance for Minecraft " + mcVersion + " and Forge " + forge.asText().substring(mcVersion.length() + 1), ex); + } + }); + + versionMeta.put(mcVersion, forgeVersionsForMCVer); + + }); + + return this; + + } + + /** + * Get a list of available Minecraft versions for Forge. + * @author Griefed + * @return {@link String}-list of the available Minecraft versions for Forge. + */ + protected List<String> minecraftVersions() { return minecraftVersions; } + + /** + * Get a list of available Forge versions. + * @author Griefed + * @return {@link String}-list of the available Forge versions. + */ + protected List<String> forgeVersions() { + return forgeVersions; + } + + /** + * Get the {@link ForgeLoader} version-meta.<br> + * key: {@link String} Minecraft version<br> + * value: {@link String}-list of Forge versions available for the given Minecraft version. + * @author Griefed + * @return {@link HashMap} containing the version meta. + */ + protected HashMap<String, List<String>> versionMeta() { + return versionMeta; + } + + /** + * Get the Forge version to Minecraft version meta.<br> + * key: {@link String} Forge version.<br> + * version: {@link String} Minecraft version for the given Forge version. + * @author Griefed + * @return {@link HashMap} with Forge-to-Minecraft-version mappings. + */ + protected HashMap<String, String> forgeToMinecraftMeta() { + return forgeToMinecraftMeta; + } + + /** + * Get the Minecraft-Forge-version meta.<br> + * key: {@link String} Minecraft version + Forge version concatenation.<br> + * value: {@link ForgeInstance} for the given Minecraft version + Forge version concatenation. + * @author Griefed + * @return {@link HashMap} with Minecraft-Forge-version-to-ForgeInstance mapping. + */ + protected HashMap<String, ForgeInstance> instanceMeta() { + return instanceMeta; + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/forge/ForgeMeta.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/forge/ForgeMeta.java new file mode 100644 index 0000000000000000000000000000000000000000..0a7767583dfe7ce4878144490cf450910141f05c --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/forge/ForgeMeta.java @@ -0,0 +1,414 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta.forge; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Lists; +import de.griefed.serverpackcreator.ApplicationProperties; +import de.griefed.serverpackcreator.versionmeta.Type; +import de.griefed.serverpackcreator.versionmeta.minecraft.MinecraftMeta; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * Forge meta containing information about available Forge releases. + * @author Griefed + */ +public class ForgeMeta { + + private final ApplicationProperties APPLICATIONPROPERTIES; + private final ObjectMapper OBJECTMAPPER = new ObjectMapper() + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + private ForgeLoader forgeLoader; + + public ForgeMeta(ApplicationProperties injectedApplicationProperties) { + this.APPLICATIONPROPERTIES = injectedApplicationProperties; + } + + /** + * Update this instances {@link ForgeLoader} with new information. Usually called after the Forge manifest has been + * refreshed. + * @author Griefed + * @param injectedMinecraftMeta Instance of {@link MinecraftMeta} + * @throws IOException if the manifest could not be parsed into a {@link com.fasterxml.jackson.databind.JsonNode}. + */ + public void initialize(MinecraftMeta injectedMinecraftMeta) throws IOException { + if (this.forgeLoader == null) { + this.forgeLoader = new ForgeLoader( + OBJECTMAPPER.readTree(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FORGE), + injectedMinecraftMeta + ); + } + } + + /** + * Update this instances {@link ForgeLoader} with new information. Usually called after the Forge manifest has been + * refreshed. + * @author Griefed + * @return This instance of {@link ForgeMeta} + * @throws IOException if the manifest could not be parsed into a {@link com.fasterxml.jackson.databind.JsonNode}. + */ + public ForgeMeta update() throws IOException { + this.forgeLoader.update(OBJECTMAPPER.readTree(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_FORGE)); + + return this; + } + + /** + * Get the list of Forge supported Minecraft versions, with either {@link Type#ASCENDING} or {@link Type#DESCENDING} + * order. + * @author Griefed + * @param order {@link Type} The order of the resulting list. Either {@link Type#ASCENDING} or {@link Type#DESCENDING}. + * @return {@link String}-list Forge supported Minecraft versions, in either {@link Type#ASCENDING} or {@link Type#DESCENDING} + * order. + */ + private List<String> supportedMinecraftVersionsList(Type order) { + if (order == Type.DESCENDING) { + return Lists.reverse(forgeLoader.minecraftVersions()); + } else { + return forgeLoader.minecraftVersions(); + } + } + + /** + * Get the list of available Forge versions, with either {@link Type#ASCENDING} or {@link Type#DESCENDING} order. + * @author Griefed + * @param order {@link Type} The order of the resulting list. Either {@link Type#ASCENDING} or {@link Type#DESCENDING}. + * @return {@link String}-list Forge versions, in either {@link Type#ASCENDING} or {@link Type#DESCENDING} order. + */ + private List<String> supportedForgeVersionsList(Type order) { + if (order == Type.DESCENDING) { + return Lists.reverse(forgeLoader.forgeVersions()); + } else { + return forgeLoader.forgeVersions(); + } + } + + /** + * Get an array of available Forge version for a given Minecraft version, either {@link Type#ASCENDING} or + * {@link Type#DESCENDING}, wrapped in an {@link Optional}. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @param order {@link Type} Either {@link Type#DESCENDING}, wrapped in an {@link Optional}. + * @return {@link String}-array of available Forge versions for the given Minecraft version, either + * {@link Type#ASCENDING} or {@link Type#DESCENDING}, wrapped in an {@link Optional}. + */ + private Optional<String[]> getForgeVersionsArray(String minecraftVersion, Type order) { + if (!checkMinecraftVersion(minecraftVersion)) { + return Optional.empty(); + } + if (order == Type.DESCENDING) { + return Optional.of(Lists.reverse(forgeLoader.versionMeta().get(minecraftVersion)).toArray(new String[0])); + } else { + return Optional.of(forgeLoader.versionMeta().get(minecraftVersion).toArray(new String[0])); + } + } + + /** + * Get a list of available Forge version for a given Minecraft version, with either {@link Type#ASCENDING} or + * {@link Type#DESCENDING} order. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @param order {@link Type} The order of the resulting list. Either {@link Type#ASCENDING} or {@link Type#DESCENDING}. + * @return {@link String}-list of available Forge versions for the given Minecraft version, with either + * {@link Type#ASCENDING} or {@link Type#DESCENDING} order. + */ + private Optional<List<String>> getForgeVersions(String minecraftVersion, Type order) { + if (!checkMinecraftVersion(minecraftVersion)) { + return Optional.empty(); + } + if (order == Type.DESCENDING) { + return Optional.ofNullable(Lists.reverse(forgeLoader.versionMeta().get(minecraftVersion))); + } else { + return Optional.ofNullable(forgeLoader.versionMeta().get(minecraftVersion)); + } + } + + /** + * Check whether a given Forge version is valid/supported/available. + * @author Griefed + * @param forgeVersion {@link String} Forge version. + * @return {@link Boolean} <code>true</code> if the given Forge version is valid/supported/available. + */ + public boolean checkForgeVersion(String forgeVersion) { + return Optional.ofNullable(forgeLoader.forgeToMinecraftMeta().get(forgeVersion)).isPresent(); + } + + /** + * Check whether a given Minecraft version is valid/supported/available. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @return {@link Boolean} <code>true</code> if the given Minecraft version is valid/supported/available. + */ + public boolean checkMinecraftVersion(String minecraftVersion) { + return Optional.ofNullable(forgeLoader.versionMeta().get(minecraftVersion)).isPresent(); + } + + /** + * Check whether the given Minecraft and Forge versions are valid/supported/available. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @param forgeVersion {@link String} Forge version. + * @return {@link Boolean} <code>true</code> if the given Minecraft and Forge versions are valid/supported/available. + */ + public boolean checkForgeAndMinecraftVersion(String minecraftVersion, String forgeVersion) { + return checkMinecraftVersion(minecraftVersion) && checkForgeVersion(forgeVersion); + } + + /** + * Check whether Forge is available for a given Forge- and Minecraft version. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @param forgeVersion {@link String} Forge version. + * @return {@link Boolean} <code>true</code> if Forge is available for the given Forge- and Minecraft version. + */ + public boolean isForgeInstanceAvailable(String minecraftVersion, String forgeVersion) { + return getForgeInstance(minecraftVersion,forgeVersion).isPresent(); + } + + /** + * Check whether Forge is available for a given Forge version + * @author Griefed + * @param forgeVersion {@link String} Forge version. + * @return {@link Boolean} <code>true</code> if Forge is available for the given Forge version. + */ + public boolean isForgeInstanceAvailable(String forgeVersion) { + return getForgeInstance(forgeVersion).isPresent(); + } + + /** + * Get the Minecraft version for a given Forge version, wrapped in an {@link Optional}. + * @author Griefed + * @param forgeVersion {@link String} Forge version. + * @return {@link String} Minecraft version for the given Forge version, wrapped in an {@link Optional}. + */ + public Optional<String> supportedMinecraftVersion(String forgeVersion) { + return Optional.ofNullable(forgeLoader.forgeToMinecraftMeta().get(forgeVersion)); + } + + /** + * Get a {@link ForgeInstance} for a given Minecraft and Forge version, wrapped in an {@link Optional}. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @param forgeVersion {@link String} Forge version. + * @return {@link ForgeInstance} for the given Minecraft and Forge version, wrapped in an {@link Optional} + */ + public Optional<ForgeInstance> getForgeInstance(String minecraftVersion, String forgeVersion) { + return Optional.ofNullable(forgeLoader.instanceMeta().get(minecraftVersion + "-" + forgeVersion)); + } + + /** + * Get a {@link ForgeInstance} for a given Forge version, wrapped in an {@link Optional}. + * @author Griefed + * @param forgeVersion {@link String} Forge version. + * @return {@link ForgeInstance} for the given Forge version, wrapped in an {@link Optional} + */ + public Optional<ForgeInstance> getForgeInstance(String forgeVersion) { + if (!checkForgeVersion(forgeVersion)) { + return Optional.empty(); + } + return getForgeInstance(supportedMinecraftVersion(forgeVersion).get(),forgeVersion); + } + + /** + * Get a list of all available {@link ForgeInstance} for a given Minecraft version, wrapped in an {@link Optional} + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @return {@link ForgeInstance}-list for the given Minecraft version. + */ + public Optional<List<ForgeInstance>> getForgeInstances(String minecraftVersion) { + List<ForgeInstance> list = new ArrayList<>(); + if (Optional.ofNullable(forgeLoader.versionMeta().get(minecraftVersion)).isPresent()) { + + forgeLoader.versionMeta().get(minecraftVersion).forEach(forgeVersion -> { + + if (forgeLoader.instanceMeta().get(minecraftVersion + "-" + forgeVersion) != null) { + list.add(forgeLoader.instanceMeta().get(minecraftVersion + "-" + forgeVersion)); + } + + }); + + return Optional.of(list); + + } else { + return Optional.empty(); + } + } + + /** + * Latest Forge version for a given Minecraft version, wrapped in {@link Optional} + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @return {@link String} Latest Forge version for the given Minecraft version, wrapped in an {@link Optional} + */ + public Optional<String> latestForgeVersion(String minecraftVersion) { + if (!checkMinecraftVersion(minecraftVersion)) { + return Optional.empty(); + } + return Optional.of(getForgeVersions(minecraftVersion, Type.ASCENDING).get().get( + getForgeVersions(minecraftVersion, Type.ASCENDING).get().size() - 1 + )); + } + + /** + * Oldest Forge version for a given Minecraft version, wrapped in {@link Optional} + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @return {@link String} Oldest Forge version for the given Minecraft version, wrapped in {@link Optional} + */ + public Optional<String> oldestForgeVersion(String minecraftVersion) { + if (!checkMinecraftVersion(minecraftVersion)) { + return Optional.empty(); + } + return Optional.ofNullable(getForgeVersions(minecraftVersion, Type.ASCENDING).get().get(0)); + } + + /** + * Get the list of Forge supported Minecraft versions, in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-list Forge supported Minecraft versions, in ascending order. + */ + public List<String> minecraftVersionsAscending() { + return supportedMinecraftVersionsList(Type.ASCENDING); + } + + /** + * Get the list of Forge supported Minecraft versions, in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-list Forge supported Minecraft versions, in descending order. + */ + public List<String> minecraftVersionsDescending() { + return supportedMinecraftVersionsList(Type.DESCENDING); + } + + /** + * Get the array of Forge supported Minecraft versions, in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-array Forge supported Minecraft versions, in descending order. + */ + public String[] minecraftVersionsArrayAscending() { + return supportedMinecraftVersionsList(Type.ASCENDING).toArray(new String[0]); + } + + /** + * Get the array of Forge supported Minecraft versions, in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-array Forge supported Minecraft versions, in descending order. + */ + public String[] minecraftVersionsArrayDescending() { + return supportedMinecraftVersionsList(Type.DESCENDING).toArray(new String[0]); + } + + /** + * Get the list of available Forge versions, in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-list Available Forge versions. + */ + public List<String> forgeVersions() { + return supportedForgeVersionsList(Type.ASCENDING); + } + + /** + * Get the list of available Forge versions, in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-list Available Forge versions. + */ + public List<String> forgeVersionsDescending() { + return supportedForgeVersionsList(Type.DESCENDING); + } + + /** + * Get the array of available Forge versions, in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-array Available Forge versions. + */ + public String[] forgeVersionsArray() { + return supportedForgeVersionsList(Type.ASCENDING).toArray(new String[0]); + } + + /** + * Get the array of available Forge versions, in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-array Available Forge versions. + */ + public String[] forgeVersionsArrayDescending() { + return supportedForgeVersionsList(Type.DESCENDING).toArray(new String[0]); + } + + /** + * Get a list of available Forge version for a given Minecraft version, in {@link Type#ASCENDING} order, wrapped in an {@link Optional}. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @return {@link String}-list of available Forge versions for the given Minecraft version, in ascending order, wrapped in an {@link Optional} + */ + public Optional<List<String>> availableForgeVersionsAscending(String minecraftVersion) { + return getForgeVersions(minecraftVersion,Type.ASCENDING); + } + + /** + * Get a list of available Forge version for a given Minecraft version, in {@link Type#DESCENDING} order, wrapped in an {@link Optional}. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @return {@link String}-list of available Forge versions for the given Minecraft version, in descending order, wrapped in an {@link Optional} + */ + public Optional<List<String>> availableForgeVersionsDescending(String minecraftVersion) { + return getForgeVersions(minecraftVersion,Type.DESCENDING); + } + + /** + * Get an array of available Forge version for a given Minecraft version, in {@link Type#ASCENDING} order, wrapped in an {@link Optional}. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @return {@link String}-array of available Forge versions for the given Minecraft version, in ascending order, wrapped in an {@link Optional} + */ + public Optional<String[]> availableForgeVersionsArrayAscending(String minecraftVersion) { + return getForgeVersionsArray(minecraftVersion,Type.ASCENDING); + } + + /** + * Get an array of available Forge version for a given Minecraft version, in {@link Type#DESCENDING} order, wrapped in an {@link Optional}. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @return {@link String}-array of available Forge versions for the given Minecraft version, in descending order, wrapped in an {@link Optional} + */ + public Optional<String[]> availableForgeVersionsArrayDescending(String minecraftVersion) { + return getForgeVersionsArray(minecraftVersion, Type.DESCENDING); + } + + /** + * Get the Forge server installer URL for a given Forge version, wrapped in an {@link Optional}. + * @author Griefed + * @param forgeVersion {@link String} Forge version. + * @return {@link URL} Forge server installer URL for the given Forge version, wrapped in an {@link Optional}. + */ + public Optional<URL> installerUrl(String forgeVersion) { + if (!checkForgeVersion(forgeVersion)) { + return Optional.empty(); + } + return Optional.ofNullable(getForgeInstance(forgeVersion).get().installerUrl()); + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftClient.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftClient.java new file mode 100644 index 0000000000000000000000000000000000000000..7f26328179bb8e16706581aecbf02ab79d1faf9e --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftClient.java @@ -0,0 +1,126 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta.minecraft; + +import de.griefed.serverpackcreator.versionmeta.Type; +import de.griefed.serverpackcreator.versionmeta.forge.ForgeInstance; +import de.griefed.serverpackcreator.versionmeta.forge.ForgeMeta; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.net.URL; +import java.util.List; +import java.util.Optional; + +/** + * Relevant information about a given Minecraft client. + * @author Griefed + */ +public class MinecraftClient { + + private static final Logger LOG = LogManager.getLogger(MinecraftClient.class); + + private final String VERSION; + private final Type TYPE; + private final URL URL; + private final MinecraftServer MINECRAFT_SERVER; + private ForgeMeta FORGE_META; + + /** + * Constructor using version, type and url. + * @author Griefed + * @param version {@link String} The Minecraft version. + * @param type {@link Type} Either {@link Type#RELEASE} or {@link Type#SNAPSHOT}. + * @param url {@link URL} Url to this versions manifest. + * @param forgeMeta {@link ForgeMeta} to acquire Forge instances for this {@link MinecraftClient} version. + */ + protected MinecraftClient(String version, Type type, URL url, ForgeMeta forgeMeta) { + this.VERSION = version; + this.TYPE = type; + this.URL = url; + this.FORGE_META = forgeMeta; + + MinecraftServer minecraftServer = null; + try { + minecraftServer = new MinecraftServer(version, type, url); + } catch (Exception ex) { + LOG.debug("No server available for Minecraft version " + this.VERSION); + } finally { + this.MINECRAFT_SERVER = minecraftServer; + } + } + + /** + * Constructor using version, type, url and a {@link MinecraftServer}. + * @author Griefed + * @param version {@link String} The Minecraft version. + * @param type {@link Type} Either {@link Type#RELEASE} or {@link Type#SNAPSHOT}. + * @param url {@link URL} Url to this versions manifest. + * @param server Instance of {@link MinecraftServer} + * @param forgeMeta {@link ForgeMeta} to acquire Forge instances for this {@link MinecraftClient} version. + */ + protected MinecraftClient(String version, Type type, URL url, MinecraftServer server, ForgeMeta forgeMeta) { + this.VERSION = version; + this.TYPE = type; + this.URL = url; + this.MINECRAFT_SERVER = server; + this.FORGE_META = forgeMeta; + } + + /** + * The Minecraft version of this {@link MinecraftClient} instance. + * @author Griefed + * @return {@link String} Minecraft version. + */ + public String version() { + return VERSION; + } + + /** + * Release-type. Either {@link Type#RELEASE} or {@link Type#SNAPSHOT}. + * @author Griefed + * @return {@link Type} Either {@link Type#RELEASE} or {@link Type#SNAPSHOT}. + */ + public Type type() { + return TYPE; + } + + /** + * The {@link URL} to this versions manifest. + * @author Griefed + * @return {@link URL} + */ + public URL url() { + return URL; + } + + /** + * The {@link MinecraftServer} for this Minecraft version, wrapped in an {@link Optional}. + * @author Griefed + * @return {@link MinecraftServer} wrapped in an {@link Optional} + */ + public Optional<MinecraftServer> server() { + return Optional.ofNullable(MINECRAFT_SERVER); + } + + public Optional<List<ForgeInstance>> forge() { + return FORGE_META.getForgeInstances(VERSION); + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftClientMeta.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftClientMeta.java new file mode 100644 index 0000000000000000000000000000000000000000..65fe91e45f0e785ec85bbf0bf9abc94c1d217c03 --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftClientMeta.java @@ -0,0 +1,180 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta.minecraft; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import de.griefed.serverpackcreator.ApplicationProperties; +import de.griefed.serverpackcreator.versionmeta.Type; +import de.griefed.serverpackcreator.versionmeta.forge.ForgeMeta; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * Minecraft client meta containing informatiom about available Minecraft releases. + * @author Griefed + */ +public class MinecraftClientMeta { + + private static final Logger LOG = LogManager.getLogger(MinecraftClientMeta.class); + private final ObjectMapper OBJECTMAPPER = new ObjectMapper() + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + private final ForgeMeta FORGE_META; + private final ApplicationProperties APPLICATIONPROPERTIES; + private final List<MinecraftClient> RELEASES = new ArrayList<>(); + private final List<MinecraftClient> SNAPSHOTS = new ArrayList<>(); + + private MinecraftClient latestRelease; + private MinecraftClient latestSnapshot; + private HashMap<String, MinecraftClient> meta = new HashMap<>(); + + /** + * Constructor. + * @author Griefed + * @param injectedForgeMeta {@link ForgeMeta} to acquire Forge instances for this {@link MinecraftClient} version. + * @param injectedApplicationProperties Instance of {@link ApplicationProperties}. + */ + protected MinecraftClientMeta(ApplicationProperties injectedApplicationProperties, ForgeMeta injectedForgeMeta) { + this.APPLICATIONPROPERTIES = injectedApplicationProperties; + this.FORGE_META = injectedForgeMeta; + } + + /** + * Update the meta information. + * @author Griefed + * @return This instance of {@link MinecraftClientMeta} + * @throws IOException if the manifest could not be read. + */ + protected MinecraftClientMeta update() throws IOException { + + RELEASES.clear(); + SNAPSHOTS.clear(); + meta = new HashMap<>(); + + JsonNode minecraftManifest = OBJECTMAPPER.readTree(APPLICATIONPROPERTIES.PATH_FILE_MANIFEST_MINECRAFT); + + minecraftManifest.get("versions").forEach(minecraftVersion -> { + + if (minecraftVersion.get("type").asText().equalsIgnoreCase("release")) { + + try { + RELEASES.add(new MinecraftClient( + minecraftVersion.get("id").asText(), + Type.RELEASE, + new URL(minecraftVersion.get("url").asText()), + this.FORGE_META + )); + } catch (IOException ex) { + LOG.debug("No server available for MinecraftClient version " + minecraftVersion.get("id").asText(), ex); + } + + } else if (minecraftVersion.get("type").asText().equalsIgnoreCase("snapshot")) { + + try { + SNAPSHOTS.add(new MinecraftClient( + minecraftVersion.get("id").asText(), + Type.SNAPSHOT, + new URL(minecraftVersion.get("url").asText()), + this.FORGE_META + )); + } catch (IOException ex) { + LOG.debug("No server available for MinecraftClient version " + minecraftVersion.get("id").asText(), ex); + } + } + + }); + + RELEASES.forEach(minecraftClient -> meta.put(minecraftClient.version(), minecraftClient)); + SNAPSHOTS.forEach(minecraftClient -> meta.put(minecraftClient.version(), minecraftClient)); + + this.latestRelease = new MinecraftClient( + minecraftManifest.get("latest").get("release").asText(), + Type.RELEASE, + meta.get(minecraftManifest.get("latest").get("release").asText()).url(), + meta.get(minecraftManifest.get("latest").get("release").asText()).server().get(), + this.FORGE_META + ); + this.latestSnapshot = new MinecraftClient( + minecraftManifest.get("latest").get("snapshot").asText(), + Type.SNAPSHOT, + meta.get(minecraftManifest.get("latest").get("snapshot").asText()).url(), + meta.get(minecraftManifest.get("latest").get("snapshot").asText()).server().get(), + this.FORGE_META + ); + + return this; + } + + /** + * Get a list of {@link MinecraftClient} of the {@link Type#RELEASE}. + * @author Griefed + * @return {@link MinecraftClient}-list of the {@link Type#RELEASE}. + */ + protected List<MinecraftClient> releases() { + return RELEASES; + } + + /** + * Get a list of {@link MinecraftClient} of the {@link Type#SNAPSHOT}. + * @author Griefed + * @return {@link MinecraftClient}-list of the {@link Type#SNAPSHOT}. + */ + protected List<MinecraftClient> snapshots() { + return SNAPSHOTS; + } + + /** + * Get the latest Minecraft {@link Type#RELEASE} as a {@link MinecraftClient}. + * @author Griefed + * @return {@link MinecraftClient} {@link Type#RELEASE} as a {@link MinecraftClient} + */ + protected MinecraftClient latestRelease() { + return latestRelease; + } + + /** + * Get the latest Minecraft {@link Type#SNAPSHOT} as a {@link MinecraftClient}. + * @author Griefed + * @return {@link MinecraftClient} {@link Type#SNAPSHOT} as a {@link MinecraftClient} + */ + protected MinecraftClient latestSnapshot() { + return latestSnapshot; + } + + /** + * Get the {@link MinecraftClient} meta.<br> + * key: {@link String} Minecraft version<br> + * value: {@link MinecraftClient} for said Minecraft version + * @author Griefed + * @return {@link HashMap} containing the {@link MinecraftClientMeta}. + */ + protected HashMap<String, MinecraftClient> meta() { + return meta; + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftMeta.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftMeta.java new file mode 100644 index 0000000000000000000000000000000000000000..4cbf7f6d3eb8a21996fe9cae17973c013fe356dd --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftMeta.java @@ -0,0 +1,381 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta.minecraft; + +import com.google.common.collect.Lists; +import de.griefed.serverpackcreator.ApplicationProperties; +import de.griefed.serverpackcreator.versionmeta.Type; +import de.griefed.serverpackcreator.versionmeta.forge.ForgeMeta; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * Minecraft meta containing information about available client- and server releases. + * @author Griefed + */ +public class MinecraftMeta { + + private final MinecraftClientMeta MINECRAFT_CLIENT_META; + private final MinecraftServerMeta MINECRAFT_SERVER_META; + + /** + * Constructor. + * @author Griefed + * @param injectedApplicationProperties Instance of {@link ApplicationProperties}. + * @param injectedForgeMeta {@link ForgeMeta} to acquire Forge instances for this {@link MinecraftClient} version. + */ + public MinecraftMeta(ApplicationProperties injectedApplicationProperties, ForgeMeta injectedForgeMeta) { + this.MINECRAFT_CLIENT_META = new MinecraftClientMeta(injectedApplicationProperties, injectedForgeMeta); + this.MINECRAFT_SERVER_META = new MinecraftServerMeta(this.MINECRAFT_CLIENT_META); + } + + /** + * Update the {@link MinecraftClientMeta} and {@link MinecraftServerMeta}. Usually called after the manifest-files + * have been refreshed. + * @author Griefed + * @return This instance of {@link MinecraftMeta}. + * @throws IOException if the {@link MinecraftClientMeta} could not be initialized. + */ + public MinecraftMeta update() throws IOException { + this.MINECRAFT_CLIENT_META.update(); + this.MINECRAFT_SERVER_META.update(); + return this; + } + +/* + * #==============================================================================================================# + * #..............................................................................................................# + * #...................................................STRINGS....................................................# + * #..............................................................................................................# + * #==============================================================================================================# + */ + /** + * Check whether a {@link MinecraftClient} is available for the specified Minecraft-version. + * @author Griefed + * @param minecraftVersion {@link String} The Minecraft-version. + * @return {@link Boolean} <code>true</code> if a {@link MinecraftClient} is available. + */ + public boolean checkMinecraftVersion(String minecraftVersion) { + return getClient(minecraftVersion).isPresent(); + } + + /** + * Get the list of available Minecraft version of the {@link Type#RELEASE} in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-list of all available Minecraft {@link Type#RELEASE} versions in {@link Type#DESCENDING} order. + */ + public List<String> releaseVersionsDescending() { + List<String> list = new ArrayList<>(); + releasesDescending().forEach(client -> list.add(client.version())); + return list; + } + + /** + * Get the list of available Minecraft version of the {@link Type#RELEASE} in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-list of all available Minecraft {@link Type#RELEASE} versions in {@link Type#ASCENDING} order. + */ + public List<String> releaseVersionsAscending() { + List<String> list = new ArrayList<>(); + releasesDescending().forEach(client -> list.add(client.version())); + return Lists.reverse(list); + } + + /** + * Get the array of available Minecraft version of the {@link Type#RELEASE} in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-array of all available Minecraft {@link Type#RELEASE} versions in {@link Type#DESCENDING} order. + */ + public String[] releaseVersionsArrayDescending() { + return releaseVersionsDescending().toArray(new String[0]); + } + + /** + * Get the array of available Minecraft version of the {@link Type#RELEASE} in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-array of all available Minecraft {@link Type#RELEASE} versions in {@link Type#ASCENDING} order. + */ + public String[] releaseVersionsArrayAscending() { + return releaseVersionsAscending().toArray(new String[0]); + } + + /** + * Get the list of available Minecraft version of the {@link Type#SNAPSHOT} in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-list of all available Minecraft {@link Type#SNAPSHOT} versions in {@link Type#DESCENDING} order. + */ + public List<String> snapshotsVersionsDescending() { + List<String> list = new ArrayList<>(); + snapshotsDescending().forEach(client -> list.add(client.version())); + return list; + } + + /** + * Get the list of available Minecraft version of the {@link Type#SNAPSHOT} in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-list of all available Minecraft {@link Type#SNAPSHOT} versions in {@link Type#ASCENDING} order. + */ + public List<String> snapshotVersionsAscending() { + List<String> list = new ArrayList<>(); + snapshotsDescending().forEach(client -> list.add(client.version())); + return Lists.reverse(list); + } + + /** + * Get the array of available Minecraft version of the {@link Type#SNAPSHOT} in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link String}-array of all available Minecraft {@link Type#SNAPSHOT} versions in {@link Type#DESCENDING} order. + */ + public String[] snapshotVersionsArrayDescending() { + return snapshotsVersionsDescending().toArray(new String[0]); + } + + /** + * Get the array of available Minecraft version of the {@link Type#SNAPSHOT} in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link String}-array of all available Minecraft {@link Type#SNAPSHOT} versions in {@link Type#ASCENDING} order. + */ + public String[] snapshotVersionsArrayAscending() { + return snapshotVersionsAscending().toArray(new String[0]); + } + +/* + * #==============================================================================================================# + * #..............................................................................................................# + * #...................................................CLIENTS....................................................# + * #..............................................................................................................# + * #==============================================================================================================# + */ + /** + * Get the latest Minecraft release as a {@link MinecraftClient}. + * @author Griefed + * @return {@link MinecraftClient} + */ + public MinecraftClient latestRelease() { + return MINECRAFT_CLIENT_META.latestRelease(); + } + + /** + * Get the latest Minecraft snapshot as a {@link MinecraftClient}. + * @author Griefed + * @return {@link MinecraftClient} + */ + public MinecraftClient latestSnapshot() { + return MINECRAFT_CLIENT_META.latestSnapshot(); + } + + /** + * Get a specific Minecraft client as a {@link MinecraftClient} wrapped in an {@link Optional}. + * @author Griefed + * @param minecraftVersion {@link String} Minecraft version. + * @return {@link MinecraftClient} wrapped in an {@link Optional} + */ + public Optional<MinecraftClient> getClient(String minecraftVersion) { + return Optional.ofNullable(MINECRAFT_CLIENT_META.meta().get(minecraftVersion)); + } + + /** + * Get a list of all available {@link MinecraftClient} of the {@link Type#RELEASE}, in ascending order. + * @author Griefed + * @return {@link MinecraftClient}-list + */ + public List<MinecraftClient> releasesDescending() { + return MINECRAFT_CLIENT_META.releases(); + } + + /** + * Get a list of all available {@link MinecraftClient} of the {@link Type#RELEASE}, in descending order. + * @author Griefed + * @return {@link MinecraftClient}-list + */ + public List<MinecraftClient> releasesAscending() { + return Lists.reverse(MINECRAFT_CLIENT_META.releases()); + } + + /** + * Get an array of all available {@link MinecraftClient} of the {@link Type#RELEASE}, in ascending order. + * @author Griefed + * @return {@link MinecraftClient}-array + */ + public MinecraftClient[] releasesArrayDescending() { + return releasesDescending().toArray(new MinecraftClient[0]); + } + + /** + * Get an array of all available {@link MinecraftClient} of the {@link Type#RELEASE}, in descending order. + * @author Griefed + * @return {@link MinecraftClient}-array + */ + public MinecraftClient[] releasesArrayAscending() { + return releasesAscending().toArray(new MinecraftClient[0]); + } + + /** + * Get a list of all available {@link MinecraftClient} of the {@link Type#SNAPSHOT}, in ascending order. + * @author Griefed + * @return {@link MinecraftClient}-list + */ + public List<MinecraftClient> snapshotsDescending() { + return MINECRAFT_CLIENT_META.snapshots(); + } + + /** + * Get a list of all available {@link MinecraftClient} of the {@link Type#SNAPSHOT}, in descending order. + * @author Griefed + * @return {@link MinecraftClient}-list + */ + public List<MinecraftClient> snapshotsAscending() { + return Lists.reverse(MINECRAFT_CLIENT_META.snapshots()); + } + + /** + * Get an array of all available {@link MinecraftClient} of the {@link Type#SNAPSHOT}, in ascending order. + * @author Griefed + * @return {@link MinecraftClient}-array + */ + public MinecraftClient[] snapshotsArrayDescending() { + return snapshotsDescending().toArray(new MinecraftClient[0]); + } + + /** + * Get an array of all available {@link MinecraftClient} of the {@link Type#SNAPSHOT}, in descending order. + * @author Griefed + * @return {@link MinecraftClient}-array + */ + public MinecraftClient[] snapshotsArrayAscending() { + return snapshotsAscending().toArray(new MinecraftClient[0]); + } + + /* + * #==============================================================================================================# + * #..............................................................................................................# + * #...................................................SERVERS....................................................# + * #..............................................................................................................# + * #==============================================================================================================# + */ + /** + * Get a specific {@link MinecraftServer} for the specified Minecraft-version, wrapped in an {@link Optional}. + * @author Griefed + * @param minecraftVersion {@link String} The Minecraft-version. + * @return {@link MinecraftServer} wrapped in an {@link Optional} + */ + public Optional<MinecraftServer> getServer(String minecraftVersion) { + return Optional.ofNullable(MINECRAFT_SERVER_META.meta().get(minecraftVersion)); + } + + /** + * Check whether a {@link MinecraftServer} is available for the specified Minecraft-version. + * @author Griefed + * @param minecraftVersion {@link String} The Minecraft-version. + * @return {@link Boolean} <code>true</code> if a {@link MinecraftServer} is available. + */ + public boolean checkServerAvailability(String minecraftVersion) { + return getServer(minecraftVersion).isPresent(); + } + + /** + * Get the latest {@link MinecraftServer} of the {@link Type#RELEASE}, wrapped in an {@link Optional}. + * @author Griefed + * @return {@link MinecraftServer} wrapped in an {@link Optional} + */ + public Optional<MinecraftServer> latestReleaseServer() { + return MINECRAFT_CLIENT_META.latestRelease().server(); + } + + /** + * Get the latest {@link MinecraftServer} of the {@link Type#SNAPSHOT}, wrapped in an {@link Optional}. + * @author Griefed + * @return {@link MinecraftServer} wrapped in an {@link Optional} + */ + public Optional<MinecraftServer> latestSnapshotServer() { + return MINECRAFT_CLIENT_META.latestSnapshot().server(); + } + + /** + * Get a list of all available {@link MinecraftServer} of the {@link Type#RELEASE}, in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link MinecraftServer}-list + */ + public List<MinecraftServer> releasesServersDescending() { + return MINECRAFT_SERVER_META.releases(); + } + + /** + * Get a list of all available {@link MinecraftServer} of the {@link Type#RELEASE}, in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link MinecraftServer}-list + */ + public List<MinecraftServer> releasesServersAscending() {return Lists.reverse(MINECRAFT_SERVER_META.releases()); + } + + /** + * Get an array of all available {@link MinecraftServer} of the {@link Type#RELEASE}, in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link MinecraftServer}-array + */ + public MinecraftServer[] releasesServersArrayDescending() { + return releasesServersDescending().toArray(new MinecraftServer[0]); + } + + /** + * Get an array of all available {@link MinecraftServer} of the {@link Type#RELEASE}, in {@link Type#ASCENDING} order. + * @author Griefed + * @return {@link MinecraftServer}-array + */ + public MinecraftServer[] releasesServersArrayAscending() {return releasesServersAscending().toArray(new MinecraftServer[0]); + } + + /** + * Get a list of all available {@link MinecraftServer} of the {@link Type#SNAPSHOT}, in {@link Type#DESCENDING} order. + * @author Griefed + * @return {@link MinecraftServer}-list + */ + public List<MinecraftServer> snapshotsServersDescending() { + return MINECRAFT_SERVER_META.snapshots(); + } + + /** + * Get a list of all available {@link MinecraftServer} of the {@link Type#SNAPSHOT}, in descending order. + * @author Griefed + * @return {@link MinecraftServer}-list + */ + public List<MinecraftServer> snapshotsServersAscending() {return Lists.reverse(MINECRAFT_SERVER_META.snapshots()); + } + + /** + * Get an array of all available {@link MinecraftServer} of the {@link Type#SNAPSHOT}, in ascending order. + * @author Griefed + * @return {@link MinecraftServer}-array + */ + public MinecraftServer[] snapshotsServersArrayDescending() { + return snapshotsServersDescending().toArray(new MinecraftServer[0]); + } + + /** + * Get an array of all available {@link MinecraftServer} of the {@link Type#SNAPSHOT}, in descending order. + * @author Griefed + * @return {@link MinecraftServer}-array + */ + public MinecraftServer[] snapshotsServersArrayAscending() {return snapshotsServersAscending().toArray(new MinecraftServer[0]); + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftServer.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftServer.java new file mode 100644 index 0000000000000000000000000000000000000000..6ff5ebac61b1d8b5d0df07a655ce29e6e8f90838 --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftServer.java @@ -0,0 +1,100 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta.minecraft; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import de.griefed.serverpackcreator.versionmeta.Type; + +import java.net.URL; + +/** + * Representation of a Minecraft server, containing information about its Minecraft-version, release-type, download-url + * and the java-version. + * @author Griefed + */ +public class MinecraftServer { + + private final String VERSION; + private final Type TYPE; + private final URL URL; + private final byte JAVA_VERSION; + + /** + * Constructor + * @author Griefed + * @param mcVersion {@link String} The Minecraft version of this server. + * @param mcType {@link Type} The release-type of this server. Either {@link Type#RELEASE} or {@link Type#SNAPSHOT}. + * @param mcUrl {@link URL} The URL to the download of this servers JAR-file. + * @throws Exception if the servers manifest could not be acquired, the download URL could not be parsed, or the + * Java-version could not be parsed. + */ + protected MinecraftServer(String mcVersion, Type mcType, URL mcUrl) throws Exception { + + this.VERSION = mcVersion; + this.TYPE = mcType; + + JsonNode serverJson = new ObjectMapper() + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) + .readTree(mcUrl.openStream()); + + this.URL = new URL(serverJson.get("downloads").get("server").get("url").asText()); + this.JAVA_VERSION = Byte.parseByte(serverJson.get("javaVersion").get("majorVersion").asText()); + + } + + /** + * Get the Minecraft-version of this {@link MinecraftServer}. + * @author Griefed + * @return {@link String} + */ + public String version() { + return VERSION; + } + + /** + * Get the release-type of this Minecraft-server. Either {@link Type#RELEASE} or {@link Type#SNAPSHOT}. + * @author Griefed + * @return {@link Type} + */ + public Type type() { + return TYPE; + } + + /** + * Get the {@link URL} to the download of this Minecraft-servers JAR-file. + * @author Griefed + * @return {@link URL} + */ + public URL url() { + return URL; + } + + /** + * Get the Java-version of this Minecraft-server. + * @author Griefed + * @return {@link Byte}. + */ + public byte javaVersion() { + return JAVA_VERSION; + } +} diff --git a/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftServerMeta.java b/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftServerMeta.java new file mode 100644 index 0000000000000000000000000000000000000000..8a4ad5323f47b0d066628df5fed697fa8c38653f --- /dev/null +++ b/backend/main/java/de/griefed/serverpackcreator/versionmeta/minecraft/MinecraftServerMeta.java @@ -0,0 +1,112 @@ +/* Copyright (C) 2022 Griefed + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE + */ +package de.griefed.serverpackcreator.versionmeta.minecraft; + +import de.griefed.serverpackcreator.versionmeta.Type; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * Meta containing information about Minecraft servers. + * @author Griefed + */ +class MinecraftServerMeta { + + private final MinecraftClientMeta MINECRAFT_CLIENT_META; + private final List<MinecraftServer> RELEASES = new ArrayList<>(); + private final List<MinecraftServer> SNAPSHOTS = new ArrayList<>(); + private HashMap<String, MinecraftServer> meta; + + /** + * Constructor. + * @author Griefed + * @param minecraftClientMeta Instance of {@link MinecraftClientMeta}. + */ + protected MinecraftServerMeta(MinecraftClientMeta minecraftClientMeta) { + this.MINECRAFT_CLIENT_META = minecraftClientMeta; + } + + /** + * Update this instance of {@link MinecraftServerMeta} with new information. + * @author Griefed + * @return This instance of {@link MinecraftServerMeta}. + */ + protected MinecraftServerMeta update() { + + this.RELEASES.clear(); + MINECRAFT_CLIENT_META.releases().forEach(client -> { + if (client.server().isPresent()) { + this.RELEASES.add(client.server().get()); + } + }); + + this.SNAPSHOTS.clear(); + MINECRAFT_CLIENT_META.snapshots().forEach(client -> { + if (client.server().isPresent()) { + this.SNAPSHOTS.add(client.server().get()); + } + }); + + this.meta = new HashMap<>(); + MINECRAFT_CLIENT_META.releases().forEach(client -> { + if (client.server().isPresent()) { + this.meta.put(client.version(), client.server().get()); + } + }); + MINECRAFT_CLIENT_META.snapshots().forEach(client -> { + if (client.server().isPresent()) { + this.meta.put(client.version(), client.server().get()); + } + }); + + return this; + } + + /** + * Get a list of {@link MinecraftServer} of the {@link Type#RELEASE}. + * @author Griefed + * @return {@link MinecraftServer}-list of the {@link Type#RELEASE}. + */ + protected List<MinecraftServer> releases() { + return RELEASES; + } + + /** + * Get a list of {@link MinecraftServer} of the {@link Type#SNAPSHOT}. + * @author Griefed + * @return {@link MinecraftServer}-list of the {@link Type#SNAPSHOT}. + */ + protected List<MinecraftServer> snapshots() { + return SNAPSHOTS; + } + + /** + * Get the {@link MinecraftServer} meta.<br> + * key: {@link String} Minecraft version<br> + * value: {@link MinecraftServer} for said Minecraft version + * @author Griefed + * @return {@link HashMap} containing the {@link MinecraftServerMeta}. + */ + protected HashMap<String, MinecraftServer> meta() { + return meta; + } +} \ No newline at end of file diff --git a/backend/main/resources/README.md b/backend/main/resources/README.md index 35f1f66a165e52487ba60bbee250e4fdd8847e9d..9d2007aebf7831166b22f0079474b83dd74e001c 100644 --- a/backend/main/resources/README.md +++ b/backend/main/resources/README.md @@ -119,7 +119,7 @@ Huge shoutout and thank you!** - A list of known issues can be found in [Known Issues](https://github.com/Griefed/ServerPackCreator/issues/55). -- If you want to report an issue, please make sure to follow the templates on [GitHub](https://github.com/Griefed/ServerPackCreator/issues/new/choose) and **provide as much information as detailed as possible**. The more information and details you provide for your issue at hand, the easier it is for me to investigate it! +- If you want to report an issue, please make sure to follow the templates on [GitHub](https://github.com/Griefed/ServerPackCreator/issues/new/choose) and **provide as much information as detailed as possible**. The more information and details you provide for your issue at hand, the easier it is for me to investigate it! - A wiki article containing useful hints, tips & tricks about, for and with ServerPackCreator can be found on [my Wiki's ServerPackCreator Help page](https://wiki.griefed.de/en/Documentation/ServerPackCreator/ServerPackCreator-Help) @@ -128,26 +128,26 @@ Huge shoutout and thank you!** 1. **Generate a config step-by-step by running with argument**`-cgen` 2. **Install a Forge or Fabric modloader server in your server pack** 3. **Configurable list of clientside-only mods to not include your server pack** - 1. Allow ServerPackCreator to automatically detect clientside-only mods by setting `de.griefed.serverpackcreator.serverpack.autodiscoverenabled=true` in `serverpackcreator.properties`. + 1. Allow ServerPackCreator to automatically detect clientside-only mods by setting `de.griefed.serverpackcreator.serverpack.autodiscoverenabled=true` in `serverpackcreator.properties`. 4. **Configurable list of directories from your modpack to include in your server pack** - 1. Copy saves. Specify `saves/world` and it will result in the world being copied to `your_server_pack/world`. - 2. Copy specific files. Specify `source/path/to/some.file;some/folder/destination.file` and `source/path/to/some.file` will be copied to `some/folder/destination.file` inside the server pack. - 3. Exclude files and directories. Prefixing an entry with `!` or adding it to `de.griefed.serverpackcreator.configuration.copydirs.exclude=` in `serverpackcreator.properties` will result in that file or directory not being copied to the server pack. - 4. Lazy-Mode. Only specify `lazy_mode` and **nothing** else, and the whole modpack you specified will be copied to the server pack. Be warned though that configurations using this will receive no support from me. If the generated server pack errors, it is up to you to fix it. + 1. Copy saves. Specify `saves/world` and it will result in the world being copied to `your_server_pack/world`. + 2. Copy specific files. Specify `source/path/to/some.file;some/folder/destination.file` and `source/path/to/some.file` will be copied to `some/folder/destination.file` inside the server pack. + 3. Exclude files and directories. Prefixing an entry with `!` or adding it to `de.griefed.serverpackcreator.configuration.copydirs.exclude=` in `serverpackcreator.properties` will result in that file or directory not being copied to the server pack. + 4. Lazy-Mode. Only specify `lazy_mode` and **nothing** else, and the whole modpack you specified will be copied to the server pack. Be warned though that configurations using this will receive no support from me. If the generated server pack errors, it is up to you to fix it. 5. **Generate Forge or Fabric start-scripts in your server pack** - 1. Specify JVM flags / Java Args for your start scripts! + 1. Specify JVM flags / Java Args for your start scripts! 6. **Include a server-icon.png-file in your server pack** - 1. Replace the file in `server-files` with your own! + 1. Replace the file in `server-files` with your own! 7. **Include a server.properties-file in your server pack** - 1. Replace the file in `server-files` with your own! + 1. Replace the file in `server-files` with your own! 8. **Create a ZIP-archive of your server pack** 9. **GUI to fully configure and run ServerPackCreator** - 1. Load existing config. - 2. Browse local filesystem to select modpack directory, clientside-only mods, directories to include in server pack, Java executable/binary. - 3. Logs from last run in separate tabs. - 4. Set a suffix for the server pack to be generated. - 5. And much more! -10. **Webservice** + 1. Load existing config. + 2. Browse local filesystem to select modpack directory, clientside-only mods, directories to include in server pack, Java executable/binary. + 3. Logs from last run in separate tabs. + 4. Set a suffix for the server pack to be generated. + 5. And much more! +10. **Webservice** 1. Generate a server pack from zipped up modpacks. 2. All generated server packs available for download to everyone. 11. **Addons!** @@ -201,15 +201,15 @@ Some examples for potential addons can be found [in this discussion thread](http Some excerpts: 1. Changelog generator, by @TheButterbrotMan at [Feature request]: Changelog generator #198 - - A changelog generator that checks the differences to the previous version and generates a changelog. + - A changelog generator that checks the differences to the previous version and generates a changelog. 2. Bundle Adoptium Java with server packs, by @kreezxil at [Feature request]: Bundle Adoptium Java #199 - - Because modpacks need one of the either Java 8, 16, or 17, it would be nice to have the corresponding https://adoptium.net java prebundled with the server pack. + - Because modpacks need one of the either Java 8, 16, or 17, it would be nice to have the corresponding https://adoptium.net java prebundled with the server pack. 3. Automatic setup of a server pack for [BlueMap](https://www.curseforge.com/minecraft/mc-mods/bluemap) - - Check all mods in the specified modpacks mods-directory for textures, and if any are found, add the mod to - BlueMap's resourcepack folder `config/bluemap/resourcepacks`, install BlueMap for the specified Minecraft and Forge/Fabric - version and voilà ! + - Check all mods in the specified modpacks mods-directory for textures, and if any are found, add the mod to + BlueMap's resourcepack folder `config/bluemap/resourcepacks`, install BlueMap for the specified Minecraft and Forge/Fabric + version and voilà ! # 5. Configuration @@ -260,6 +260,7 @@ After checking the configuration, run ServerPackCreator again, and it'll do it's ```properties de.griefed.serverpackcreator.versioncheck.prerelease=false de.griefed.serverpackcreator.language=en_us +# Do NOT edit de.griefed.serverpackcreator.configuration.fallbackmodslist MANUALLY. You can update this from the menu in the GUI. de.griefed.serverpackcreator.configuration.fallbackmodslist=3dSkinLayers-,AdvancementPlaques-,AmbientSounds_,armorchroma-,backtools-,BetterAdvancements-,BetterAnimationsCollection-,BetterDarkMode-,BetterF3-,BetterF3-,BetterFoliage-,BetterPingDisplay-,BetterPlacement-,Blur-,catalogue-,cherishedworlds-,classicbar-,clickadv-,ClientTweaks_,configured-,Controlling-,CraftPresence-,CTM-,customdiscordrpc-,CustomMainMenu-,DefaultOptions_,defaultoptions-,desiredservers-,Ding-,drippyloadingscreen_,drippyloadingscreen-,Durability101-,dynamic-music-,DynamicSurroundings-,DynamicSurroundingsHuds-,dynmus-,EiraMoticons_,eiramoticons-,EnchantmentDescriptions-,EquipmentCompare-,extremesoundmuffler-,extremeSoundMuffler-,Fallingleaves-,fallingleaves-,fancymenu_,findme-,flickerfix-,FpsReducer-,FullscreenWindowed-,InventoryEssentials_,InventorySpam-,InventoryTweaks-,invtweaks-,ItemBorders-,itemzoom,itlt-,jeed-,jehc-,jeiintegration_,JEITweaker-,just-enough-harvestcraft-,justenoughbeacons-,JustEnoughCalculation-,JustEnoughProfessions-,JustEnoughProfessions-,JustEnoughResources-,keywizard-,konkrete_,lazydfu-,LegendaryTooltips-,light-overlay-,LightOverlay-,LLOverlayReloaded-,loadmyresources_,lootbeams-,mcbindtype-,medievalmusic-,modnametooltip_,modnametooltip-,moreoverlays-,MouseTweaks-,multihotbar-,MyServerIsCompatible-,Neat ,NotifMod-,OldJavaWarning-,OptiFine,OptiForge,ornaments-,overloadedarmorbar-,PackMenu-,PickUpNotifier-,Ping-,preciseblockplacing-,presencefootsteps-,PresenceFootsteps-,ReAuth-,ResourceLoader-,shutupexperimentalsettings-,SimpleDiscordRichPresence-,smoothboot-,sounddeviceoptions-,SpawnerFix-,spoticraft-,tconplanner-,timestamps-,Tips-,TipTheScales-,Toast Control-,Toast-Control-,ToastControl-,torchoptimizer-,torohealth-,toughnessbar-,TravelersTitles-,WindowedFullscreen-,WorldNameRandomizer-,yisthereautojump- de.griefed.serverpackcreator.configuration.hastebinserver=https://haste.zneix.eu/documents de.griefed.serverpackcreator.serverpack.autodiscoverenabled=true @@ -279,29 +280,29 @@ de.griefed.serverpackcreator.configuration.directories.mustinclude=mods,config,d de.griefed.serverpackcreator.curseforge.api.token= ``` -| Property | Description | -|------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------| -| de.griefed.serverpackcreator.versioncheck.prerelease | `true` or `false`. Whether to check for available pre-releases, too, when checking for updates. | -| de.griefed.serverpackcreator.language | The language in which ServerPackCreator should run. | -| de.griefed.serverpackcreator.configuration.fallbackmodslist | Comma separated fallback-list of clientside-only mods. | -| de.griefed.serverpackcreator.configuration.hastebinserver | Address of a HasteBin server to use for config and logs uploading. | -| de.griefed.serverpackcreator.serverpack.autodiscoverenabled | `true` or `false`. Whether to try and determine sideness of mods in a modpack automatically. | -| de.griefed.serverpackcreator.gui.darkmode | GUI-only. `true` or `false`. Whether to use dark-mode in the GUI. | -| de.griefed.serverpackcreator.configuration.directories.serverpacks | The directory in which server packs will be generated and stored in. | -| de.griefed.serverpackcreator.curseforge.cleanup.enabled | `true` or `false`. Whether to cleanup files after generating a server pack from a CurseForge project. | -| de.griefed.serverpackcreator.serverpack.cleanup.enabled | `true` or `false`. Whether to cleanup files after generating a server pack. | -| de.griefed.serverpackcreator.serverpack.overwrite.enabled | `true` or `false`. Whether an already existing server pack should be overwritten. | -| de.griefed.serverpackcreator.configuration.directories.shouldexclude | List of directories which should not be in a server pack. | -| de.griefed.serverpackcreator.spring.cursecontroller.regenerate.enabled | `true` or `false`. Web only. Whether regeneration of an already available CurseForge project server pack is allowed/enabled. | -| de.griefed.serverpackcreator.spring.schedules.database.cleanup | Web-only. Cron-schedule at which checks are run and server packs cleaned up. | -| de.griefed.serverpackcreator.spring.schedules.files.cleanup | Web-only. Cron-schedule at which checks are run and files from server pack generations are cleaned up. | -| de.griefed.serverpackcreator.spring.schedules.versions.refresh | Web-only. Cron-schedule at which the available Minecraft, Forge and Fabric versions are refreshed. | -| de.griefed.serverpackcreator.spring.artemis.queue.max_disk_usage | Web-only. Maximum disk usage in percent at which no new tasks are accepted, preventing the generation of new server packs. | -| de.griefed.serverpackcreator.configuration.saveloadedconfig | GUI-only. `true` or `false`. Whether to overwrite the last manually loaded configuration file, too. | -| de.griefed.serverpackcreator.configuration.directories.mustinclude | List of directories which must be included in a server pack. | -| de.griefed.serverpackcreator.curseforge.api.token | CurseAPI token used for generating server packs from CurseForge projects. | - -# 5.1.2 Default `application.properties` +| Property | Description | +|------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| de.griefed.serverpackcreator.versioncheck.prerelease | `true` or `false`. Whether to check for available pre-releases, too, when checking for updates. | +| de.griefed.serverpackcreator.language | The language in which ServerPackCreator should run. | +| de.griefed.serverpackcreator.configuration.fallbackmodslist | Comma separated fallback-list of clientside-only mods. Do NOT edit de.griefed.serverpackcreator.configuration.fallbackmodslist MANUALLY. You can update this from the menu in the GUI. | +| de.griefed.serverpackcreator.configuration.hastebinserver | Address of a HasteBin server to use for config and logs uploading. | +| de.griefed.serverpackcreator.serverpack.autodiscoverenabled | `true` or `false`. Whether to try and determine sideness of mods in a modpack automatically. | +| de.griefed.serverpackcreator.gui.darkmode | GUI-only. `true` or `false`. Whether to use dark-mode in the GUI. | +| de.griefed.serverpackcreator.configuration.directories.serverpacks | The directory in which server packs will be generated and stored in. | +| de.griefed.serverpackcreator.curseforge.cleanup.enabled | `true` or `false`. Whether to cleanup files after generating a server pack from a CurseForge project. | +| de.griefed.serverpackcreator.serverpack.cleanup.enabled | `true` or `false`. Whether to cleanup files after generating a server pack. | +| de.griefed.serverpackcreator.serverpack.overwrite.enabled | `true` or `false`. Whether an already existing server pack should be overwritten. | +| de.griefed.serverpackcreator.configuration.directories.shouldexclude | List of directories which should not be in a server pack. | +| de.griefed.serverpackcreator.spring.cursecontroller.regenerate.enabled | `true` or `false`. Web only. Whether regeneration of an already available CurseForge project server pack is allowed/enabled. | +| de.griefed.serverpackcreator.spring.schedules.database.cleanup | Web-only. Cron-schedule at which checks are run and server packs cleaned up. | +| de.griefed.serverpackcreator.spring.schedules.files.cleanup | Web-only. Cron-schedule at which checks are run and files from server pack generations are cleaned up. | +| de.griefed.serverpackcreator.spring.schedules.versions.refresh | Web-only. Cron-schedule at which the available Minecraft, Forge and Fabric versions are refreshed. | +| de.griefed.serverpackcreator.spring.artemis.queue.max_disk_usage | Web-only. Maximum disk usage in percent at which no new tasks are accepted, preventing the generation of new server packs. | +| de.griefed.serverpackcreator.configuration.saveloadedconfig | GUI-only. `true` or `false`. Whether to overwrite the last manually loaded configuration file, too. | +| de.griefed.serverpackcreator.configuration.directories.mustinclude | List of directories which must be included in a server pack. | +| de.griefed.serverpackcreator.curseforge.api.token | CurseAPI token used for generating server packs from CurseForge projects. | + +# 5.1.2 Default `application.properties` `application.properties` ```properties @@ -362,304 +363,13 @@ If you wish to run ServerPackCreator with your locale (if it is already supporte 2. Running `java -jar ServerPackCreator-x.x.x.jar` without `-lang en_us` or any other language will set the locale to en_us by default and create the lang.properties-file. 3. Modify the `serverpackcreator.properties`-file in the same directory as ServerPackCreator-X-X-X.jar and set your locale like this `lang=your_locale` for example `lang=en_us` -## 6.2 Using the GUI +## 6.2 Using ServerPackCreator -You want to create a server pack for your modpack, right? +**Detailed How-To guides are available at [my wiki](https://wiki.griefed.de/en/Documentation/ServerPackCreator/ServerPackCreator-HowTo)!** -There are a couple of things you need to do in order to create a server pack for your modpack: +Make sure to give them a read if you are just getting started with ServerPackCreator, or you need some help. -**1:** Find out whether any mod in your modpack is a clientside-only mod. Those are often mods which only add things to Minecraft which are of a graphical nature, like UI stuff. You need to know whether any mod in your modpack is a clientside-only mod, because having clientside-only mods in your server pack could crash your server unexpectedly. - -**2:** Find the modloader, the modloader version and which Minecraft version your modpack is for. - -**3:** Consider the folders in your modpack directory which you must inlcude in server pack in order for your server to work. Usually folders like `config` ,`mods` ,`scripts` and so on. - -Those are the most important parts in making a server pack, I find. - -If you're on Windows, go to <https://github.com/Griefed/ServerPackCreator/releases/latest> and download `serverpackcreator-X.X.X.exe` and place it somewhere you will remember. If you're on Linux or Mac, download the `serverpackcreator-X.X.X.jar` - -The .exe can be started with a regular double click. The .jar needs to be started from the CLI with `java -jar serverpackcreator-X.X.X.jar`. - -The first run of ServerPackCreator will create a couple of default files in the directory you started it in. If you plan on including any of these in your server pack, make sure you've customized them to your needs. They're in a directory called `server_files` in the same directory in which you executed `ServerPackCreator-X.X.X.jar` or `ServerPackCreator-X.X.X.exe` and will contain the following files which you can customize to your hearts content: - -- `server.properties` - -- `server-icon.png` - -Once the ServerPackCreator window opened, you need to fill in all the information you gathered in the previously mentioned steps 1 to 3 into the designated textfields. -From top to bottom: - -**Enter the path to your modpack directory:** You will also need to configure ServerPackCreator to point at the directory your modpack files are in. Click the folder icon on the right hand side to the first textfield, which will open your file explorer so you can browse to and select your modpack directory. - -**Enter the list of clientside-only mods in your modpack:** Enter the list of clientside-only mods for your modpack into the second textfield.Every entry must be separated by a "," and NOT contain special characters such as [ \] ( ) \ / ; - -**Enter the list of directories or files in your modpack to include in the server pack:** Enter the list of folders of your modpack which need to be included in your server pack. Every entry must be separated by a "," and NOT contain special characters such as [ \] ( ) \ / ; - -**Enter the path to your Java executable/binary (optional):** If you are not sure where your java installation is located at, you can leave it blank and ServerPackCreator will try to determine said path by itself. - -**Enter the Minecraft version your modpack uses:** Enter the Minecraft version your modpack runs in - -**Enter the modloader your modpack uses:** Enter the modloader your modpack runs with. Must be either Forge or Fabric. Other modloaders are not supported. - -**Enter the version of the modloader your modpack uses:** Enter the version of the modloader your modpack uses. - -Last but not least, checkboxes: - -**"Install modloader server in server pack?"** Does what it says on the tin. Whehter to install the Forge/Fabric server for the version you specified. - -**"Include server-icon.png in server pack?"** Whether to include a custom server-icon.png in your server pack. - -**"Include server.properties in server pack"** Whether to include a custom server.properties in your server pack. - -**"Include start scripts in server pack?"** Whether to include custom start scripts for your server pack. - -**"Create ZIP-archive of server pack?"** Whether ServerPackCreator should create a zipped archive of your server pack. - -**Edit JVM flags** Open the dialog for editing of your JVM flags / Java Args via Menu->Edit->Edit Start-Scripts Java Args. - -After you've customized and configured everything to your liking, click the button on the bottom. ServerPackCreator will check your configuration for errors and start generating your server pack should no errors be detected. When the server pack is finished, a prompt will open which will ask you whether you want to browse your newly created server pack in your file explorer. - -That's pretty much it! Sounds like a lot, but honestly, all the stuff you need to do in order to configure ServerPackCreator you pretty much need to do anyway if you want to create a server pack. - -Have fun! - -## 6.3 Using the Command-line Interface - -### 6.3.1 Windows - -**1.** Download the latest version of ServerPackCreator from the Releases page: https://github.com/Griefed/ServerPackCreator/releases - -**2.** Copy the .jar file to the partent directory of your modpack. Example: - - - -**3.** Open a command prompt by Shift-Right-Clicking into a free space of the explorer window, followed by a click on "Open command prompt here": - - - -**4.** Start the initial setup of ServerPackCreator by running it with the command: `java -jar ServerPackCreator-X.X.X.jar` (X.X.X corresponds to the version you downloaded. It will probably be different to the version used in these screenshots.) - -This will generate the default files of ServerpackCreator and tell you to customize these files before running again. Example for the directory above: -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ ├── server.properties -└── ServerPackCreator.jar -``` - -With the example above, the settings would look exactly like they are already set in the serverpackcreator.conf (or creator.conf if using older version). Note that modpackDir points at a directory *relative* to the ServerPackCreator.jar. Absolute paths *should* be usable, but are currently untested. - -Configure the config file to your liking. Double check the path to your Java installation if you intend on having SPC install the modloader-server. - -For a detailed explanation of the configuration, check chapter 5. Configuration - -**5.** After you double checked that you've set up your serverpackcreator.conf it is time to run ServerPackCreator again. Simply run `java -jar ServerPackCreator-X.X.X.jar` again (X.X.X corresponds to the version you downloaded. It will probably be different to the version used in these screenshots.) - -**6.** ServerPackCreator should now start telling you what it is currently doing. Logging of these actions may be very verbose, depending on which part SPC is currently working on. Should you have configured your config file correctly and should I have released a bug-free version of SPC, it will run until the console says "Done!". (Depending on the hardware you are running on, this may take some time.) - -Included in one of the last messages by SPC is the location of your newly generated serverpack. - -If you've set `includeZipCreation` to true, there will also be a zip-file called `server_pack.zip` in your modpack folder. - -Please note: The zip file **does not** contain Mojang's minecraft-server.jar. Distributing Mojang's software is against their Terms of Service and End User License Agreement. The zip file *does* however, contain scripts for both Windows and Linux, to download the minecraft-server.jar for your serverpack. That means that Users who download your serverpack simply need to run either of those two scripts and it will download the needed file for their modded Minecraft server. - -Enjoy! - -Example after successfully running SPC: - -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ ├── addons.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ └── server.properties -├── ServerPackCreator-1.1.0.jar -└── server-packs - └── Survive Create Prosper 4 - └── ... - └── Survive Create Prosper 4_server_pack.zip -``` - -### 6.3.2 Linux - -**1.** Switch to a directory where you want ServerPackCreator to be stored in and where it can save and deploy all of its files. - -**2.** Create and save the following script to download the latest version of ServerPackCreator: -```bash -#!/bin/bash -# Retrieve the latest version of ServerPackCreator - -VERSION=$(curl --silent "https://api.github.com/repos/Griefed/ServerPackCreator/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') - -echo "Latest ServerPackCreator version is: $VERSION" - -echo "" - -echo "Retrieving..." - -curl -o ServerPackCreator-$VERSION.jar -L https://github.com/Griefed/ServerPackCreator/releases/download/$VERSION/serverpackcreator-$VERSION.jar - -if [ -f ServerPackCreator-$VERSION.jar ]; then - echo "Successfully retrieved ServerPackCreator version $VERSION" -else - echo "Something seems to have gone wrong..." - echo "ServerPackCreator-$VERSION could not be found..." -fi -``` - -Save it, `chmod +x` it, and run it. - -This script will download the latest version of ServerPackCreator from GitHub and safe it to a file called ServerPackCreator-(version).jar. - -**3.** Start the initial setup of ServerPackCreator by running it with the command: java -jar ServerPackCreator-X.X.X.jar (X.X.X corresponds to the version you downloaded.) - -This will generate the default files of ServerpackCreator and tell you to customize these files before running again. Example: - -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ ├── addons.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ └── server.properties -└── ServerPackCreator-X.X.X.jar -``` - -With the example above, the settings would look exactly like they are already set in the serverpackcreator.conf. - -Configure the config file to your liking. Double check the path to your Java installation if you intend on having SPC install the modloader-server. - -For a detailed explanation of the configuration, check chapter 5. Configuration. - -**6.** After you double checked that you've set up your serverpackcreator.conf (or creator.conf if using older version) it is time to run ServerPackCreator again. Simply run `java -jar ServerPackCreator-X.X.X.jar` again (X.X.X corresponds to the version you downloaded. It will probably be different to the version used in these screenshots.) - -**7.** ServerPackCreator should now start telling you what it is currently doing. Logging of these actions may be very verbose, depending on which part SPC is currently working on. Should you have configured your config file correctly and should I have released a bug-free version of SPC, it will run until the console says "Done!". (Depending on the hardware you are running on, this may take some time.) - -Included in one of the last messages by SPC is the location of your newly generated serverpack. - -If you've set `includeZipCreation` to true, there will also be a zip-file called `server_pack.zip` in your modpack folder. - -Please note: The zip file **does not** contain Mojang's minecraft-server.jar. Distributing Mojang's software is against their Terms of Service and End User License Agreement. The zip file *does* however, contain scripts for both Windows and Linux, to download the minecraft-server.jar for your serverpack. That means that Users who download your serverpack simply need to run either of those two scripts and it will download the needed file for their modded Minecraft server. - -Enjoy! - -Example after successfully running SPC: - -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ ├── addons.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ └── server.properties -├── ServerPackCreator-1.1.0.jar -└── server-packs - └── Survive Create Prosper 4 - └── ... - └── Survive Create Prosper 4_server_pack.zip -``` - -### 6.3.3 Mac - -(By user [whitebear60](https://github.com/whitebear60)) - -**1.** Download the latest version of ServerPackCreator from the Releases page: https://github.com/Griefed/ServerPackCreator/releases - -**2.** Copy the .jar file to the partent directory of your modpack. Example: - - - -**3.** Open Terminal using Spotlight, Launchpad or by running `Terminal.app` from `/Applications/Utilities` folder - -**4.** Change the active directory to the one with ServerPackCreator jar and your modpacks. - - -**5.** Start the initial setup of ServerPackCreator by running it with the command: `java -jar ServerPackCreator-X.X.X.jar` (X.X.X corresponds to the version you downloaded. It will probably be different to the version used in these screenshots.) - -This will generate the default files of ServerpackCreator and tell you to customize these files before running again. Example for the directory above: - -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ ├── addons.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ └── server.properties -├── ServerPackCreator-1.1.0.jar -└── server-packs - └── Survive Create Prosper 4 - └── ... - └── Survive Create Prosper 4_server_pack.zip -``` - -With the example above, the settings would look exactly like they are already set in the serverpackcreator.conf. Note that modpackDir points at a directory *relative* to the ServerPackCreator.jar. Absolute paths *should* be usable, but are currently untested. - -Configure the config file to your liking. Double check the path to your Java installation if you intend on having SPC install the modloader-server. - -For a detailed explanation of the configuration, check chapter 5. Configuration - -**6.** After you double checked that you've set up your serverpackcreator.conf (or creator.conf if using older version) it is time to run ServerPackCreator again. Simply run `java -jar ServerPackCreator-X.X.X.jar` again (X.X.X corresponds to the version you downloaded. It will probably be different to the version used in these screenshots.) - -**7.** ServerPackCreator should now start telling you what it is currently doing. Logging of these actions may be very verbose, depending on which part SPC is currently working on. Should you have configured your config file correctly and should I have released a bug-free version of SPC, it will run until the console says "Done!". (Depending on the hardware you are running on, this may take some time.) - -Included in one of the last messages by SPC is the location of your newly generated serverpack. - -If you've set `includeZipCreation` to true, there will also be a zip-file called `server_pack.zip` in your modpack folder. - -Please note: The zip file **does not** contain Mojang's minecraft-server.jar. Distributing Mojang's software is against their Terms of Service and End User License Agreement. The zip file *does* however, contain scripts for both Windows and Linux, to download the minecraft-server.jar for your serverpack. That means that Users who download your serverpack simply need to run either of those two scripts and it will download the needed file for their modded Minecraft server. - -Enjoy! - -Example after successfully running SPC: - -```console -. -├── serverpackcreator.conf -├── serverpackcreator.properties -├── log4j2.xml -├── logs -│ ├── serverpackcreator.log -│ ├── addons.log -│ └── modloader_installer.log -├── server_files -│ ├── server-icon.png -│ └── server.properties -├── ServerPackCreator-1.1.0.jar -└── server-packs - └── Survive Create Prosper 4 - └── ... - └── Survive Create Prosper 4_server_pack.zip -``` - -## 6.4 Docker +## 6.3 Docker | Tags | Description | |-----------|-----------------------------------------------------------------------------------------------| @@ -675,7 +385,7 @@ When running as a docker container, there are a couple more settings you need to | PGID | The groupID under which this container is run as. Important for file access and permissions. Run **cat /etc/passwd | grep -i $(whoami)** to find your groupID. | | STARTUP_PARAMETER | Decides which mode ServerPackCreator will start in. `cli` for commandline interface, which will generate a server pack from the given config. `web` for starting ServerPackCreator as a webservice. | | -### 6.4.1 Using docker-compose: +### 6.3.1 Using docker-compose: ```docker-compose.yml version: "2" @@ -712,13 +422,13 @@ A short excerpt: > > 1. Fork ServerPackCreator > 2. Create a new branch in your fork, following one of the following naming schemes: -> 1. The end of each branch name bust be suffixed with a one-word description fitting the changes made. Examples: -> - griefed_chore_readme + > 1. The end of each branch name bust be suffixed with a one-word description fitting the changes made. Examples: + > - griefed_chore_readme > - griefed_perf_curseforgemodpack > - griefed_feat_ziparchive > 2. For more details on what the naming scheme entails, see `.releaserc.yml` in the base directory of the repository or scroll down to the **Commits**-section. > 3. Schemes: -> 1. your_username_breaking_ + > 1. your_username_breaking_ > 2. your_username_build_ > 3. your_username_chore_ > 4. your_username_ci_ @@ -732,13 +442,13 @@ A short excerpt: > 12. your_username_test_ > 13. your_username_other_ > 3. Make your changes to your new branch: -> 1. Try to keep the changes atomic, so they best fit the name of the branch. + > 1. Try to keep the changes atomic, so they best fit the name of the branch. > 2. Follow conventional commit messages. See **Commits**-section for more details. Example: -> - feat: Allow upload of modpack-export zip-archive to web-frontend + > - feat: Allow upload of modpack-export zip-archive to web-frontend > - refactor: Use apache commons-io for copying, instead of Files > 4. Open an issue on the main repository, using the **Pull Request** template: -> 1. Issue title: Your Username - Branch type (e.g. feat) - Short description of your changes. Example: -> - Griefed - feat - Allow upload of modpack-export zip-archive to web-frontend + > 1. Issue title: Your Username - Branch type (e.g. feat) - Short description of your changes. Example: + > - Griefed - feat - Allow upload of modpack-export zip-archive to web-frontend > 2. Issue description: Fill in the sections the template provide. > 3. Submit the new issue > 5. I will then create a new branch in the main repository, with the same name as your branch, to which you will **then** create a pull request to. diff --git a/backend/main/resources/de/griefed/resources/lang/lang_en_us.properties b/backend/main/resources/de/griefed/resources/lang/lang_en_us.properties index 54aa953932af1cb509e8a09b269b2512f20da38c..da6f288d560c27a8435dffcf387c448f5e88e365 100644 --- a/backend/main/resources/de/griefed/resources/lang/lang_en_us.properties +++ b/backend/main/resources/de/griefed/resources/lang/lang_en_us.properties @@ -170,6 +170,10 @@ menubar.gui.menuitem.saveconfig=Save Configuration menubar.gui.menuitem.saveas=Save Configuration As... menubar.gui.menuitem.uploadconfig=Upload Configuration to HasteBin menubar.gui.menuitem.uploadlog=Upload ServerPackCreator Log to HasteBin +menubar.gui.menuitem.updatefallback=Update Fallback Clientside Modslist +menubar.gui.menuitem.updatefallback.title=Fallback Clientside Modslist Updatecheck +menubar.gui.menuitem.updatefallback.updated=Your fallback list has been updated! +menubar.gui.menuitem.updatefallback.nochange=No update available. menubar.gui.menuitem.exit=Exit menubar.gui.menuitem.theme=Toggle light/dark-mode menubar.gui.menuitem.javaargs=Edit Start-Scripts Java Args @@ -186,6 +190,8 @@ menubar.gui.menuitem.issues=View Issues on GitHub menubar.gui.menuitem.releases=View Releases on GitHub menubar.gui.menuitem.discord=Join my Discord server! menubar.gui.menuitem.donate=Support me! +menubar.gui.menuitem.wiki.help=Help +menubar.gui.menuitem.wiki.howto=Getting started update.dialog.new=An update to ServerPackCreator is available at:\n%s\n\nWhat would you like to do? update.dialog.available=Update available! update.dialog.yes=Open in Browser diff --git a/backend/main/resources/serverpackcreator.properties b/backend/main/resources/serverpackcreator.properties index 64d48e3744ef5803d3a5ea9b9b72091d5ae75b5f..9c6ecaf52a3169c2313c9f04409e24202f2ff5dc 100644 --- a/backend/main/resources/serverpackcreator.properties +++ b/backend/main/resources/serverpackcreator.properties @@ -1,7 +1,7 @@ # Supported languages: [en_us, uk_ua, de_de] de.griefed.serverpackcreator.versioncheck.prerelease=false de.griefed.serverpackcreator.language=en_us -de.griefed.serverpackcreator.configuration.fallbackmodslist=3dSkinLayers-,AdvancementPlaques-,AmbientSounds_,armorchroma-,backtools-,BetterAdvancements-,BetterAnimationsCollection-,BetterDarkMode-,BetterF3-,BetterFoliage-,BetterPingDisplay-,BetterPlacement-,bhmenu-,BH-Menu-,Blur-,catalogue-,charmonium-,Charmonium-,cherishedworlds-,classicbar-,clickadv-,ClientTweaks_,configured-,Controlling-,CraftPresence-,CTM-,customdiscordrpc-,CustomMainMenu-,dashloader-,DefaultOptions_,defaultoptions-,desiredservers-,Ding-,drippyloadingscreen_,drippyloadingscreen-,Durability101-,dynamic-music-,DynamicSurroundings-,DynamicSurroundingsHuds-,dynmus-,EiraMoticons_,eiramoticons-,EnchantmentDescriptions-,entity-texture-features-,EquipmentCompare-,extremesoundmuffler-,extremeSoundMuffler-,Fallingleaves-,fallingleaves-,fancymenu_,findme-,flickerfix-,FpsReducer-,FullscreenWindowed-,InventoryEssentials_,InventorySpam-,InventoryTweaks-,invtweaks-,ItemBorders-,itemzoom,itlt-,jeed-,jehc-,jeiintegration_,JEITweaker-,just-enough-harvestcraft-,justenoughbeacons-,JustEnoughCalculation-,JustEnoughProfessions-,JustEnoughProfessions-,JustEnoughResources-,keywizard-,konkrete_,lazydfu-,LegendaryTooltips-,light-overlay-,LightOverlay-,LLOverlayReloaded-,loadmyresources_,lootbeams-,mcbindtype-,medievalmusic-,modnametooltip_,modnametooltip-,moreoverlays-,MouseTweaks-,multihotbar-,MyServerIsCompatible-,Neat ,NotifMod-,OldJavaWarning-,OptiFine,OptiForge,ornaments-,overloadedarmorbar-,PackMenu-,PickUpNotifier-,Ping-,preciseblockplacing-,presencefootsteps-,PresenceFootsteps-,ReAuth-,ResourceLoader-,shutupexperimentalsettings-,SimpleDiscordRichPresence-,smoothboot-,sounddeviceoptions-,SpawnerFix-,spoticraft-,tconplanner-,timestamps-,Tips-,TipTheScales-,Toast Control-,Toast-Control-,ToastControl-,torchoptimizer-,torohealth-,toughnessbar-,TravelersTitles-,WindowedFullscreen-,WorldNameRandomizer-,yisthereautojump- +de.griefed.serverpackcreator.configuration.fallbackmodslist=3dSkinLayers-,3dskinlayers-,Absolutely-Not-A-Zoom-Mod-,AdvancementPlaques-,AmbientEnvironment-,AmbientSounds_,antighost-,armorchroma-,armorpointspp-,ArmorSoundTweak-,authme-,autoreconnect-,auto-reconnect-,axolotl-item-fix-,backtools-,BetterAdvancements-,BetterAnimationsCollection-,BetterDarkMode-,BetterF3-,BetterFoliage-,BetterPingDisplay-,BetterPlacement-,BetterTaskbar-,bhmenu-,BH-Menu-,Blur-,borderless-mining-,catalogue-,charmonium-,Charmonium-,chat_heads-,cherishedworlds-,classicbar-,clickadv-,ClientTweaks_,configured-,Controlling-,CraftPresence-,CTM-,cullleaves-,customdiscordrpc-,CustomMainMenu-,dashloader-,DefaultOptions_,defaultoptions-,DeleteWorldsToTrash-,desiredservers-,Ding-,drippyloadingscreen_,drippyloadingscreen-,DripSounds-,Durability101-,dynamic-music-,DynamicSurroundings-,DynamicSurroundingsHuds-,dynmus-,effective-,EiraMoticons_,eiramoticons-,EnchantmentDescriptions-,entity-texture-features-,EquipmentCompare-,extremesoundmuffler-,extremeSoundMuffler-,fabricemotes-,Fallingleaves-,fallingleaves-,fancymenu_,findme-,flickerfix-,FPS-Monitor-,FpsReducer-,FullscreenWindowed-,InventoryEssentials_,InventorySpam-,InventoryTweaks-,invtweaks-,ItemBorders-,itemzoom,itlt-,jeed-,jehc-,jeiintegration_,JEITweaker-,just-enough-harvestcraft-,justenoughbeacons-,JustEnoughCalculation-,JustEnoughProfessions-,JustEnoughProfessions-,JustEnoughResources-,keymap-,keywizard-,konkrete_,lazydfu-,LegendaryTooltips-,light-overlay-,LightOverlay-,LLOverlayReloaded-,loadmyresources_,lootbeams-,mcbindtype-,medievalmusic-,modnametooltip_,modnametooltip-,moreoverlays-,MouseTweaks-,movement-vision-,multihotbar-,musicdr-,music-duration-reducer-,MyServerIsCompatible-,Neat ,ngrok-lan-expose-mod-,NotifMod-,OldJavaWarning-,OptiFine,OptiForge,ornaments-,overloadedarmorbar-,PackMenu-,PickUpNotifier-,Ping-,preciseblockplacing-,presencefootsteps-,PresenceFootsteps-,ReAuth-,ResourceLoader-,shutupexperimentalsettings-,SimpleDiscordRichPresence-,smoothboot-,sounddeviceoptions-,SpawnerFix-,spoticraft-,tconplanner-,timestamps-,Tips-,TipTheScales-,Toast Control-,Toast-Control-,ToastControl-,torchoptimizer-,torohealth-,toughnessbar-,TravelersTitles-,WindowedFullscreen-,WorldNameRandomizer-,yisthereautojump- de.griefed.serverpackcreator.configuration.hastebinserver=https://haste.zneix.eu/documents de.griefed.serverpackcreator.serverpack.autodiscoverenabled=true de.griefed.serverpackcreator.gui.darkmode=true diff --git a/backend/test/java/de/griefed/serverpackcreator/ApplicationPropertiesTest.java b/backend/test/java/de/griefed/serverpackcreator/ApplicationPropertiesTest.java index d1cd83265e1934bad4437d2880aa78156574f2a4..8e4e49f3a890771b538cedc18b73de482fd0dfe2 100644 --- a/backend/test/java/de/griefed/serverpackcreator/ApplicationPropertiesTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/ApplicationPropertiesTest.java @@ -1,9 +1,11 @@ package de.griefed.serverpackcreator; +import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -12,6 +14,14 @@ public class ApplicationPropertiesTest { private final ApplicationProperties APPLICATIONPROPERTIES; ApplicationPropertiesTest() { + try { + FileUtils.copyFile( + new File("backend/test/resources/serverpackcreator.properties"), + new File("serverpackcreator.properties") + ); + } catch (IOException e) { + throw new RuntimeException(e); + } this.APPLICATIONPROPERTIES = new ApplicationProperties(); } @@ -33,9 +43,19 @@ public class ApplicationPropertiesTest { Assertions.assertEquals(APPLICATIONPROPERTIES.LIST_FALLBACK_MODS_DEFAULT,new ArrayList<>( Arrays.asList(( "3dSkinLayers-," + + "3dskinlayers-," + + "Absolutely-Not-A-Zoom-Mod-," + "AdvancementPlaques-," + + "AmbientEnvironment-," + "AmbientSounds_," + + "antighost-," + "armorchroma-," + + "armorpointspp-," + + "ArmorSoundTweak-," + + "authme-," + + "autoreconnect-," + + "auto-reconnect-," + + "axolotl-item-fix-," + "backtools-," + "BetterAdvancements-," + "BetterAnimationsCollection-," + @@ -44,12 +64,15 @@ public class ApplicationPropertiesTest { "BetterFoliage-," + "BetterPingDisplay-," + "BetterPlacement-," + + "BetterTaskbar-," + "bhmenu-," + "BH-Menu-," + "Blur-," + + "borderless-mining-," + "catalogue-," + "charmonium-," + "Charmonium-," + + "chat_heads-," + "cherishedworlds-," + "classicbar-," + "clickadv-," + @@ -58,20 +81,24 @@ public class ApplicationPropertiesTest { "Controlling-," + "CraftPresence-," + "CTM-," + + "cullleaves-," + "customdiscordrpc-," + "CustomMainMenu-," + "dashloader-," + "DefaultOptions_," + "defaultoptions-," + + "DeleteWorldsToTrash-," + "desiredservers-," + "Ding-," + "drippyloadingscreen_," + "drippyloadingscreen-," + + "DripSounds-," + "Durability101-," + "dynamic-music-," + "DynamicSurroundings-," + "DynamicSurroundingsHuds-," + "dynmus-," + + "effective-," + "EiraMoticons_," + "eiramoticons-," + "EnchantmentDescriptions-," + @@ -79,11 +106,13 @@ public class ApplicationPropertiesTest { "EquipmentCompare-," + "extremesoundmuffler-," + "extremeSoundMuffler-," + + "fabricemotes-," + "Fallingleaves-," + "fallingleaves-," + "fancymenu_," + "findme-," + "flickerfix-," + + "FPS-Monitor-," + "FpsReducer-," + "FullscreenWindowed-," + "InventoryEssentials_," + @@ -103,6 +132,7 @@ public class ApplicationPropertiesTest { "JustEnoughProfessions-," + "JustEnoughProfessions-," + "JustEnoughResources-," + + "keymap-," + "keywizard-," + "konkrete_," + "lazydfu-," + @@ -118,9 +148,13 @@ public class ApplicationPropertiesTest { "modnametooltip-," + "moreoverlays-," + "MouseTweaks-," + + "movement-vision-," + "multihotbar-," + + "musicdr-," + + "music-duration-reducer-," + "MyServerIsCompatible-," + "Neat ," + + "ngrok-lan-expose-mod-," + "NotifMod-," + "OldJavaWarning-," + "OptiFine," + @@ -237,4 +271,11 @@ public class ApplicationPropertiesTest { void getServerPackCreatorVersionTest() { Assertions.assertEquals("dev",APPLICATIONPROPERTIES.getServerPackCreatorVersion()); } + + @Test + void updateFallbackTest() { + APPLICATIONPROPERTIES.setProperty("de.griefed.serverpackcreator.configuration.fallbackmodslist","bla"); + APPLICATIONPROPERTIES.updateFallback(); + Assertions.assertNotEquals(APPLICATIONPROPERTIES.getProperty("de.griefed.serverpackcreator.configuration.fallbackmodslist"),"bla"); + } } diff --git a/backend/test/java/de/griefed/serverpackcreator/ConfigurationHandlerTest.java b/backend/test/java/de/griefed/serverpackcreator/ConfigurationHandlerTest.java index a478514852a202780fb739b1a00d2008439a09c8..f44c5173967b62cc01af791d3ed8153f43722809 100644 --- a/backend/test/java/de/griefed/serverpackcreator/ConfigurationHandlerTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/ConfigurationHandlerTest.java @@ -5,7 +5,9 @@ import de.griefed.serverpackcreator.curseforge.CurseCreateModpack; import de.griefed.serverpackcreator.curseforge.InvalidFileException; import de.griefed.serverpackcreator.curseforge.InvalidModpackException; import de.griefed.serverpackcreator.i18n.LocalizationManager; -import de.griefed.serverpackcreator.utilities.*; +import de.griefed.serverpackcreator.utilities.ConfigUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; @@ -17,18 +19,10 @@ import java.util.*; class ConfigurationHandlerTest { private final ConfigurationHandler CONFIGURATIONHANDLER; - private final CurseCreateModpack CURSECREATEMODPACK; - private final LocalizationManager LOCALIZATIONMANAGER; - private final DefaultFiles DEFAULTFILES; - private final VersionLister VERSIONLISTER; - private final BooleanUtilities BOOLEANUTILITIES; - private final ListUtilities LISTUTILITIES; - private final StringUtilities STRINGUTILITIES; - private final ConfigUtilities CONFIGUTILITIES; - private final SystemUtilities SYSTEMUTILITIES; + private final VersionMeta VERSIONMETA; private final ApplicationProperties APPLICATIONPROPERTIES; - ConfigurationHandlerTest() { + ConfigurationHandlerTest() throws IOException { try { FileUtils.copyFile(new File("backend/main/resources/serverpackcreator.properties"),new File("serverpackcreator.properties")); } catch (IOException e) { @@ -36,19 +30,13 @@ class ConfigurationHandlerTest { } this.APPLICATIONPROPERTIES = new ApplicationProperties(); - - LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); - LOCALIZATIONMANAGER.initialize(); - DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - DEFAULTFILES.filesSetup(); - VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); - LISTUTILITIES = new ListUtilities(); - STRINGUTILITIES = new StringUtilities(); - SYSTEMUTILITIES = new SystemUtilities(); - BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, BOOLEANUTILITIES, LISTUTILITIES, APPLICATIONPROPERTIES, STRINGUTILITIES, VERSIONLISTER); - CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES); - CONFIGURATIONHANDLER = new ConfigurationHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONLISTER, APPLICATIONPROPERTIES, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, SYSTEMUTILITIES, CONFIGUTILITIES); + LocalizationManager LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); + DefaultFiles DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + this.VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); + Utilities UTILITIES = new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + ConfigUtilities CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, UTILITIES, APPLICATIONPROPERTIES, VERSIONMETA); + CurseCreateModpack CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES,CONFIGUTILITIES); + this.CONFIGURATIONHANDLER = new ConfigurationHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONMETA, APPLICATIONPROPERTIES, UTILITIES, CONFIGUTILITIES); } @@ -61,9 +49,19 @@ class ConfigurationHandlerTest { void getFallbackModsListTestEquals() { String FALLBACK_MODS_DEFAULT_ASSTRING = "3dSkinLayers-," + + "3dskinlayers-," + + "Absolutely-Not-A-Zoom-Mod-," + "AdvancementPlaques-," + + "AmbientEnvironment-," + "AmbientSounds_," + + "antighost-," + "armorchroma-," + + "armorpointspp-," + + "ArmorSoundTweak-," + + "authme-," + + "autoreconnect-," + + "auto-reconnect-," + + "axolotl-item-fix-," + "backtools-," + "BetterAdvancements-," + "BetterAnimationsCollection-," + @@ -72,12 +70,15 @@ class ConfigurationHandlerTest { "BetterFoliage-," + "BetterPingDisplay-," + "BetterPlacement-," + + "BetterTaskbar-," + "bhmenu-," + "BH-Menu-," + "Blur-," + + "borderless-mining-," + "catalogue-," + "charmonium-," + "Charmonium-," + + "chat_heads-," + "cherishedworlds-," + "classicbar-," + "clickadv-," + @@ -86,20 +87,24 @@ class ConfigurationHandlerTest { "Controlling-," + "CraftPresence-," + "CTM-," + + "cullleaves-," + "customdiscordrpc-," + "CustomMainMenu-," + "dashloader-," + "DefaultOptions_," + "defaultoptions-," + + "DeleteWorldsToTrash-," + "desiredservers-," + "Ding-," + "drippyloadingscreen_," + "drippyloadingscreen-," + + "DripSounds-," + "Durability101-," + "dynamic-music-," + "DynamicSurroundings-," + "DynamicSurroundingsHuds-," + "dynmus-," + + "effective-," + "EiraMoticons_," + "eiramoticons-," + "EnchantmentDescriptions-," + @@ -107,11 +112,13 @@ class ConfigurationHandlerTest { "EquipmentCompare-," + "extremesoundmuffler-," + "extremeSoundMuffler-," + + "fabricemotes-," + "Fallingleaves-," + "fallingleaves-," + "fancymenu_," + "findme-," + "flickerfix-," + + "FPS-Monitor-," + "FpsReducer-," + "FullscreenWindowed-," + "InventoryEssentials_," + @@ -131,6 +138,7 @@ class ConfigurationHandlerTest { "JustEnoughProfessions-," + "JustEnoughProfessions-," + "JustEnoughResources-," + + "keymap-," + "keywizard-," + "konkrete_," + "lazydfu-," + @@ -146,9 +154,13 @@ class ConfigurationHandlerTest { "modnametooltip-," + "moreoverlays-," + "MouseTweaks-," + + "movement-vision-," + "multihotbar-," + + "musicdr-," + + "music-duration-reducer-," + "MyServerIsCompatible-," + "Neat ," + + "ngrok-lan-expose-mod-," + "NotifMod-," + "OldJavaWarning-," + "OptiFine," + @@ -406,32 +418,32 @@ class ConfigurationHandlerTest { @Test void isMinecraftVersionCorrectTest() { - Assertions.assertTrue(CONFIGURATIONHANDLER.isMinecraftVersionCorrect("1.16.5")); + Assertions.assertTrue(VERSIONMETA.minecraft().checkMinecraftVersion("1.16.5")); } @Test void isMinecraftVersionCorrectTestFalse() { - Assertions.assertFalse(CONFIGURATIONHANDLER.isMinecraftVersionCorrect("1.99.5")); + Assertions.assertFalse(VERSIONMETA.minecraft().checkMinecraftVersion("1.99.5")); } @Test void isFabricVersionCorrectTest() { - Assertions.assertTrue(CONFIGURATIONHANDLER.isFabricVersionCorrect("0.11.3")); + Assertions.assertTrue(VERSIONMETA.fabric().checkFabricVersion("0.11.3")); } @Test void isFabricVersionCorrectTestFalse() { - Assertions.assertFalse(CONFIGURATIONHANDLER.isFabricVersionCorrect("0.90.3")); + Assertions.assertFalse(VERSIONMETA.fabric().checkFabricVersion("0.90.3")); } @Test void isForgeVersionCorrectTest() { - Assertions.assertTrue(CONFIGURATIONHANDLER.isForgeVersionCorrect("36.1.2", "1.16.5")); + Assertions.assertTrue(VERSIONMETA.forge().checkForgeAndMinecraftVersion("1.16.5","36.1.2")); } @Test void isForgeVersionCorrectTestFalse() { - Assertions.assertFalse(CONFIGURATIONHANDLER.isForgeVersionCorrect("99.0.0","1.16.5")); + Assertions.assertFalse(VERSIONMETA.forge().checkForgeAndMinecraftVersion("1.16.5","99.0.0")); } @Test diff --git a/backend/test/java/de/griefed/serverpackcreator/DefaultFilesTest.java b/backend/test/java/de/griefed/serverpackcreator/DefaultFilesTest.java index 4df0ee9b6430061136d9c5a7b7468d250043ef32..1bba3adf4f4755a246756c3818c8bdf416d9a1f2 100644 --- a/backend/test/java/de/griefed/serverpackcreator/DefaultFilesTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/DefaultFilesTest.java @@ -20,10 +20,8 @@ class DefaultFilesTest { } this.APPLICATIONPROPERTIES = new ApplicationProperties(); - - LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); - LOCALIZATIONMANAGER.initialize(); - DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + this.LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); + this.DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); } @Test @@ -131,6 +129,7 @@ class DefaultFilesTest { FileUtils.deleteQuietly(new File("./serverpackcreator.conf")); FileUtils.deleteQuietly(new File("./work/minecraft-manifest.json")); FileUtils.deleteQuietly(new File("./work/fabric-manifest.xml")); + FileUtils.deleteQuietly(new File("./work/fabric-installer-manifest.xml")); FileUtils.deleteQuietly(new File("./work/forge-manifest.json")); DEFAULTFILES.filesSetup(); Assertions.assertTrue(new File("./server_files").isDirectory()); @@ -142,6 +141,7 @@ class DefaultFilesTest { Assertions.assertTrue(new File("./serverpackcreator.conf").exists()); Assertions.assertTrue(new File("./work/minecraft-manifest.json").exists()); Assertions.assertTrue(new File("./work/fabric-manifest.xml").exists()); + Assertions.assertTrue(new File("./work/fabric-installer-manifest.xml").exists()); Assertions.assertTrue(new File("./work/forge-manifest.json").exists()); } diff --git a/backend/test/java/de/griefed/serverpackcreator/MainSpringBootTest.java b/backend/test/java/de/griefed/serverpackcreator/MainSpringBootTest.java index ff047b63d1b6ded49ac77afb63998c31cb21dd27..fc05407822a55ed9b9e4dac66464ee8cf8554715 100644 --- a/backend/test/java/de/griefed/serverpackcreator/MainSpringBootTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/MainSpringBootTest.java @@ -33,12 +33,9 @@ public class MainSpringBootTest { } this.APPLICATIONPROPERTIES = new ApplicationProperties(); - - LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); - LOCALIZATIONMANAGER.initialize(); - DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - DEFAULTFILES.filesSetup(); - DEFAULTFILES.checkDatabase(); + this.LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); + this.DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + this.DEFAULTFILES.checkDatabase(); } @Test diff --git a/backend/test/java/de/griefed/serverpackcreator/ServerPackModelHandlerTest.java b/backend/test/java/de/griefed/serverpackcreator/ServerPackHandlerTest.java similarity index 80% rename from backend/test/java/de/griefed/serverpackcreator/ServerPackModelHandlerTest.java rename to backend/test/java/de/griefed/serverpackcreator/ServerPackHandlerTest.java index 7b5c12d8910a3017a5010595c8ff43d4da5fdf21..3a2f04e616eb7f5d3a0e85f323ea97b8877e464f 100644 --- a/backend/test/java/de/griefed/serverpackcreator/ServerPackModelHandlerTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/ServerPackHandlerTest.java @@ -2,8 +2,11 @@ package de.griefed.serverpackcreator; import de.griefed.serverpackcreator.curseforge.CurseCreateModpack; import de.griefed.serverpackcreator.i18n.LocalizationManager; +import de.griefed.serverpackcreator.plugins.ApplicationPlugins; import de.griefed.serverpackcreator.spring.serverpack.ServerPackModel; -import de.griefed.serverpackcreator.utilities.*; +import de.griefed.serverpackcreator.utilities.ConfigUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -16,45 +19,29 @@ import java.util.*; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; -class ServerPackModelHandlerTest { +class ServerPackHandlerTest { private final ServerPackHandler SERVERPACKHANDLER; private final DefaultFiles DEFAULTFILES; - private final CurseCreateModpack CURSECREATEMODPACK; - private final LocalizationManager LOCALIZATIONMANAGER; private final ConfigurationHandler CONFIGURATIONHANDLER; - private final VersionLister VERSIONLISTER; - private final BooleanUtilities BOOLEANUTILITIES; - private final ListUtilities LISTUTILITIES; - private final StringUtilities STRINGUTILITIES; - private final ConfigUtilities CONFIGUTILITIES; - private final SystemUtilities SYSTEMUTILITIES; - private final ApplicationProperties APPLICATIONPROPERTIES; - private final ApplicationPlugins PLUGINMANAGER; - ServerPackModelHandlerTest() { + ServerPackHandlerTest() throws IOException { try { FileUtils.copyFile(new File("backend/main/resources/serverpackcreator.properties"),new File("serverpackcreator.properties")); } catch (IOException e) { e.printStackTrace(); } - this.APPLICATIONPROPERTIES = new ApplicationProperties(); - - LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); - LOCALIZATIONMANAGER.initialize(); - DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - DEFAULTFILES.filesSetup(); - VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); - LISTUTILITIES = new ListUtilities(); - STRINGUTILITIES = new StringUtilities(); - SYSTEMUTILITIES = new SystemUtilities(); - BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, BOOLEANUTILITIES, LISTUTILITIES, APPLICATIONPROPERTIES, STRINGUTILITIES, VERSIONLISTER); - CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES); - CONFIGURATIONHANDLER = new ConfigurationHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONLISTER, APPLICATIONPROPERTIES, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, SYSTEMUTILITIES, CONFIGUTILITIES); - PLUGINMANAGER = new ApplicationPlugins(); - SERVERPACKHANDLER = new ServerPackHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, CONFIGURATIONHANDLER, APPLICATIONPROPERTIES, VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, SYSTEMUTILITIES, CONFIGUTILITIES, PLUGINMANAGER); + ApplicationProperties APPLICATIONPROPERTIES = new ApplicationProperties(); + LocalizationManager LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); + this.DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + VersionMeta VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); + Utilities UTILITIES = new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + ConfigUtilities CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, UTILITIES, APPLICATIONPROPERTIES, VERSIONMETA); + CurseCreateModpack CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES, CONFIGUTILITIES); + this.CONFIGURATIONHANDLER = new ConfigurationHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, VERSIONMETA, APPLICATIONPROPERTIES, UTILITIES, CONFIGUTILITIES); + ApplicationPlugins PLUGINMANAGER = new ApplicationPlugins(); + this.SERVERPACKHANDLER = new ServerPackHandler(LOCALIZATIONMANAGER, CURSECREATEMODPACK, APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES, PLUGINMANAGER, CONFIGUTILITIES); } diff --git a/backend/test/java/de/griefed/serverpackcreator/VersionListerTest.java b/backend/test/java/de/griefed/serverpackcreator/VersionListerTest.java deleted file mode 100644 index 1e7a4f4d260b37bc0f5e9c25b8f52b02c5b0086a..0000000000000000000000000000000000000000 --- a/backend/test/java/de/griefed/serverpackcreator/VersionListerTest.java +++ /dev/null @@ -1,146 +0,0 @@ -package de.griefed.serverpackcreator; - -import de.griefed.serverpackcreator.i18n.LocalizationManager; -import org.apache.commons.io.FileUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -public class VersionListerTest { - - private final LocalizationManager LOCALIZATIONMANAGER; - private final DefaultFiles DEFAULTFILES; - private final VersionLister VERSIONLISTER; - private static final Logger LOG = LogManager.getLogger(VersionListerTest.class); - private final ApplicationProperties APPLICATIONPROPERTIES; - - public VersionListerTest() { - try { - FileUtils.copyFile(new File("backend/main/resources/serverpackcreator.properties"),new File("serverpackcreator.properties")); - } catch (IOException e) { - e.printStackTrace(); - } - this.APPLICATIONPROPERTIES = new ApplicationProperties(); - LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); - LOCALIZATIONMANAGER.initialize(); - DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - DEFAULTFILES.filesSetup(); - this.VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); - } - - @Test - void getMinecraftReleaseVersionTest() { - Assertions.assertNotNull(VERSIONLISTER.getMinecraftReleaseVersion()); - } - - @Test - void getMinecraftReleaseVersionsTest() { - Assertions.assertNotNull(VERSIONLISTER.getMinecraftReleaseVersions()); - } - - @Test - void getMinecraftSnapshotVersionTest() { - Assertions.assertNotNull(VERSIONLISTER.getMinecraftSnapshotVersion()); - } - - @Test - void getMinecraftSnapshotVersionsTest() { - Assertions.assertNotNull(VERSIONLISTER.getMinecraftSnapshotVersions()); - } - - @Test - void getFabricVersionsTest() { - Assertions.assertNotNull(VERSIONLISTER.getFabricVersions()); - } - - @Test - void getFabricLatestVersionTest() { - Assertions.assertNotNull(VERSIONLISTER.getFabricLatestVersion()); - } - - @Test - void getFabricReleaseVersionTest() { - Assertions.assertNotNull(VERSIONLISTER.getFabricReleaseVersion()); - } - - @Test - void getMinecraftReleaseVersionsAsArrayTest() { - Assertions.assertNotNull(VERSIONLISTER.getMinecraftReleaseVersionsAsArray()); - } - - @Test - void getFabricVersionsAsArrayTest() { - Assertions.assertNotNull(VERSIONLISTER.getFabricVersionsAsArray()); - } - - @Test - void getForgeVersionsAsArrayTest() { - for (int i = 0; i < VERSIONLISTER.getMinecraftReleaseVersions().size(); i++) { - Assertions.assertNotNull(VERSIONLISTER.getForgeVersionsAsArray(VERSIONLISTER.getMinecraftReleaseVersions().get(i))); - } - } - - @Test - void getForgeMetaTest() { - List<String> minecraftVersions = VERSIONLISTER.getMinecraftReleaseVersions(); - for (String version : minecraftVersions) { - Assertions.assertNotNull(VERSIONLISTER.getForgeMeta().get(version)); - } - } - - @Test - void getFabricLatestInstallerVersionTest() { - Assertions.assertNotNull(VERSIONLISTER.getFabricLatestInstallerVersion()); - } - - @Test - void getFabricReleaseInstallerVersionTest() { - Assertions.assertNotNull(VERSIONLISTER.getFabricReleaseInstallerVersion()); - } - - @Test - void reverseOrderListTest() { - Assertions.assertNotNull(VERSIONLISTER.reverseOrderList(VERSIONLISTER.getFabricVersions())); - Assertions.assertEquals( - VERSIONLISTER.reverseOrderList(VERSIONLISTER.getFabricVersions()).get(VERSIONLISTER.reverseOrderList(VERSIONLISTER.getFabricVersions()).size() - 1), - VERSIONLISTER.getFabricVersions().get(0) - ); - } - - @Test - void reverseOrderArrayTest() { - Assertions.assertNotNull(VERSIONLISTER.reverseOrderArray(VERSIONLISTER.getForgeVersionsAsArray(VERSIONLISTER.getMinecraftReleaseVersion()))); - Assertions.assertEquals( - VERSIONLISTER.reverseOrderArray(VERSIONLISTER.getForgeVersionsAsArray(VERSIONLISTER.getMinecraftReleaseVersion()))[VERSIONLISTER.reverseOrderArray(VERSIONLISTER.getForgeVersionsAsArray(VERSIONLISTER.getMinecraftReleaseVersion())).length - 1], - VERSIONLISTER.getForgeVersionsAsArray(VERSIONLISTER.getMinecraftReleaseVersion())[0] - ); - } - - @Test - void refreshVersionsTest() { - DEFAULTFILES.refreshManifestFile(DEFAULTFILES.getMinecraftManifestUrl(), APPLICATIONPROPERTIES.FILE_MANIFEST_MINECRAFT); - DEFAULTFILES.refreshManifestFile(DEFAULTFILES.getForgeManifestUrl(), APPLICATIONPROPERTIES.FILE_MANIFEST_FORGE); - DEFAULTFILES.refreshManifestFile(DEFAULTFILES.getFabricManifestUrl(), APPLICATIONPROPERTIES.FILE_MANIFEST_FABRIC); - DEFAULTFILES.refreshManifestFile(DEFAULTFILES.getFabricInstallerManifestUrl(), APPLICATIONPROPERTIES.FILE_MANIFEST_FABRIC_INSTALLER); - - VERSIONLISTER.refreshVersions(); - - Assertions.assertNotNull(VERSIONLISTER.getFabricReleaseInstallerVersion()); - Assertions.assertNotNull(VERSIONLISTER.getFabricLatestInstallerVersion()); - Assertions.assertTrue(VERSIONLISTER.getFabricVersions().size() > 1); - Assertions.assertTrue(VERSIONLISTER.getMinecraftReleaseVersions().size() > 1); - for (int i = 0; i < VERSIONLISTER.getMinecraftReleaseVersions().size(); i++) { - Assertions.assertNotNull(VERSIONLISTER.getForgeVersionsAsArray(VERSIONLISTER.getMinecraftReleaseVersions().get(i))); - } - } - - @Test - void forgeVersionsAsListTest() { - for (String minecraft : VERSIONLISTER.getMinecraftReleaseVersions()) Assertions.assertNotNull(VERSIONLISTER.getForgeVersionsAsList(minecraft)); - } -} diff --git a/backend/test/java/de/griefed/serverpackcreator/VersionMetaTest.java b/backend/test/java/de/griefed/serverpackcreator/VersionMetaTest.java new file mode 100644 index 0000000000000000000000000000000000000000..df9ebc2f48ce63ddfa28116ea99ec6a860f33726 --- /dev/null +++ b/backend/test/java/de/griefed/serverpackcreator/VersionMetaTest.java @@ -0,0 +1,300 @@ +package de.griefed.serverpackcreator; + +import de.griefed.serverpackcreator.i18n.LocalizationManager; +import de.griefed.serverpackcreator.versionmeta.Type; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.IOException; + +public class VersionMetaTest { + + private final VersionMeta VERSIONMETA; + + public VersionMetaTest() throws IOException { + try { + FileUtils.copyFile(new File("backend/main/resources/serverpackcreator.properties"),new File("serverpackcreator.properties")); + } catch (IOException e) { + e.printStackTrace(); + } + ApplicationProperties APPLICATIONPROPERTIES = new ApplicationProperties(); + LocalizationManager LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); + DefaultFiles DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + this.VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); + } + + @Test + void meta() throws IOException { + Assertions.assertNotNull(VERSIONMETA.update()); + } + + @Test + void minecraft() { + Assertions.assertTrue(VERSIONMETA.minecraft().checkMinecraftVersion("1.16.5")); + Assertions.assertFalse(VERSIONMETA.minecraft().checkMinecraftVersion("1.16.7")); + Assertions.assertNotNull(VERSIONMETA.minecraft().latestRelease()); + Assertions.assertNotNull(VERSIONMETA.minecraft().latestRelease().version()); + Assertions.assertTrue(VERSIONMETA.minecraft().latestRelease().server().isPresent()); + Assertions.assertNotNull(VERSIONMETA.minecraft().latestRelease().server().get()); + Assertions.assertNotNull(VERSIONMETA.minecraft().latestRelease().url()); + Assertions.assertEquals(VERSIONMETA.minecraft().latestRelease().type(), Type.RELEASE); + Assertions.assertNotNull(VERSIONMETA.minecraft().releaseVersionsDescending()); + Assertions.assertNotNull(VERSIONMETA.minecraft().releaseVersionsAscending()); + Assertions.assertNotNull(VERSIONMETA.minecraft().releaseVersionsArrayDescending()); + Assertions.assertEquals(VERSIONMETA.minecraft().releaseVersionsArrayDescending().length,VERSIONMETA.minecraft().releaseVersionsDescending().size()); + Assertions.assertEquals( + VERSIONMETA.minecraft().releaseVersionsArrayDescending()[0], + VERSIONMETA.minecraft().releaseVersionsArrayAscending()[VERSIONMETA.minecraft().releaseVersionsArrayAscending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.minecraft().releaseVersionsArrayAscending()); + Assertions.assertEquals(VERSIONMETA.minecraft().releaseVersionsArrayAscending().length,VERSIONMETA.minecraft().releaseVersionsAscending().size()); + Assertions.assertEquals( + VERSIONMETA.minecraft().releaseVersionsArrayAscending()[0], + VERSIONMETA.minecraft().releaseVersionsArrayDescending()[VERSIONMETA.minecraft().releaseVersionsArrayDescending().length-1] + ); + VERSIONMETA.minecraft().releasesDescending().forEach(release -> { + Assertions.assertNotNull(release); + Assertions.assertNotNull(release.version()); + if (release.server().isPresent()) { + Assertions.assertNotNull(release.server().get()); + Assertions.assertNotNull(release.server().get()); + } + Assertions.assertNotNull(release.url()); + Assertions.assertEquals(release.type(), Type.RELEASE); + }); + Assertions.assertNotNull(VERSIONMETA.minecraft().latestSnapshot()); + Assertions.assertNotNull(VERSIONMETA.minecraft().latestSnapshot().version()); + Assertions.assertNotNull(VERSIONMETA.minecraft().latestSnapshot().url()); + Assertions.assertEquals(VERSIONMETA.minecraft().latestSnapshot().type(), Type.SNAPSHOT); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotsVersionsDescending()); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotVersionsAscending()); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotVersionsArrayDescending()); + Assertions.assertEquals(VERSIONMETA.minecraft().snapshotVersionsArrayDescending().length,VERSIONMETA.minecraft().snapshotsVersionsDescending().size()); + Assertions.assertEquals( + VERSIONMETA.minecraft().snapshotVersionsArrayDescending()[0], + VERSIONMETA.minecraft().snapshotVersionsArrayAscending()[VERSIONMETA.minecraft().snapshotVersionsArrayAscending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotVersionsArrayAscending()); + Assertions.assertEquals(VERSIONMETA.minecraft().snapshotVersionsArrayAscending().length,VERSIONMETA.minecraft().snapshotVersionsAscending().size()); + Assertions.assertEquals( + VERSIONMETA.minecraft().snapshotVersionsArrayAscending()[0], + VERSIONMETA.minecraft().snapshotVersionsArrayDescending()[VERSIONMETA.minecraft().snapshotVersionsArrayDescending().length-1] + ); + VERSIONMETA.minecraft().releasesDescending().forEach(release -> { + Assertions.assertNotNull(release); + Assertions.assertNotNull(release.version()); + Assertions.assertNotNull(release.url()); + Assertions.assertEquals(release.type(), Type.RELEASE); + if (release.forge().isPresent()) { + release.forge().get().forEach(forgeInstance -> { + Assertions.assertNotNull(forgeInstance); + Assertions.assertNotNull(forgeInstance.minecraftVersion()); + Assertions.assertNotNull(forgeInstance.minecraftClient()); + Assertions.assertNotNull(forgeInstance.installerUrl()); + Assertions.assertNotNull(forgeInstance.forgeVersion()); + }); + } + }); + VERSIONMETA.minecraft().releaseVersionsAscending().forEach(mcVer -> Assertions.assertTrue(VERSIONMETA.minecraft().getClient(mcVer).isPresent())); + Assertions.assertNotNull(VERSIONMETA.minecraft().releasesArrayAscending()); + Assertions.assertEquals(VERSIONMETA.minecraft().releasesArrayAscending().length,VERSIONMETA.minecraft().releasesAscending().size()); + Assertions.assertEquals( + VERSIONMETA.minecraft().releasesArrayAscending()[0], + VERSIONMETA.minecraft().releasesArrayDescending()[VERSIONMETA.minecraft().releasesArrayDescending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotsDescending()); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotsAscending()); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotsArrayDescending()); + Assertions.assertEquals(VERSIONMETA.minecraft().snapshotsArrayDescending().length,VERSIONMETA.minecraft().snapshotsDescending().size()); + Assertions.assertEquals( + VERSIONMETA.minecraft().snapshotsArrayDescending()[0], + VERSIONMETA.minecraft().snapshotsArrayAscending()[VERSIONMETA.minecraft().snapshotsArrayAscending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotsArrayAscending()); + Assertions.assertEquals(VERSIONMETA.minecraft().snapshotsArrayAscending().length,VERSIONMETA.minecraft().snapshotsAscending().size()); + Assertions.assertEquals( + VERSIONMETA.minecraft().snapshotsArrayAscending()[0], + VERSIONMETA.minecraft().snapshotsArrayDescending()[VERSIONMETA.minecraft().snapshotsArrayDescending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.minecraft().getServer("1.16.5").get()); + Assertions.assertTrue(VERSIONMETA.minecraft().checkServerAvailability("1.16.5")); + Assertions.assertFalse(VERSIONMETA.minecraft().checkServerAvailability("1.16.6")); + Assertions.assertNotNull(VERSIONMETA.minecraft().latestReleaseServer().get()); + Assertions.assertNotNull(VERSIONMETA.minecraft().latestSnapshotServer().get()); + Assertions.assertNotNull(VERSIONMETA.minecraft().releasesServersDescending()); + Assertions.assertNotNull(VERSIONMETA.minecraft().releasesServersAscending()); + VERSIONMETA.minecraft().snapshotsDescending().forEach(snapshot -> { + Assertions.assertNotNull(snapshot); + Assertions.assertNotNull(snapshot.version()); + Assertions.assertNotNull(snapshot.url()); + Assertions.assertEquals(snapshot.type(), Type.SNAPSHOT); + }); + Assertions.assertNotNull(VERSIONMETA.minecraft().releasesServersArrayDescending()); + Assertions.assertEquals(VERSIONMETA.minecraft().releasesServersArrayDescending().length,VERSIONMETA.minecraft().releasesServersDescending().size()); + Assertions.assertEquals( + VERSIONMETA.minecraft().releasesServersArrayDescending()[0], + VERSIONMETA.minecraft().releasesServersArrayAscending()[VERSIONMETA.minecraft().releasesServersArrayAscending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.minecraft().releasesServersArrayAscending()); + Assertions.assertEquals(VERSIONMETA.minecraft().releasesServersArrayAscending().length,VERSIONMETA.minecraft().releasesServersAscending().size()); + Assertions.assertEquals( + VERSIONMETA.minecraft().releasesServersArrayAscending()[0], + VERSIONMETA.minecraft().releasesServersArrayDescending()[VERSIONMETA.minecraft().releasesServersArrayDescending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotsServersDescending()); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotsServersAscending()); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotsServersArrayDescending()); + Assertions.assertEquals(VERSIONMETA.minecraft().snapshotsServersArrayDescending().length,VERSIONMETA.minecraft().snapshotsServersDescending().size()); + Assertions.assertEquals( + VERSIONMETA.minecraft().snapshotsServersArrayDescending()[0], + VERSIONMETA.minecraft().snapshotsServersArrayAscending()[VERSIONMETA.minecraft().snapshotsServersArrayAscending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.minecraft().snapshotsServersArrayAscending()); + Assertions.assertEquals(VERSIONMETA.minecraft().snapshotsServersArrayAscending().length,VERSIONMETA.minecraft().snapshotsServersAscending().size()); + Assertions.assertEquals( + VERSIONMETA.minecraft().snapshotsServersArrayAscending()[0], + VERSIONMETA.minecraft().snapshotsServersArrayDescending()[VERSIONMETA.minecraft().snapshotsServersArrayDescending().length-1] + ); + } + + @Test + void forge() { + Assertions.assertTrue(VERSIONMETA.forge().checkForgeVersion("40.0.45")); + Assertions.assertFalse(VERSIONMETA.forge().checkForgeVersion("40.99.99")); + Assertions.assertTrue(VERSIONMETA.forge().checkMinecraftVersion("1.16.5")); + Assertions.assertFalse(VERSIONMETA.forge().checkMinecraftVersion("1.16.8")); + Assertions.assertTrue(VERSIONMETA.forge().checkForgeAndMinecraftVersion("1.18.2","40.0.45")); + Assertions.assertFalse(VERSIONMETA.forge().checkForgeAndMinecraftVersion("1.18.21","99.0.45")); + Assertions.assertTrue(VERSIONMETA.forge().isForgeInstanceAvailable("1.18.2","40.0.45")); + Assertions.assertFalse(VERSIONMETA.forge().isForgeInstanceAvailable("1.182.2","40.023.45")); + Assertions.assertTrue(VERSIONMETA.forge().isForgeInstanceAvailable("40.0.4")); + Assertions.assertFalse(VERSIONMETA.forge().isForgeInstanceAvailable("40.0123.4")); + Assertions.assertNotNull(VERSIONMETA.forge().supportedMinecraftVersion("40.0.4").get()); + Assertions.assertTrue(VERSIONMETA.forge().supportedMinecraftVersion("40.0.4").isPresent()); + Assertions.assertFalse(VERSIONMETA.forge().supportedMinecraftVersion("40.0123.4").isPresent()); + Assertions.assertNotNull(VERSIONMETA.forge().getForgeInstance("1.18.2","40.0.45").get()); + Assertions.assertTrue(VERSIONMETA.forge().getForgeInstance("1.18.2","40.0.45").isPresent()); + Assertions.assertFalse(VERSIONMETA.forge().getForgeInstance("1.18.2","40.0123.45").isPresent()); + Assertions.assertNotNull(VERSIONMETA.forge().getForgeInstance("40.0.45").get()); + Assertions.assertTrue(VERSIONMETA.forge().getForgeInstance("40.0.45").isPresent()); + Assertions.assertFalse(VERSIONMETA.forge().getForgeInstance("40.0.45123").isPresent()); + Assertions.assertNotNull(VERSIONMETA.forge().forgeVersions()); + Assertions.assertNotNull(VERSIONMETA.forge().forgeVersionsDescending()); + Assertions.assertNotNull(VERSIONMETA.forge().forgeVersionsArray()); + Assertions.assertNotNull(VERSIONMETA.forge().forgeVersionsArrayDescending()); + VERSIONMETA.forge().forgeVersions().forEach(forgeVersion -> { + Assertions.assertTrue(VERSIONMETA.forge().getForgeInstance(forgeVersion).isPresent()); + Assertions.assertNotNull(VERSIONMETA.forge().getForgeInstance(forgeVersion).get()); + Assertions.assertNotNull(VERSIONMETA.forge().getForgeInstance(forgeVersion).get().forgeVersion()); + Assertions.assertNotNull(VERSIONMETA.forge().getForgeInstance(forgeVersion).get().minecraftVersion()); + Assertions.assertNotNull(VERSIONMETA.forge().getForgeInstance(forgeVersion).get().installerUrl()); + Assertions.assertNotNull(VERSIONMETA.forge().getForgeInstance(forgeVersion).get().minecraftClient()); + }); + VERSIONMETA.forge().minecraftVersionsAscending().forEach(minecraftVersion -> { + Assertions.assertTrue(VERSIONMETA.forge().getForgeInstances(minecraftVersion).isPresent()); + VERSIONMETA.forge().getForgeInstances(minecraftVersion).get().forEach(instance -> { + Assertions.assertNotNull(instance); + Assertions.assertNotNull(instance.installerUrl()); + Assertions.assertNotNull(instance.forgeVersion()); + Assertions.assertNotNull(instance.minecraftVersion()); + Assertions.assertNotNull(instance.minecraftClient()); + }); + + }); + VERSIONMETA.forge().minecraftVersionsDescending().forEach(minecraftVersion -> { + Assertions.assertTrue(VERSIONMETA.forge().getForgeInstances(minecraftVersion).isPresent()); + if (VERSIONMETA.forge().getForgeInstances(minecraftVersion).isPresent()) { + VERSIONMETA.forge().getForgeInstances(minecraftVersion).get().forEach(instance -> { + Assertions.assertNotNull(instance); + Assertions.assertNotNull(instance.installerUrl()); + Assertions.assertNotNull(instance.forgeVersion()); + Assertions.assertNotNull(instance.minecraftVersion()); + Assertions.assertNotNull(instance.minecraftClient()); + }); + } + }); + Assertions.assertNotNull(VERSIONMETA.forge().latestForgeVersion("1.18.2").get()); + Assertions.assertTrue(VERSIONMETA.forge().latestForgeVersion("1.18.2").isPresent()); + Assertions.assertFalse(VERSIONMETA.forge().latestForgeVersion("1.18.2123").isPresent()); + Assertions.assertNotNull(VERSIONMETA.forge().oldestForgeVersion("1.18.2").get()); + Assertions.assertTrue(VERSIONMETA.forge().oldestForgeVersion("1.18.2").isPresent()); + Assertions.assertFalse(VERSIONMETA.forge().oldestForgeVersion("1.18.2123").isPresent()); + Assertions.assertNotNull(VERSIONMETA.forge().minecraftVersionsArrayAscending()); + Assertions.assertEquals(VERSIONMETA.forge().minecraftVersionsArrayAscending().length,VERSIONMETA.forge().minecraftVersionsAscending().size()); + Assertions.assertEquals( + VERSIONMETA.forge().minecraftVersionsArrayAscending()[0], + VERSIONMETA.forge().minecraftVersionsArrayDescending()[VERSIONMETA.forge().minecraftVersionsArrayDescending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.forge().minecraftVersionsArrayDescending()); + Assertions.assertEquals(VERSIONMETA.forge().minecraftVersionsArrayDescending().length,VERSIONMETA.forge().minecraftVersionsDescending().size()); + Assertions.assertEquals( + VERSIONMETA.forge().minecraftVersionsArrayDescending()[0], + VERSIONMETA.forge().minecraftVersionsArrayAscending()[VERSIONMETA.forge().minecraftVersionsArrayAscending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.forge().availableForgeVersionsAscending("1.16.5").get()); + Assertions.assertTrue(VERSIONMETA.forge().availableForgeVersionsAscending("1.16.5").isPresent()); + Assertions.assertFalse(VERSIONMETA.forge().availableForgeVersionsAscending("1.16.5123").isPresent()); + Assertions.assertNotNull(VERSIONMETA.forge().availableForgeVersionsDescending("1.16.5").get()); + Assertions.assertTrue(VERSIONMETA.forge().availableForgeVersionsDescending("1.16.5").isPresent()); + Assertions.assertFalse(VERSIONMETA.forge().availableForgeVersionsDescending("1.16.5123").isPresent()); + Assertions.assertNotNull(VERSIONMETA.forge().availableForgeVersionsArrayAscending("1.16.5").get()); + Assertions.assertTrue(VERSIONMETA.forge().availableForgeVersionsArrayAscending("1.16.5").isPresent()); + Assertions.assertFalse(VERSIONMETA.forge().availableForgeVersionsArrayAscending("1.16.5123").isPresent()); + Assertions.assertEquals(VERSIONMETA.forge().availableForgeVersionsArrayAscending("1.16.5").get().length,VERSIONMETA.forge().availableForgeVersionsAscending("1.16.5").get().size()); + Assertions.assertEquals( + VERSIONMETA.forge().availableForgeVersionsArrayAscending("1.16.5").get()[0], + VERSIONMETA.forge().availableForgeVersionsArrayDescending("1.16.5").get()[VERSIONMETA.forge().availableForgeVersionsArrayDescending("1.16.5").get().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.forge().availableForgeVersionsArrayDescending("1.16.5").get()); + Assertions.assertTrue(VERSIONMETA.forge().availableForgeVersionsArrayDescending("1.16.5").isPresent()); + Assertions.assertFalse(VERSIONMETA.forge().availableForgeVersionsArrayDescending("1.16.5123").isPresent()); + Assertions.assertEquals(VERSIONMETA.forge().availableForgeVersionsArrayDescending("1.16.5").get().length,VERSIONMETA.forge().availableForgeVersionsDescending("1.16.5").get().size()); + Assertions.assertEquals( + VERSIONMETA.forge().availableForgeVersionsArrayDescending("1.16.5").get()[0], + VERSIONMETA.forge().availableForgeVersionsArrayAscending("1.16.5").get()[VERSIONMETA.forge().availableForgeVersionsArrayAscending("1.16.5").get().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.forge().installerUrl("40.0.45").get()); + Assertions.assertTrue(VERSIONMETA.forge().installerUrl("40.0.45").isPresent()); + Assertions.assertFalse(VERSIONMETA.forge().installerUrl("40.0.41235").isPresent()); + } + + @Test + void fabric() { + Assertions.assertNotNull(VERSIONMETA.fabric().loaderVersionsAscending()); + Assertions.assertNotNull(VERSIONMETA.fabric().loaderVersionsDescending()); + Assertions.assertNotNull(VERSIONMETA.fabric().loaderVersionsArrayAscending()); + Assertions.assertNotNull(VERSIONMETA.fabric().loaderVersionsArrayDescending()); + Assertions.assertNotNull(VERSIONMETA.fabric().latestLoaderVersion()); + Assertions.assertNotNull(VERSIONMETA.fabric().releaseLoaderVersion()); + Assertions.assertNotNull(VERSIONMETA.fabric().latestInstallerVersion()); + Assertions.assertNotNull(VERSIONMETA.fabric().releaseInstallerVersion()); + Assertions.assertNotNull(VERSIONMETA.fabric().installerVersionsAscending()); + Assertions.assertNotNull(VERSIONMETA.fabric().installerVersionsDescending()); + Assertions.assertNotNull(VERSIONMETA.fabric().installerVersionsAscending()); + Assertions.assertNotNull(VERSIONMETA.fabric().installerVersionsArrayAscending()); + Assertions.assertEquals(VERSIONMETA.fabric().installerVersionsArrayAscending().length,VERSIONMETA.fabric().installerVersionsAscending().size()); + Assertions.assertEquals( + VERSIONMETA.fabric().installerVersionsArrayAscending()[0], + VERSIONMETA.fabric().installerVersionsArrayDescending()[VERSIONMETA.fabric().installerVersionsArrayDescending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.fabric().installerVersionsArrayDescending()); + Assertions.assertEquals(VERSIONMETA.fabric().installerVersionsArrayDescending().length,VERSIONMETA.fabric().installerVersionsDescending().size()); + Assertions.assertEquals( + VERSIONMETA.fabric().installerVersionsArrayDescending()[0], + VERSIONMETA.fabric().installerVersionsArrayAscending()[VERSIONMETA.fabric().installerVersionsArrayAscending().length-1] + ); + Assertions.assertNotNull(VERSIONMETA.fabric().latestInstallerUrl()); + Assertions.assertNotNull(VERSIONMETA.fabric().releaseInstallerUrl()); + VERSIONMETA.fabric().installerVersionsAscending().forEach(version -> { + Assertions.assertTrue(VERSIONMETA.fabric().isInstallerUrlAvailable(version)); + Assertions.assertNotNull(VERSIONMETA.fabric().installerUrl(version).get()); + }); + Assertions.assertFalse(VERSIONMETA.fabric().isInstallerUrlAvailable("0.11233.3")); + Assertions.assertFalse(VERSIONMETA.fabric().installerUrl("0.13123.3").isPresent()); + Assertions.assertTrue(VERSIONMETA.fabric().checkFabricVersion("0.13.3")); + Assertions.assertFalse(VERSIONMETA.fabric().checkFabricVersion("0.12313.3")); + } +} diff --git a/backend/test/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpackTest.java b/backend/test/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpackTest.java index 0024c86542023bc261e7d06153620857b46f0497..e9840e050371ccf914cdc0dd0bafebd6a31266b1 100644 --- a/backend/test/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpackTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpackTest.java @@ -5,8 +5,9 @@ import com.therandomlabs.curseapi.CurseException; import de.griefed.serverpackcreator.ConfigurationModel; import de.griefed.serverpackcreator.i18n.LocalizationManager; import de.griefed.serverpackcreator.ApplicationProperties; -import de.griefed.serverpackcreator.VersionLister; -import de.griefed.serverpackcreator.utilities.*; +import de.griefed.serverpackcreator.utilities.ConfigUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; @@ -25,33 +26,19 @@ import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; class CurseCreateModpackTest { private final CurseCreateModpack CURSECREATEMODPACK; - private final LocalizationManager LOCALIZATIONMANAGER; - private final ApplicationProperties APPLICATIONPROPERTIES; - private final VersionLister VERSIONLISTER; - private final BooleanUtilities BOOLEANUTILITIES; - private final ListUtilities LISTUTILITIES; - private final StringUtilities STRINGUTILITIES; - private final ConfigUtilities CONFIGUTILITIES; - private final SystemUtilities SYSTEMUTILITIES; - CurseCreateModpackTest() { + CurseCreateModpackTest() throws IOException { try { FileUtils.copyFile(new File("backend/main/resources/serverpackcreator.properties"),new File("serverpackcreator.properties")); } catch (IOException e) { e.printStackTrace(); } - this.APPLICATIONPROPERTIES = new ApplicationProperties(); - - this.LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); - LOCALIZATIONMANAGER.initialize(); - LISTUTILITIES = new ListUtilities(); - STRINGUTILITIES = new StringUtilities(); - SYSTEMUTILITIES = new SystemUtilities(); - BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - this.VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); - CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, BOOLEANUTILITIES, LISTUTILITIES, APPLICATIONPROPERTIES, STRINGUTILITIES, VERSIONLISTER); - this.CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONLISTER, BOOLEANUTILITIES, LISTUTILITIES, STRINGUTILITIES, CONFIGUTILITIES, SYSTEMUTILITIES); + ApplicationProperties APPLICATIONPROPERTIES = new ApplicationProperties(); + LocalizationManager LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); + VersionMeta VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); + Utilities UTILITIES = new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + this.CURSECREATEMODPACK = new CurseCreateModpack(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES, VERSIONMETA, UTILITIES, new ConfigUtilities(LOCALIZATIONMANAGER, UTILITIES, APPLICATIONPROPERTIES, VERSIONMETA)); } @Test diff --git a/backend/test/java/de/griefed/serverpackcreator/i18n/LocalizationManagerTest.java b/backend/test/java/de/griefed/serverpackcreator/i18n/LocalizationManagerTest.java index d85c894601deb5e3c9a204e5ea560a0518f8939a..6b9b9f1a87d9886a4cb2f1e9087b8bfca5f373a1 100644 --- a/backend/test/java/de/griefed/serverpackcreator/i18n/LocalizationManagerTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/i18n/LocalizationManagerTest.java @@ -21,8 +21,6 @@ public class LocalizationManagerTest { @Test void newTest() { FileUtils.deleteQuietly(new File("lang")); - - LOG.info("newTest() en_us"); LocalizationManager localizationManager = new LocalizationManager(); Assertions.assertEquals("English (United States)",localizationManager.getLocalizedString("localeUnlocalizedName")); } diff --git a/backend/test/java/de/griefed/serverpackcreator/ApplicationPluginsTest.java b/backend/test/java/de/griefed/serverpackcreator/plugins/ApplicationPluginsTest.java similarity index 62% rename from backend/test/java/de/griefed/serverpackcreator/ApplicationPluginsTest.java rename to backend/test/java/de/griefed/serverpackcreator/plugins/ApplicationPluginsTest.java index bbe32a513ef3844f87d13aa3fd4df437857f778f..bc33f2d9eaa1d337b3d06d379606b55718102f54 100644 --- a/backend/test/java/de/griefed/serverpackcreator/ApplicationPluginsTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/plugins/ApplicationPluginsTest.java @@ -1,8 +1,7 @@ -package de.griefed.serverpackcreator; +package de.griefed.serverpackcreator.plugins; import org.apache.logging.log4j.core.util.FileUtils; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.io.File; @@ -11,7 +10,6 @@ import java.nio.file.Paths; public class ApplicationPluginsTest { - @Disabled @Test void test() { try { @@ -22,10 +20,10 @@ public class ApplicationPluginsTest { } catch (Exception ignored) {} ApplicationPlugins applicationPlugins = new ApplicationPlugins(); Assertions.assertNotNull(applicationPlugins); - Assertions.assertEquals(1,applicationPlugins.PLUGINS_SERVERPACKARCHIVECREATED.size()); - Assertions.assertEquals(1,applicationPlugins.PLUGINS_SERVERPACKCREATED.size()); - Assertions.assertEquals(1,applicationPlugins.PLUGINS_SERVERPACKSTART.size()); - Assertions.assertEquals(1,applicationPlugins.PLUGINS_TABBEDPANE.size()); + Assertions.assertEquals(1,applicationPlugins.pluginsPostGenExtension().size()); + Assertions.assertEquals(1,applicationPlugins.pluginsTabExtension().size()); + Assertions.assertEquals(1,applicationPlugins.pluginsPreGenExtension().size()); + Assertions.assertEquals(1,applicationPlugins.pluginsPreZipExtension().size()); } } diff --git a/backend/test/java/de/griefed/serverpackcreator/spring/jms/ArtemisConfigTest.java b/backend/test/java/de/griefed/serverpackcreator/spring/jms/ArtemisConfigTest.java index 1af0ce80f213af22ed8f578cc723659e5c550558..fbca30b04f54a881cd50dbc9abcb5b9e57fe73c3 100644 --- a/backend/test/java/de/griefed/serverpackcreator/spring/jms/ArtemisConfigTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/spring/jms/ArtemisConfigTest.java @@ -34,9 +34,6 @@ public class ArtemisConfigTest { private final String QUEUE_UNIQUE_ID = "unique_id"; private final String QUEUE_TASKS = "tasks.background"; - private final DefaultFiles DEFAULTFILES; - private final LocalizationManager LOCALIZATIONMANAGER; - private final ApplicationProperties APPLICATIONPROPERTIES; @Autowired ArtemisConfigTest(JmsTemplate injectedJmsTemplate) { @@ -46,16 +43,14 @@ public class ArtemisConfigTest { e.printStackTrace(); } - this.APPLICATIONPROPERTIES = new ApplicationProperties(); + ApplicationProperties APPLICATIONPROPERTIES = new ApplicationProperties(); this.jmsTemplate = injectedJmsTemplate; this.jmsTemplate.setReceiveTimeout(JmsDestinationAccessor.RECEIVE_TIMEOUT_NO_WAIT); - LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); - LOCALIZATIONMANAGER.initialize(); - DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - DEFAULTFILES.filesSetup(); + LocalizationManager LOCALIZATIONMANAGER = new LocalizationManager(APPLICATIONPROPERTIES); + DefaultFiles DEFAULTFILES = new DefaultFiles(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); DEFAULTFILES.checkDatabase(); } diff --git a/backend/test/java/de/griefed/serverpackcreator/utilities/ConfigUtilitiesTest.java b/backend/test/java/de/griefed/serverpackcreator/utilities/ConfigUtilitiesTest.java index 1550b2d11b4dd981ab0dce1f0a95a5e1363141d4..eb42509c90a961b9f2b1d5673f9cd9fa589a98ea 100644 --- a/backend/test/java/de/griefed/serverpackcreator/utilities/ConfigUtilitiesTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/utilities/ConfigUtilitiesTest.java @@ -5,8 +5,12 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import de.griefed.serverpackcreator.ApplicationProperties; import de.griefed.serverpackcreator.ConfigurationModel; -import de.griefed.serverpackcreator.VersionLister; import de.griefed.serverpackcreator.i18n.LocalizationManager; +import de.griefed.serverpackcreator.utilities.commonutilities.BooleanUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.ListUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.StringUtilities; +import de.griefed.serverpackcreator.utilities.commonutilities.Utilities; +import de.griefed.serverpackcreator.versionmeta.VersionMeta; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -20,22 +24,16 @@ import java.util.List; public class ConfigUtilitiesTest { - private final LocalizationManager LOCALIZATIONMANAGER; - private final ApplicationProperties APPLICATIONPROPERTIES; - private final BooleanUtilities BOOLEANUTILITIES; - private final ListUtilities LISTUTILITIES; - private final StringUtilities STRINGUTILITIES; private final ConfigUtilities CONFIGUTILITIES; - private final VersionLister VERSIONLISTER; - - ConfigUtilitiesTest() { - this.LOCALIZATIONMANAGER = new LocalizationManager(); - this.APPLICATIONPROPERTIES = new ApplicationProperties(); - this.BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); - this.LISTUTILITIES = new ListUtilities(); - this.STRINGUTILITIES = new StringUtilities(); - this.VERSIONLISTER = new VersionLister(APPLICATIONPROPERTIES); - this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, BOOLEANUTILITIES, LISTUTILITIES, APPLICATIONPROPERTIES, STRINGUTILITIES, VERSIONLISTER); + + ConfigUtilitiesTest() throws IOException { + LocalizationManager LOCALIZATIONMANAGER = new LocalizationManager(); + ApplicationProperties APPLICATIONPROPERTIES = new ApplicationProperties(); + BooleanUtilities BOOLEANUTILITIES = new BooleanUtilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES); + ListUtilities LISTUTILITIES = new ListUtilities(); + StringUtilities STRINGUTILITIES = new StringUtilities(); + VersionMeta VERSIONMETA = new VersionMeta(APPLICATIONPROPERTIES); + this.CONFIGUTILITIES = new ConfigUtilities(LOCALIZATIONMANAGER, new Utilities(LOCALIZATIONMANAGER, APPLICATIONPROPERTIES), APPLICATIONPROPERTIES, VERSIONMETA); } @SuppressWarnings("ResultOfMethodCallIgnored") diff --git a/backend/test/java/de/griefed/serverpackcreator/utilities/SystemUtilitiesTest.java b/backend/test/java/de/griefed/serverpackcreator/utilities/SystemUtilitiesTest.java deleted file mode 100644 index 40da0deac62e4c91a841cc33a51eca698c117dbf..0000000000000000000000000000000000000000 --- a/backend/test/java/de/griefed/serverpackcreator/utilities/SystemUtilitiesTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package de.griefed.serverpackcreator.utilities; - -import org.apache.commons.io.FileUtils; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Comparator; - -public class SystemUtilitiesTest { - - private final SystemUtilities SYSTEMUTILITIES; - - SystemUtilitiesTest() { - this.SYSTEMUTILITIES = new SystemUtilities(); - } - - @Test - void acquireJavaPathFromSystemTest() { - Assertions.assertNotNull(SYSTEMUTILITIES.acquireJavaPathFromSystem()); - Assertions.assertTrue(new File(SYSTEMUTILITIES.acquireJavaPathFromSystem()).exists()); - Assertions.assertTrue(new File(SYSTEMUTILITIES.acquireJavaPathFromSystem()).isFile()); - Assertions.assertTrue(SYSTEMUTILITIES.acquireJavaPathFromSystem().replace("\\","/").contains("bin/java")); - } - - @Test - void downloadFileTest() { - try { - SYSTEMUTILITIES.downloadFile("Fabric-Server-Launcher.jar",new URL("https://meta.fabricmc.net/v2/versions/loader/1.18.1/0.12.12/0.10.2/server/jar")); - } catch (Exception ignored) {} - Assertions.assertTrue(new File("Fabric-Server-Launcher.jar").exists()); - FileUtils.deleteQuietly(new File("Fabric-Server-Launcher.jar")); - try { - SYSTEMUTILITIES.downloadFile("some_foooooolder/foooobar/Fabric-Server-Launcher.jar",new URL("https://meta.fabricmc.net/v2/versions/loader/1.18.1/0.12.12/0.10.2/server/jar")); - } catch (Exception ignored) {} - Assertions.assertTrue(new File("some_foooooolder/foooobar/Fabric-Server-Launcher.jar").exists()); - FileUtils.deleteQuietly(new File("some_foooooolder")); - } - - @Test - void unzipArchiveTest() { - String modpackDir = "backend/test/resources/curseforge_tests"; - String zipFile = "backend/test/resources/curseforge_tests/modpack.zip"; - SYSTEMUTILITIES.unzipArchive(zipFile, modpackDir); - Assertions.assertTrue(new File("./backend/test/resources/curseforge_tests/manifest.json").exists()); - Assertions.assertTrue(new File("./backend/test/resources/curseforge_tests/modlist.html").exists()); - Assertions.assertTrue(new File("./backend/test/resources/curseforge_tests/overrides").isDirectory()); - FileUtils.deleteQuietly(new File("./backend/test/resources/curseforge_tests/manifest.json")); - FileUtils.deleteQuietly(new File("./backend/test/resources/curseforge_tests/modlist.html")); - FileUtils.deleteQuietly(new File("./backend/test/resources/curseforge_tests/overrides")); - } - - @SuppressWarnings("ResultOfMethodCallIgnored") - @Test - void replaceFileTest() throws IOException { - File source = new File("source.file"); - File destination = new File("destination.file"); - source.createNewFile(); - destination.createNewFile(); - SYSTEMUTILITIES.replaceFile(source,destination); - Assertions.assertFalse(source.exists()); - Assertions.assertTrue(destination.exists()); - FileUtils.deleteQuietly(destination); - } -} diff --git a/backend/test/java/de/griefed/serverpackcreator/utilities/BooleanUtilitiesTest.java b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/BooleanUtilitiesTest.java similarity index 96% rename from backend/test/java/de/griefed/serverpackcreator/utilities/BooleanUtilitiesTest.java rename to backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/BooleanUtilitiesTest.java index 4dd1c001d98d348be43210a2fb741aea4e04bd49..426cc241222b5e584d96189d81706241cc8510bd 100644 --- a/backend/test/java/de/griefed/serverpackcreator/utilities/BooleanUtilitiesTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/BooleanUtilitiesTest.java @@ -1,4 +1,4 @@ -package de.griefed.serverpackcreator.utilities; +package de.griefed.serverpackcreator.utilities.commonutilities; import de.griefed.serverpackcreator.ApplicationProperties; import de.griefed.serverpackcreator.i18n.LocalizationManager; diff --git a/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/FileUtilitiesTest.java b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/FileUtilitiesTest.java new file mode 100644 index 0000000000000000000000000000000000000000..9934803b47d1c1184628755e35e42dca95006402 --- /dev/null +++ b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/FileUtilitiesTest.java @@ -0,0 +1,44 @@ +package de.griefed.serverpackcreator.utilities.commonutilities; + +import de.griefed.serverpackcreator.utilities.commonutilities.FileUtilities; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.IOException; + +public class FileUtilitiesTest { + + private final FileUtilities FILE_UTILITIES; + + FileUtilitiesTest() { + this.FILE_UTILITIES = new FileUtilities(); + } + + @Test + void unzipArchiveTest() { + String modpackDir = "backend/test/resources/curseforge_tests"; + String zipFile = "backend/test/resources/curseforge_tests/modpack.zip"; + FILE_UTILITIES.unzipArchive(zipFile, modpackDir); + Assertions.assertTrue(new File("./backend/test/resources/curseforge_tests/manifest.json").exists()); + Assertions.assertTrue(new File("./backend/test/resources/curseforge_tests/modlist.html").exists()); + Assertions.assertTrue(new File("./backend/test/resources/curseforge_tests/overrides").isDirectory()); + FileUtils.deleteQuietly(new File("./backend/test/resources/curseforge_tests/manifest.json")); + FileUtils.deleteQuietly(new File("./backend/test/resources/curseforge_tests/modlist.html")); + FileUtils.deleteQuietly(new File("./backend/test/resources/curseforge_tests/overrides")); + } + + @SuppressWarnings("ResultOfMethodCallIgnored") + @Test + void replaceFileTest() throws IOException { + File source = new File("source.file"); + File destination = new File("destination.file"); + source.createNewFile(); + destination.createNewFile(); + FILE_UTILITIES.replaceFile(source,destination); + Assertions.assertFalse(source.exists()); + Assertions.assertTrue(destination.exists()); + FileUtils.deleteQuietly(destination); + } +} diff --git a/backend/test/java/de/griefed/serverpackcreator/utilities/JarUtilitiesTest.java b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/JarUtilitiesTest.java similarity index 96% rename from backend/test/java/de/griefed/serverpackcreator/utilities/JarUtilitiesTest.java rename to backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/JarUtilitiesTest.java index 1cd2499d5a62362f702094744473c18ecd0a18cc..87b94a50ac7f7c20fe284abd760ebb916f0ecec4 100644 --- a/backend/test/java/de/griefed/serverpackcreator/utilities/JarUtilitiesTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/JarUtilitiesTest.java @@ -1,11 +1,10 @@ -package de.griefed.serverpackcreator.utilities; +package de.griefed.serverpackcreator.utilities.commonutilities; import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; -import java.io.IOException; import java.util.HashMap; public class JarUtilitiesTest { diff --git a/backend/test/java/de/griefed/serverpackcreator/utilities/ListUtilitiesTest.java b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/ListUtilitiesTest.java similarity index 96% rename from backend/test/java/de/griefed/serverpackcreator/utilities/ListUtilitiesTest.java rename to backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/ListUtilitiesTest.java index d6b79dda7ab6cb52f3f0ab653c9a5f80a02a32c4..8a8100d10c63e89a8d4f5ff2b5757412b6bc97d8 100644 --- a/backend/test/java/de/griefed/serverpackcreator/utilities/ListUtilitiesTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/ListUtilitiesTest.java @@ -1,5 +1,6 @@ -package de.griefed.serverpackcreator.utilities; +package de.griefed.serverpackcreator.utilities.commonutilities; +import de.griefed.serverpackcreator.utilities.commonutilities.ListUtilities; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/backend/test/java/de/griefed/serverpackcreator/utilities/StringUtilitiesTest.java b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/StringUtilitiesTest.java similarity index 83% rename from backend/test/java/de/griefed/serverpackcreator/utilities/StringUtilitiesTest.java rename to backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/StringUtilitiesTest.java index 0403d4717ac96dd17d646a390281557db7cc5a33..75373b0ffba10d4597a766890d62d1a76171fa3e 100644 --- a/backend/test/java/de/griefed/serverpackcreator/utilities/StringUtilitiesTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/StringUtilitiesTest.java @@ -1,5 +1,6 @@ -package de.griefed.serverpackcreator.utilities; +package de.griefed.serverpackcreator.utilities.commonutilities; +import de.griefed.serverpackcreator.utilities.commonutilities.StringUtilities; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/SystemUtilitiesTest.java b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/SystemUtilitiesTest.java new file mode 100644 index 0000000000000000000000000000000000000000..9b5261615485d0b9f7fcb1b3c461512dbbd5ca02 --- /dev/null +++ b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/SystemUtilitiesTest.java @@ -0,0 +1,24 @@ +package de.griefed.serverpackcreator.utilities.commonutilities; + +import de.griefed.serverpackcreator.utilities.commonutilities.SystemUtilities; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.File; + +public class SystemUtilitiesTest { + + private final SystemUtilities SYSTEMUTILITIES; + + SystemUtilitiesTest() { + this.SYSTEMUTILITIES = new SystemUtilities(); + } + + @Test + void acquireJavaPathFromSystemTest() { + Assertions.assertNotNull(SYSTEMUTILITIES.acquireJavaPathFromSystem()); + Assertions.assertTrue(new File(SYSTEMUTILITIES.acquireJavaPathFromSystem()).exists()); + Assertions.assertTrue(new File(SYSTEMUTILITIES.acquireJavaPathFromSystem()).isFile()); + Assertions.assertTrue(SYSTEMUTILITIES.acquireJavaPathFromSystem().replace("\\","/").contains("bin/java")); + } +} diff --git a/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/WebUtilitiesTest.java b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/WebUtilitiesTest.java new file mode 100644 index 0000000000000000000000000000000000000000..6960ef61659534ec8c9035e1101a23d732eebd73 --- /dev/null +++ b/backend/test/java/de/griefed/serverpackcreator/utilities/commonutilities/WebUtilitiesTest.java @@ -0,0 +1,32 @@ +package de.griefed.serverpackcreator.utilities.commonutilities; + +import de.griefed.serverpackcreator.utilities.commonutilities.WebUtilities; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.net.URL; + +public class WebUtilitiesTest { + + private final WebUtilities WEB_UTILITIES; + + WebUtilitiesTest() { + this.WEB_UTILITIES = new WebUtilities(); + } + + @Test + void downloadFileTest() { + try { + WEB_UTILITIES.downloadFile("Fabric-Server-Launcher.jar",new URL("https://meta.fabricmc.net/v2/versions/loader/1.18.1/0.12.12/0.10.2/server/jar")); + } catch (Exception ignored) {} + Assertions.assertTrue(new File("Fabric-Server-Launcher.jar").exists()); + FileUtils.deleteQuietly(new File("Fabric-Server-Launcher.jar")); + try { + WEB_UTILITIES.downloadFile("some_foooooolder/foooobar/Fabric-Server-Launcher.jar",new URL("https://meta.fabricmc.net/v2/versions/loader/1.18.1/0.12.12/0.10.2/server/jar")); + } catch (Exception ignored) {} + Assertions.assertTrue(new File("some_foooooolder/foooobar/Fabric-Server-Launcher.jar").exists()); + FileUtils.deleteQuietly(new File("some_foooooolder")); + } +} diff --git a/backend/test/resources/fabric_tests_server_pack.zip b/backend/test/resources/fabric_tests_server_pack.zip new file mode 100644 index 0000000000000000000000000000000000000000..df88148ac462a6b43624428d799e912841d20f7f Binary files /dev/null and b/backend/test/resources/fabric_tests_server_pack.zip differ diff --git a/backend/test/resources/forge_tests_server_pack.zip b/backend/test/resources/forge_tests_server_pack.zip new file mode 100644 index 0000000000000000000000000000000000000000..2aaa3dde278d2731c0f5eccb652b21fe56cdee3a Binary files /dev/null and b/backend/test/resources/forge_tests_server_pack.zip differ diff --git a/backend/test/resources/serverpackcreator.properties b/backend/test/resources/serverpackcreator.properties index 4b0d92c1666721cba7f4f1d3dea3fe7f9ef2528e..f4f137094f8976abb165a8b5d42dc72cd3b57a25 100644 --- a/backend/test/resources/serverpackcreator.properties +++ b/backend/test/resources/serverpackcreator.properties @@ -1,6 +1,6 @@ # Supported languages: [en_us, uk_ua, de_de] de.griefed.serverpackcreator.language=en_us -de.griefed.serverpackcreator.configuration.fallbackmodslist=3dSkinLayers-,AdvancementPlaques-,AmbientSounds_,armorchroma-,backtools-,BetterAdvancements-,BetterAnimationsCollection-,BetterDarkMode-,BetterF3-,BetterFoliage-,BetterPingDisplay-,BetterPlacement-,bhmenu-,BH-Menu-,Blur-,catalogue-,charmonium-,Charmonium-,cherishedworlds-,classicbar-,clickadv-,ClientTweaks_,configured-,Controlling-,CraftPresence-,CTM-,customdiscordrpc-,CustomMainMenu-,dashloader-,DefaultOptions_,defaultoptions-,desiredservers-,Ding-,drippyloadingscreen_,drippyloadingscreen-,Durability101-,dynamic-music-,DynamicSurroundings-,DynamicSurroundingsHuds-,dynmus-,EiraMoticons_,eiramoticons-,EnchantmentDescriptions-,entity-texture-features-,EquipmentCompare-,extremesoundmuffler-,extremeSoundMuffler-,Fallingleaves-,fallingleaves-,fancymenu_,findme-,flickerfix-,FpsReducer-,FullscreenWindowed-,InventoryEssentials_,InventorySpam-,InventoryTweaks-,invtweaks-,ItemBorders-,itemzoom,itlt-,jeed-,jehc-,jeiintegration_,JEITweaker-,just-enough-harvestcraft-,justenoughbeacons-,JustEnoughCalculation-,JustEnoughProfessions-,JustEnoughProfessions-,JustEnoughResources-,keywizard-,konkrete_,lazydfu-,LegendaryTooltips-,light-overlay-,LightOverlay-,LLOverlayReloaded-,loadmyresources_,lootbeams-,mcbindtype-,medievalmusic-,modnametooltip_,modnametooltip-,moreoverlays-,MouseTweaks-,multihotbar-,MyServerIsCompatible-,Neat ,NotifMod-,OldJavaWarning-,OptiFine,OptiForge,ornaments-,overloadedarmorbar-,PackMenu-,PickUpNotifier-,Ping-,preciseblockplacing-,presencefootsteps-,PresenceFootsteps-,ReAuth-,ResourceLoader-,shutupexperimentalsettings-,SimpleDiscordRichPresence-,smoothboot-,sounddeviceoptions-,SpawnerFix-,spoticraft-,tconplanner-,timestamps-,Tips-,TipTheScales-,Toast Control-,Toast-Control-,ToastControl-,torchoptimizer-,torohealth-,toughnessbar-,TravelersTitles-,WindowedFullscreen-,WorldNameRandomizer-,yisthereautojump- +de.griefed.serverpackcreator.configuration.fallbackmodslist=3dSkinLayers-,3dskinlayers-,Absolutely-Not-A-Zoom-Mod-,AdvancementPlaques-,AmbientEnvironment-,AmbientSounds_,antighost-,armorchroma-,armorpointspp-,ArmorSoundTweak-,authme-,autoreconnect-,auto-reconnect-,axolotl-item-fix-,backtools-,BetterAdvancements-,BetterAnimationsCollection-,BetterDarkMode-,BetterF3-,BetterFoliage-,BetterPingDisplay-,BetterPlacement-,BetterTaskbar-,bhmenu-,BH-Menu-,Blur-,borderless-mining-,catalogue-,charmonium-,Charmonium-,chat_heads-,cherishedworlds-,classicbar-,clickadv-,ClientTweaks_,configured-,Controlling-,CraftPresence-,CTM-,cullleaves-,customdiscordrpc-,CustomMainMenu-,dashloader-,DefaultOptions_,defaultoptions-,DeleteWorldsToTrash-,desiredservers-,Ding-,drippyloadingscreen_,drippyloadingscreen-,DripSounds-,Durability101-,dynamic-music-,DynamicSurroundings-,DynamicSurroundingsHuds-,dynmus-,effective-,EiraMoticons_,eiramoticons-,EnchantmentDescriptions-,entity-texture-features-,EquipmentCompare-,extremesoundmuffler-,extremeSoundMuffler-,fabricemotes-,Fallingleaves-,fallingleaves-,fancymenu_,findme-,flickerfix-,FPS-Monitor-,FpsReducer-,FullscreenWindowed-,InventoryEssentials_,InventorySpam-,InventoryTweaks-,invtweaks-,ItemBorders-,itemzoom,itlt-,jeed-,jehc-,jeiintegration_,JEITweaker-,just-enough-harvestcraft-,justenoughbeacons-,JustEnoughCalculation-,JustEnoughProfessions-,JustEnoughProfessions-,JustEnoughResources-,keymap-,keywizard-,konkrete_,lazydfu-,LegendaryTooltips-,light-overlay-,LightOverlay-,LLOverlayReloaded-,loadmyresources_,lootbeams-,mcbindtype-,medievalmusic-,modnametooltip_,modnametooltip-,moreoverlays-,MouseTweaks-,movement-vision-,multihotbar-,musicdr-,music-duration-reducer-,MyServerIsCompatible-,Neat ,ngrok-lan-expose-mod-,NotifMod-,OldJavaWarning-,OptiFine,OptiForge,ornaments-,overloadedarmorbar-,PackMenu-,PickUpNotifier-,Ping-,preciseblockplacing-,presencefootsteps-,PresenceFootsteps-,ReAuth-,ResourceLoader-,shutupexperimentalsettings-,SimpleDiscordRichPresence-,smoothboot-,sounddeviceoptions-,SpawnerFix-,spoticraft-,tconplanner-,timestamps-,Tips-,TipTheScales-,Toast Control-,Toast-Control-,ToastControl-,torchoptimizer-,torohealth-,toughnessbar-,TravelersTitles-,WindowedFullscreen-,WorldNameRandomizer-,yisthereautojump- de.griefed.serverpackcreator.configuration.hastebinserver=https://haste.zneix.eu/documents de.griefed.serverpackcreator.serverpack.autodiscoverenabled=true de.griefed.serverpackcreator.gui.darkmode=true diff --git a/backend/test/resources/testresources/serverpackcreatorexampleaddon.jar b/backend/test/resources/testresources/serverpackcreatorexampleaddon.jar new file mode 100644 index 0000000000000000000000000000000000000000..a0392a78ba89b2c2e7724ec4ef9a299aba36573b Binary files /dev/null and b/backend/test/resources/testresources/serverpackcreatorexampleaddon.jar differ diff --git a/build.gradle b/build.gradle index 611f9aae45ece21bf1650155a029999a2217353b..1a7b173b85c86fbd0470193f6c4dae1ab4f22fd2 100644 --- a/build.gradle +++ b/build.gradle @@ -94,7 +94,6 @@ dependencies { embed 'org.springframework.boot:spring-boot-starter-artemis:2.6.5' embed 'org.apache.activemq:artemis-jms-server:2.19.1' embed 'com.github.gwenn:sqlite-dialect:0.1.2' - embed 'org.apache.logging.log4j:log4j-web:2.17.2' // Dev tools developmentOnly 'org.springframework.boot:spring-boot-devtools:2.6.5' diff --git a/frontend/src/pages/SubmitRequest.vue b/frontend/src/pages/SubmitRequest.vue index f71be0c5f8901b0c92474b35a3fb5e598c78d03f..b65ed4f4e753be8b3ef7d9eeac598b4dc7845808 100644 --- a/frontend/src/pages/SubmitRequest.vue +++ b/frontend/src/pages/SubmitRequest.vue @@ -240,7 +240,7 @@ UPLOAD AND CREATE FROM ZIP </div> </div> - <div class="column flex-center"> +<!-- <div class="column flex-center"> <q-toggle v-model="installServer" checked-icon="check" @@ -248,14 +248,14 @@ UPLOAD AND CREATE FROM ZIP :color="installServer ? 'positive' : 'negative'" label="Install modloader server?" /> - </div> + </div>--> </div> - <div :class="this.$q.platform.is.mobile ? 'row flex-center' : 'row no-wrap flex-center'"> + <div :class="this.$q.platform.is.mobile ? 'row flex-center' : 'row no-wrap flex-center'" style="margin-top: 20px;"> <div> <q-btn label="Submit" :disable="disableZip" :loading="loading" type="submit" color="primary" /> - <q-btn label="Reset" type="reset" color="warning" class="q-ml-sm" /> + <q-btn label="Reset" type="reset" color="warning" class="q-ml-sm" /> </div> </div> @@ -466,7 +466,7 @@ export default defineComponent({ store, loading: ref(false), tab: ref('zip'), - installServer: ref(true), + installServer: ref(false), /* * CURSE */ @@ -935,41 +935,44 @@ export default defineComponent({ * with versions that are available to the backend, too. */ api.get("/versions/minecraft") - .then(response => { - this.minecraftVersions = response.data.minecraft; + .then(mcResponse => { + this.minecraftVersions = mcResponse.data.minecraft; this.minecraftVersion = this.minecraftVersions[0]; + /* + * Acquire a list of available Forge versions for a given Minecraft version from our backend. + * We do not get this list from Forge directly because we need to make sure we only submit request to the backend + * with versions that are available to the backend, too. + */ + api.get("/versions/forge/" + this.minecraftVersion) + .then(forgeResponse => { + this.forgeVersions = forgeResponse.data.forge; + this.modloaderVersion = this.forgeVersions[0]; + }) + .catch(error => { + console.log(error); + this.errorNotification(error); + }); + }) .catch(error => { console.log(error); this.errorNotification(error); }); + /* - * Acquire a list of available Fabric versions from our backend. - * We do not get this list from Fabric directly because we need to make sure we only submit request to the backend - * with versions that are available to the backend, too. - */ + * Acquire a list of available Fabric versions from our backend. + * We do not get this list from Fabric directly because we need to make sure we only submit request to the backend + * with versions that are available to the backend, too. + */ api.get("/versions/fabric") .then(response => { this.fabricVersions = response.data.fabric; }) - .catch(error => { - console.log(error); - this.errorNotification(error); - }); - /* - * Acquire a list of available Forge versions for a given Minecraft version from our backend. - * We do not get this list from Forge directly because we need to make sure we only submit request to the backend - * with versions that are available to the backend, too. - */ - api.get("/versions/forge/" + this.minecraftVersion) - .then(response => { - this.forgeVersions = response.data.forge; - this.modloaderVersion = this.forgeVersions[0]; - }) .catch(error => { console.log(error); this.errorNotification(error); }); + /* * Check cookies whether the user has previously generated a server pack from a CurseForge projectID,fileID and set * the GUI accordingly.