diff --git a/.gitignore b/.gitignore index db10ec62442244a18d349b2af7a542a16a398e2d..f38cb16af43587f18ac3659947ab609a5ab0e18d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ out *.ipr *.iws -*.iml \ No newline at end of file +*.iml +/libs/ diff --git a/README.md b/README.md index 0846ec9a89cdf9aa562735135d131e0ddeb8c950..8b63bbc06cf670db380bc507f945d851c1b83c44 100644 --- a/README.md +++ b/README.md @@ -2,42 +2,80 @@ This is an example server pack addon for [ServerPackCreator](https://github.com/Griefed/ServerPackCreator) -Server pack addons for ServerPackCreator are executed right after a server pack was generated, allowing for additional -operations and more customization of server packs. Users are free to write their own addons, distribute and share them. +The following endpoints are available in ServerPackCreator to add you extra functionality with a plugin. This example plugin provides examples for all four of them: -This example provides JavaDocs and tests. +- TabExtension: Allows you to add your own JComponent in the form of an additional tab to the GUI. You can run whatever code you want in that tab. -Using this example with a [dev-build of ServerPackCreator](https://git.griefed.de/Griefed/ServerPackCreator/-/pipelines?page=1&scope=all&ref=webservice) would result in the following output to the addons.log file: +- PreGenExtension: Will allow you to run your code before generation of a server pack starts +- PreZipExtension: Will allow you to run your code after a server pack was generated, but before the ZIP-archive is created + +- PostGenExtension: Will allow you to run your code after the server pack ZIP-archive was generated, so right at the on of the SPC process, basically. + +Using this example plugin would result in the following or similar output in ServerPackCreator itself: + +serverpackcreator.log: +``` +INFO [main] (AbstractPluginManager.java:814) - Plugin 'example-plugin@0.0.1' resolved +INFO [main] (AbstractPluginManager.java:357) - Start plugin 'example-plugin@0.0.1' +INFO [main] (ApplicationPlugins.java:74) - Available PreGenExtension plugins: +INFO [main] (ApplicationPlugins.java:76) - Name: ServerPackCreatorExampleAddon +INFO [main] (ApplicationPlugins.java:77) - Description:This is an example addon for ServerPackCreator showcasing all, currently 4, aspects ofServerPackCreators addon functionality. In this example you see code which gets executed before a server pack is generated,code that gets executed after a server pack was generated but before the ZIP-archive is created, code that gets executedafter this ZIP-archive was created, as well as code adding a new tabbed pane to the GUI. +INFO [main] (ApplicationPlugins.java:78) - Version: 0.0.1 +INFO [main] (ApplicationPlugins.java:79) - Author: Griefed +INFO [main] (ApplicationPlugins.java:83) - Available PreZipExtension plugins: +INFO [main] (ApplicationPlugins.java:85) - Name: ServerPackCreatorExampleAddon +INFO [main] (ApplicationPlugins.java:86) - Description:This is an example addon for ServerPackCreator showcasing all, currently 4, aspects ofServerPackCreators addon functionality. In this example you see code which gets executed before a server pack is generated,code that gets executed after a server pack was generated but before the ZIP-archive is created, code that gets executedafter this ZIP-archive was created, as well as code adding a new tabbed pane to the GUI. +INFO [main] (ApplicationPlugins.java:87) - Version: 0.0.1 +INFO [main] (ApplicationPlugins.java:88) - Author: Griefed +INFO [main] (ApplicationPlugins.java:92) - Available PostGenExtension plugins: +INFO [main] (ApplicationPlugins.java:94) - Name: ServerPackCreatorExampleAddon +INFO [main] (ApplicationPlugins.java:95) - Description:This is an example addon for ServerPackCreator showcasing all, currently 4, aspects ofServerPackCreators addon functionality. In this example you see code which gets executed before a server pack is generated,code that gets executed after a server pack was generated but before the ZIP-archive is created, code that gets executedafter this ZIP-archive was created, as well as code adding a new tabbed pane to the GUI. +INFO [main] (ApplicationPlugins.java:96) - Version: 0.0.1 +INFO [main] (ApplicationPlugins.java:97) - Author: Griefed +INFO [main] (ApplicationPlugins.java:101) - Available TabExtension plugins: +INFO [main] (ApplicationPlugins.java:103) - Name: ServerPackCreatorExampleAddon +INFO [main] (ApplicationPlugins.java:104) - Description:This is an example addon for ServerPackCreator showcasing all, currently 4, aspects ofServerPackCreators addon functionality. In this example you see code which gets executed before a server pack is generated,code that gets executed after a server pack was generated but before the ZIP-archive is created, code that gets executedafter this ZIP-archive was created, as well as code adding a new tabbed pane to the GUI. +INFO [main] (ApplicationPlugins.java:105) - Version: 0.0.1 +INFO [main] (ApplicationPlugins.java:106) - Author: Griefed +``` + +addons.log: ``` -2021-08-02T20:53:28,077 DEBUG [pool-2-thread-1] (AddonsHandler.java:240) - Addon work-directory is: work\temp\serverpackcreatorexampleaddon -2021-08-02T20:53:28,077 DEBUG [pool-2-thread-1] (AddonsHandler.java:254) - ProcessBuilder command is: [C:/Program Files/Java/jdk1.8.0_291/bin/java.exe, -jar, C:/Minecraft/ServerPackCreator/addons/serverpackcreatorexampleaddon.jar, C:/Minecraft/Game/Instances/Survive Create Prosper 4 1.16.5, AmbientSounds, BackTools, BetterAdvancement, BetterFoliage, BetterPing, BetterPlacement, Blur, cherished, ClientTweaks, Controlling, customdiscordrpc, CustomMainMenu, DefaultOptions, durability, DynamicSurroundings, FullscreenWindowed, iemzoom, jeiintegration, jei-professions, JustEnoughResources, keywizard, modnametooltip, MouseTweaks, multihotbar-, Neat, OldJavaWarning, PackMenu, prciseblockplacing, ResourceLoader, SimpleDiscordRichPresence, SpawnerFix, timestamps, TipTheScales, WorldNameRandomizer, config, defaultconfigs, mods, scripts, seeds, C:/Program Files/Java/jdk1.8.0_291/bin/java.exe, 1.16.5, Forge, 36.2.2, true, true, true, true, true, C:/Minecraft/ServerPackCreator] -2021-08-02T20:53:28,255 INFO [pool-2-thread-1] (AddonsHandler.java:272) - We have recieved the following configuration: [C:/Minecraft/Game/Instances/Survive Create Prosper 4 1.16.5, AmbientSounds, BackTools, BetterAdvancement, BetterFoliage, BetterPing, BetterPlacement, Blur, cherished, ClientTweaks, Controlling, customdiscordrpc, CustomMainMenu, DefaultOptions, durability, DynamicSurroundings, FullscreenWindowed, iemzoom, jeiintegration, jei-professions, JustEnoughResources, keywizard, modnametooltip, MouseTweaks, multihotbar-, Neat, OldJavaWarning, PackMenu, prciseblockplacing, ResourceLoader, SimpleDiscordRichPresence, SpawnerFix, timestamps, TipTheScales, WorldNameRandomizer, config, defaultconfigs, mods, scripts, seeds, C:/Program Files/Java/jdk1.8.0_291/bin/java.exe, 1.16.5, Forge, 36.2.2, true, true, true, true, true, C:/Minecraft/ServerPackCreator] -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Configuration passed from ServerPackCreator, processed and now usable however we wish. -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Modpack directory: C:/Minecraft/Game/Instances/Survive Create Prosper 4 1.16.5 -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Clientside-only mods: [AmbientSounds, BackTools, BetterAdvancement, BetterFoliage, BetterPing, BetterPlacement, Blur, cherished, ClientTweaks, Controlling, customdiscordrpc, CustomMainMenu, DefaultOptions, durability, DynamicSurroundings, FullscreenWindowed, iemzoom, jeiintegration, jei-professions, JustEnoughResources, keywizard, modnametooltip, MouseTweaks, multihotbar-, Neat, OldJavaWarning, PackMenu, prciseblockplacing, ResourceLoader, SimpleDiscordRichPresence, SpawnerFix, timestamps, TipTheScales, WorldNameRandomizer] -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Directories to copy to server pack: [config, defaultconfigs, mods, scripts, seeds] -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Path to Java installation: C:/Program Files/Java/jdk1.8.0_291/bin/java.exe -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Minecraft version: 1.16.5 -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Specified modloader: Forge -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Specified modloader version: 36.2.2 -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Whether to install the modloader server: true -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Whether to copy the server-icon.png: true -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Whether to copy the server.properties: true -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Whether to create a ZIP-archive of the server pack:true -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Example addon configuration for someconfig: This is an example for working with the addon.conf-file. -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - -2021-08-02T20:53:28,256 INFO [pool-2-thread-1] (AddonsHandler.java:272) - Base path for ServerPackCreator: C:/Minecraft/ServerPackCreator -2021-08-02T20:53:28,259 INFO [pool-2-thread-1] (AddonsHandler.java:284) - All addons executed. Returning to ServerPackCreator. +2022-01-26T18:20:45,896 INFO [main] (ExamplePlugin.java:45) - Starting ExamplePlugin... +2022-01-26T18:20:45,897 INFO [main] (ExamplePlugin.java:46) - This methods should prepare the environment for anything you want to do with it. +2022-01-26T18:20:45,897 INFO [main] (ExamplePlugin.java:47) - You could download some files. Create or replace some files. Basically you can do whatever you want. +2022-01-26T18:21:55,874 INFO [pool-2-thread-1] (ServerPackHandler.java:253) - Executing PreGenExtension addons +2022-01-26T18:21:55,874 INFO [pool-2-thread-1] (ServerPackHandler.java:255) - Executing plugin ServerPackCreatorExampleAddon +2022-01-26T18:21:55,874 INFO [pool-2-thread-1] (ExamplePlugin.java:58) - This would run before a server pack generation. +2022-01-26T18:21:55,875 INFO [pool-2-thread-1] (ExamplePlugin.java:59) - Received destination: G:/GitLab/ServerPackCreator/testruns/server-packs/Deathdusk +2022-01-26T18:21:55,875 INFO [pool-2-thread-1] (ExamplePlugin.java:60) - We recieved the following configurationModel: ConfigurationModel{clientMods=[AdvancementPlaques-, AmbientSounds_, 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-, dynmus-, dynamic-music-, DynamicSurroundings-, DynamicSurroundingsHuds-, eiramoticons-, EiraMoticons_, EnchantmentDescriptions-, EquipmentCompare-, extremesoundmuffler-, extremeSoundMuffler-, Fallingleaves-, fallingleaves-, fancymenu_, findme-, flickerfix-, FpsReducer-, FullscreenWindowed-, WindowedFullscreen-, InventoryEssentials_, InventorySpam-, invtweaks-, InventoryTweaks-, ItemBorders-, itemzoom, itlt-, jeed-, jeiintegration_, JustEnoughProfessions-, JEITweaker-, justenoughbeacons-, JustEnoughCalculation-, jehc-, just-enough-harvestcraft-, JustEnoughProfessions-, JustEnoughResources-, keywizard-, konkrete_, lazydfu-, LegendaryTooltips-, LightOverlay-, light-overlay-, LLOverlayReloaded-, loadmyresources_, lootbeams-, mcbindtype-, modnametooltip_, modnametooltip-, moreoverlays-, MouseTweaks-, multihotbar-, MyServerIsCompatible-, Neat, NotifMod-, OldJavaWarning-, ornaments-, overloadedarmorbar-, PackMenu-, PickUpNotifier-, Ping-, preciseblockplacing-, presencefootsteps-, PresenceFootsteps-, ReAuth-, ResourceLoader-, shutupexperimentalsettings-, SimpleDiscordRichPresence-, smoothboot-, sounddeviceoptions-, SpawnerFix-, spoticraft-, tconplanner-, timestamps-, Tips-, TipTheScales-, Toast Control-, Toast-Control-, torohealth-, toughnessbar-, TravelersTitles-, WorldNameRandomizer-], copyDirs=[config, mods], modpackDir='C:/Minecraft/Game/Instances/Deathdusk', javaPath='C:/Program Files/Java/jdk1.8.0_291/jre/bin/java.exe', minecraftVersion='1.18.1', modLoader='Fabric', modLoaderVersion='0.12.12', javaArgs='empty', serverPackSuffix='', serverIconPath='', serverPropertiesPath='', includeServerInstallation=true, includeServerIcon=true, includeServerProperties=true, includeZipCreation=true, curseModpack=null, projectName='null', fileName='null', fileDiskName='null', projectID=0, fileID=0} +2022-01-26T18:21:55,875 INFO [pool-2-thread-1] (ExamplePlugin.java:61) - We received the following applicationProperties: {de.griefed.serverpackcreator.serverpack.autodiscoverenabled=true, de.griefed.serverpackcreator.spring.schedules.database.cleanup=0 0 24 * *, de.griefed.serverpackcreator.configuration.hastebinserver=https://haste.zneix.eu/documents, de.griefed.serverpackcreator.spring.artemis.queue.max_disk_usage=90, de.griefed.serverpackcreator.serverpack.overwrite.enabled=true, de.griefed.serverpackcreator.configuration.saveloadedconfig=false, de.griefed.serverpackcreator.gui.darkmode=true, de.griefed.serverpackcreator.configuration.directories.shouldexclude=overrides,packmenu,resourcepacks,server_pack,fancymenu, de.griefed.serverpackcreator.language=en_us, de.griefed.serverpackcreator.configuration.directories.serverpacks=server-packs, homeDir=G:/GitLab/ServerPackCreator/build/classes/java, de.griefed.serverpackcreator.curseforge.cleanup.enabled=true, de.griefed.serverpackcreator.plugins.directory=./plugins, de.griefed.serverpackcreator.versioncheck.prerelease=true, de.griefed.serverpackcreator.configuration.directories.mustinclude=mods,config,defaultconfigs,scripts,saves,seeds,libraries, de.griefed.serverpackcreator.serverpack.cleanup.enabled=true, de.griefed.serverpackcreator.spring.cursecontroller.regenerate.enabled=false, de.griefed.serverpackcreator.configuration.fallbackmodslist=AdvancementPlaques-,AmbientSounds_,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-,dynmus-,dynamic-music-,DynamicSurroundings-,DynamicSurroundingsHuds-,eiramoticons-,EiraMoticons_,EnchantmentDescriptions-,EquipmentCompare-,extremesoundmuffler-,extremeSoundMuffler-,Fallingleaves-,fallingleaves-,fancymenu_,findme-,flickerfix-,FpsReducer-,FullscreenWindowed-,WindowedFullscreen-,InventoryEssentials_,InventorySpam-,invtweaks-,InventoryTweaks-,ItemBorders-,itemzoom,itlt-,jeed-,jeiintegration_,JustEnoughProfessions-,JEITweaker-,justenoughbeacons-,JustEnoughCalculation-,jehc-,just-enough-harvestcraft-,JustEnoughProfessions-,JustEnoughResources-,keywizard-,konkrete_,lazydfu-,LegendaryTooltips-,LightOverlay-,light-overlay-,LLOverlayReloaded-,loadmyresources_,lootbeams-,mcbindtype-,modnametooltip_,modnametooltip-,moreoverlays-,MouseTweaks-,multihotbar-,MyServerIsCompatible-,Neat,NotifMod-,OldJavaWarning-,ornaments-,overloadedarmorbar-,PackMenu-,PickUpNotifier-,Ping-,preciseblockplacing-,presencefootsteps-,PresenceFootsteps-,ReAuth-,ResourceLoader-,shutupexperimentalsettings-,SimpleDiscordRichPresence-,smoothboot-,sounddeviceoptions-,SpawnerFix-,spoticraft-,tconplanner-,timestamps-,Tips-,TipTheScales-,Toast Control-,Toast-Control-,torohealth-,toughnessbar-,TravelersTitles-,WorldNameRandomizer-} +2022-01-26T18:22:06,414 INFO [pool-2-thread-1] (ServerPackHandler.java:303) - Executing PreZipExtension addons +2022-01-26T18:22:06,414 INFO [pool-2-thread-1] (ServerPackHandler.java:305) - Executing plugin ServerPackCreatorExampleAddon +2022-01-26T18:22:06,414 INFO [pool-2-thread-1] (ExamplePlugin.java:98) - This would run after a server pack was generated, but BEFORE the ZIP-archive would be generated. +2022-01-26T18:22:06,414 INFO [pool-2-thread-1] (ExamplePlugin.java:99) - Received destination: G:/GitLab/ServerPackCreator/testruns/server-packs/Deathdusk +2022-01-26T18:22:06,414 INFO [pool-2-thread-1] (ExamplePlugin.java:100) - We recieved the following configurationModel: ConfigurationModel{clientMods=[AdvancementPlaques-, AmbientSounds_, 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-, dynmus-, dynamic-music-, DynamicSurroundings-, DynamicSurroundingsHuds-, eiramoticons-, EiraMoticons_, EnchantmentDescriptions-, EquipmentCompare-, extremesoundmuffler-, extremeSoundMuffler-, Fallingleaves-, fallingleaves-, fancymenu_, findme-, flickerfix-, FpsReducer-, FullscreenWindowed-, WindowedFullscreen-, InventoryEssentials_, InventorySpam-, invtweaks-, InventoryTweaks-, ItemBorders-, itemzoom, itlt-, jeed-, jeiintegration_, JustEnoughProfessions-, JEITweaker-, justenoughbeacons-, JustEnoughCalculation-, jehc-, just-enough-harvestcraft-, JustEnoughProfessions-, JustEnoughResources-, keywizard-, konkrete_, lazydfu-, LegendaryTooltips-, LightOverlay-, light-overlay-, LLOverlayReloaded-, loadmyresources_, lootbeams-, mcbindtype-, modnametooltip_, modnametooltip-, moreoverlays-, MouseTweaks-, multihotbar-, MyServerIsCompatible-, Neat, NotifMod-, OldJavaWarning-, ornaments-, overloadedarmorbar-, PackMenu-, PickUpNotifier-, Ping-, preciseblockplacing-, presencefootsteps-, PresenceFootsteps-, ReAuth-, ResourceLoader-, shutupexperimentalsettings-, SimpleDiscordRichPresence-, smoothboot-, sounddeviceoptions-, SpawnerFix-, spoticraft-, tconplanner-, timestamps-, Tips-, TipTheScales-, Toast Control-, Toast-Control-, torohealth-, toughnessbar-, TravelersTitles-, WorldNameRandomizer-], copyDirs=[config, mods], modpackDir='C:/Minecraft/Game/Instances/Deathdusk', javaPath='C:/Program Files/Java/jdk1.8.0_291/jre/bin/java.exe', minecraftVersion='1.18.1', modLoader='Fabric', modLoaderVersion='0.12.12', javaArgs='empty', serverPackSuffix='', serverIconPath='', serverPropertiesPath='', includeServerInstallation=true, includeServerIcon=true, includeServerProperties=true, includeZipCreation=true, curseModpack=null, projectName='null', fileName='null', fileDiskName='null', projectID=0, fileID=0} +2022-01-26T18:22:06,414 INFO [pool-2-thread-1] (ExamplePlugin.java:101) - We received the following applicationProperties: {de.griefed.serverpackcreator.serverpack.autodiscoverenabled=true, de.griefed.serverpackcreator.spring.schedules.database.cleanup=0 0 24 * *, de.griefed.serverpackcreator.configuration.hastebinserver=https://haste.zneix.eu/documents, de.griefed.serverpackcreator.spring.artemis.queue.max_disk_usage=90, de.griefed.serverpackcreator.serverpack.overwrite.enabled=true, de.griefed.serverpackcreator.configuration.saveloadedconfig=false, de.griefed.serverpackcreator.gui.darkmode=true, de.griefed.serverpackcreator.configuration.directories.shouldexclude=overrides,packmenu,resourcepacks,server_pack,fancymenu, de.griefed.serverpackcreator.language=en_us, de.griefed.serverpackcreator.configuration.directories.serverpacks=server-packs, homeDir=G:/GitLab/ServerPackCreator/build/classes/java, de.griefed.serverpackcreator.curseforge.cleanup.enabled=true, de.griefed.serverpackcreator.plugins.directory=./plugins, de.griefed.serverpackcreator.versioncheck.prerelease=true, de.griefed.serverpackcreator.configuration.directories.mustinclude=mods,config,defaultconfigs,scripts,saves,seeds,libraries, de.griefed.serverpackcreator.serverpack.cleanup.enabled=true, de.griefed.serverpackcreator.spring.cursecontroller.regenerate.enabled=false, de.griefed.serverpackcreator.configuration.fallbackmodslist=AdvancementPlaques-,AmbientSounds_,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-,dynmus-,dynamic-music-,DynamicSurroundings-,DynamicSurroundingsHuds-,eiramoticons-,EiraMoticons_,EnchantmentDescriptions-,EquipmentCompare-,extremesoundmuffler-,extremeSoundMuffler-,Fallingleaves-,fallingleaves-,fancymenu_,findme-,flickerfix-,FpsReducer-,FullscreenWindowed-,WindowedFullscreen-,InventoryEssentials_,InventorySpam-,invtweaks-,InventoryTweaks-,ItemBorders-,itemzoom,itlt-,jeed-,jeiintegration_,JustEnoughProfessions-,JEITweaker-,justenoughbeacons-,JustEnoughCalculation-,jehc-,just-enough-harvestcraft-,JustEnoughProfessions-,JustEnoughResources-,keywizard-,konkrete_,lazydfu-,LegendaryTooltips-,LightOverlay-,light-overlay-,LLOverlayReloaded-,loadmyresources_,lootbeams-,mcbindtype-,modnametooltip_,modnametooltip-,moreoverlays-,MouseTweaks-,multihotbar-,MyServerIsCompatible-,Neat,NotifMod-,OldJavaWarning-,ornaments-,overloadedarmorbar-,PackMenu-,PickUpNotifier-,Ping-,preciseblockplacing-,presencefootsteps-,PresenceFootsteps-,ReAuth-,ResourceLoader-,shutupexperimentalsettings-,SimpleDiscordRichPresence-,smoothboot-,sounddeviceoptions-,SpawnerFix-,spoticraft-,tconplanner-,timestamps-,Tips-,TipTheScales-,Toast Control-,Toast-Control-,torohealth-,toughnessbar-,TravelersTitles-,WorldNameRandomizer-} +2022-01-26T18:22:45,053 INFO [pool-2-thread-1] (ServerPackHandler.java:333) - Executing PostGenExtension addons +2022-01-26T18:22:45,053 INFO [pool-2-thread-1] (ServerPackHandler.java:335) - Executing plugin ServerPackCreatorExampleAddon +2022-01-26T18:22:45,053 INFO [pool-2-thread-1] (ExamplePlugin.java:143) - This would run after the server pack ZIP-archive was created. +2022-01-26T18:22:45,053 INFO [pool-2-thread-1] (ExamplePlugin.java:144) - Received destination: G:/GitLab/ServerPackCreator/testruns/server-packs/Deathdusk +2022-01-26T18:22:45,053 INFO [pool-2-thread-1] (ExamplePlugin.java:145) - We recieved the following configurationModel: ConfigurationModel{clientMods=[AdvancementPlaques-, AmbientSounds_, 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-, dynmus-, dynamic-music-, DynamicSurroundings-, DynamicSurroundingsHuds-, eiramoticons-, EiraMoticons_, EnchantmentDescriptions-, EquipmentCompare-, extremesoundmuffler-, extremeSoundMuffler-, Fallingleaves-, fallingleaves-, fancymenu_, findme-, flickerfix-, FpsReducer-, FullscreenWindowed-, WindowedFullscreen-, InventoryEssentials_, InventorySpam-, invtweaks-, InventoryTweaks-, ItemBorders-, itemzoom, itlt-, jeed-, jeiintegration_, JustEnoughProfessions-, JEITweaker-, justenoughbeacons-, JustEnoughCalculation-, jehc-, just-enough-harvestcraft-, JustEnoughProfessions-, JustEnoughResources-, keywizard-, konkrete_, lazydfu-, LegendaryTooltips-, LightOverlay-, light-overlay-, LLOverlayReloaded-, loadmyresources_, lootbeams-, mcbindtype-, modnametooltip_, modnametooltip-, moreoverlays-, MouseTweaks-, multihotbar-, MyServerIsCompatible-, Neat, NotifMod-, OldJavaWarning-, ornaments-, overloadedarmorbar-, PackMenu-, PickUpNotifier-, Ping-, preciseblockplacing-, presencefootsteps-, PresenceFootsteps-, ReAuth-, ResourceLoader-, shutupexperimentalsettings-, SimpleDiscordRichPresence-, smoothboot-, sounddeviceoptions-, SpawnerFix-, spoticraft-, tconplanner-, timestamps-, Tips-, TipTheScales-, Toast Control-, Toast-Control-, torohealth-, toughnessbar-, TravelersTitles-, WorldNameRandomizer-], copyDirs=[config, mods], modpackDir='C:/Minecraft/Game/Instances/Deathdusk', javaPath='C:/Program Files/Java/jdk1.8.0_291/jre/bin/java.exe', minecraftVersion='1.18.1', modLoader='Fabric', modLoaderVersion='0.12.12', javaArgs='empty', serverPackSuffix='', serverIconPath='', serverPropertiesPath='', includeServerInstallation=true, includeServerIcon=true, includeServerProperties=true, includeZipCreation=true, curseModpack=null, projectName='null', fileName='null', fileDiskName='null', projectID=0, fileID=0} +2022-01-26T18:22:45,053 INFO [pool-2-thread-1] (ExamplePlugin.java:146) - We received the following applicationProperties: {de.griefed.serverpackcreator.serverpack.autodiscoverenabled=true, de.griefed.serverpackcreator.spring.schedules.database.cleanup=0 0 24 * *, de.griefed.serverpackcreator.configuration.hastebinserver=https://haste.zneix.eu/documents, de.griefed.serverpackcreator.spring.artemis.queue.max_disk_usage=90, de.griefed.serverpackcreator.serverpack.overwrite.enabled=true, de.griefed.serverpackcreator.configuration.saveloadedconfig=false, de.griefed.serverpackcreator.gui.darkmode=true, de.griefed.serverpackcreator.configuration.directories.shouldexclude=overrides,packmenu,resourcepacks,server_pack,fancymenu, de.griefed.serverpackcreator.language=en_us, de.griefed.serverpackcreator.configuration.directories.serverpacks=server-packs, homeDir=G:/GitLab/ServerPackCreator/build/classes/java, de.griefed.serverpackcreator.curseforge.cleanup.enabled=true, de.griefed.serverpackcreator.plugins.directory=./plugins, de.griefed.serverpackcreator.versioncheck.prerelease=true, de.griefed.serverpackcreator.configuration.directories.mustinclude=mods,config,defaultconfigs,scripts,saves,seeds,libraries, de.griefed.serverpackcreator.serverpack.cleanup.enabled=true, de.griefed.serverpackcreator.spring.cursecontroller.regenerate.enabled=false, de.griefed.serverpackcreator.configuration.fallbackmodslist=AdvancementPlaques-,AmbientSounds_,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-,dynmus-,dynamic-music-,DynamicSurroundings-,DynamicSurroundingsHuds-,eiramoticons-,EiraMoticons_,EnchantmentDescriptions-,EquipmentCompare-,extremesoundmuffler-,extremeSoundMuffler-,Fallingleaves-,fallingleaves-,fancymenu_,findme-,flickerfix-,FpsReducer-,FullscreenWindowed-,WindowedFullscreen-,InventoryEssentials_,InventorySpam-,invtweaks-,InventoryTweaks-,ItemBorders-,itemzoom,itlt-,jeed-,jeiintegration_,JustEnoughProfessions-,JEITweaker-,justenoughbeacons-,JustEnoughCalculation-,jehc-,just-enough-harvestcraft-,JustEnoughProfessions-,JustEnoughResources-,keywizard-,konkrete_,lazydfu-,LegendaryTooltips-,LightOverlay-,light-overlay-,LLOverlayReloaded-,loadmyresources_,lootbeams-,mcbindtype-,modnametooltip_,modnametooltip-,moreoverlays-,MouseTweaks-,multihotbar-,MyServerIsCompatible-,Neat,NotifMod-,OldJavaWarning-,ornaments-,overloadedarmorbar-,PackMenu-,PickUpNotifier-,Ping-,preciseblockplacing-,presencefootsteps-,PresenceFootsteps-,ReAuth-,ResourceLoader-,shutupexperimentalsettings-,SimpleDiscordRichPresence-,smoothboot-,sounddeviceoptions-,SpawnerFix-,spoticraft-,tconplanner-,timestamps-,Tips-,TipTheScales-,Toast Control-,Toast-Control-,torohealth-,toughnessbar-,TravelersTitles-,WorldNameRandomizer-} ``` +Additionally, the following files/directories would be created in the server pack-directory: + +- `./ExampleStartExtension` +- `./ExampleArchiveExtension` +- `serverpackcreator.conf` as it was used to generate the server pack +- `./some/folder/with/a/name` + # 1. The reason for allowing ServerPackCreator to run addons: -There are things which people want to do with their server packs which could most certainly be automated. Some of those -things so special, or maybe out of place, that they would not warrant a separate feature for ServerPackCreator itself. +Some people need additional functionality for their server packs, or have some additional wishes for them. Some of those +things may not fit into the core functionality of ServerPackCreator itself. It may also be that it is such a niche feature, that I either don't have the time to code it in, or simply don't want to. Maybe it doesn't fit into the overall design of ServerPackCreator, too. Who knows, it could be any of those reasons or another. @@ -47,62 +85,46 @@ Maybe it doesn't fit into the overall design of ServerPackCreator, too. Who know This allows people to write their own addons to expand the functionality of ServerPackCreator with their own features as they see fit or want. -One example would be: Automatic setup of a server pack for [BlueMap](https://www.curseforge.com/minecraft/mc-mods/bluemap). -An addon could check all mods in the specified modpacks mods-directory for textures, and if any are found, add them to -BlueMap's resourcepack folder `config/bluemap/resourcepacks`, install BlueMap for the specified Minecraft and Forge/Fabric -version and voilà ! ServerPackCreator has BlueMap Support Automation functionality, thanks to an addon, without having to wait -for me to write it and add it to ServerPackCreators core-functionality for you! +Some examples for addons can be found [in this discussion thread](https://github.com/Griefed/ServerPackCreator/discussions/201). -# 2. How +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. + +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. -## 2.1 Values to work with +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à ! -ServerPackCreator passes the configuration used to create a server pack to all addons configured as `serverpack`-addons. -That list consists of: -* modpackDir -* clientMods -* copyDirs -* javaPath -* minecraftVersion -* modLoader -* modLoaderVersion -* includeServerInstallation -* includeServerIcon -* includeServerProperties -* includeZipCreation +# 2. How -That list is parsed in `ConfigurationHandler` and written into an instance of `ConfigurationModel`, allowing you to make use -of the whole configuration with which the server pack, which was generated before the addon gets executed, got made. +During the start of ServerPackCreator, all plugins are loaded and started. If you have anything you need to run then and there, +use `public void start() {...}` and do your thing. -## 2.2 Where to get values from +## 2.1 Extensions -Working with this example, you can simply call any `get`-method in the `ConfigurationModel`-class and use it to do your -operations. +One plugin can have multiple extensions. -## 2.3 Working directory +ServerPackCreator passes the `ConfigurationModel` and `ApplicationProperties`, used to create a server pack, to all `PreGenExtension`, `PreZipExtension` and `PostGenExtension` extensions. -All addons are run in the <code>work/temp/addon_name</code>-directory. Be aware of that when creating your addons! This also means -that you should be wary of trying to cleanup the temp-directory yourself, as it could potentially interfere with any other -addon running after yours! -ServerPackCreator also passes the path to itself to any of its addons it executes, making it easier for you to work with -any and all files regarding it and the server packs. +If you have a plugin with multiple extensions of the same type, you can set the priority in which they are executed by specifiying and ordinal for your extension: `@Extension(ordinal = 1)` +The higher the ordinal, the lower the priority. See [pf4j documentation](https://pf4j.org/doc/extensions) on extensions. -## 2.4 Logs +## 2.2 Logs -Any and all message you would normally let log4j write to a log-file need to be printed using `System.out.println("Some message.")` -or similar methods. These are caught by ServerPacKCreator and added to the addons.log. +If you want to print log messages, then use the `LOG_ADDONS` logger as shown in this example. This will result in ServerPackCreator writing any and all log entries from this logger to the `addons.log`-file. # 3. Building 1. Fork and clone this repository 2. Make your changes and additions. 3. Build with `gradlew about build --info`. -4. Copy the JAR-file from `build/libs` to the addons-directory created by ServerPackCreator. +4. Copy the JAR-file from `build/libs` to the plugins-directory created by ServerPackCreator. 5. Run ServerPackCreator! -**NOTE: Please be aware that you might need to change the tests I've provided as an example for this addon. If you change the -base behaviour of this example, the chance that you will have to make changes to tests, too, is quite high.** - ## 4. Contributing If you have written an addon, let me know by creating an issue in this repository. Provide a short description of what your @@ -114,6 +136,6 @@ along with a small description, if you provided one. Example: -| Addon | Creator | Description | -| :---- | :------ | :---------- | +| Addon | Creator | Description | +|:-------------------------------------------------------------------------|:--------|:-------------------------------------------------------------------| | [ExampleAddon](https://github.com/Griefed/ServerPackCreatorExampleAddon) | Griefed | An example addon providing a starting point for addon development. | \ No newline at end of file diff --git a/build.gradle b/build.gradle index 9ad842da43d4a296c04ca724d7aef6d7b2cfb5a0..5694c8fb4fe0ef3a55dfb0954198d3dd77ce0d35 100644 --- a/build.gradle +++ b/build.gradle @@ -3,11 +3,9 @@ import java.text.SimpleDateFormat plugins { id 'java' id 'idea' - - id 'maven-publish' } -group 'de.griefed' +group 'de.griefed.serverpackcreatorexampleaddon' //noinspection GroovyUnusedAssignment sourceCompatibility = targetCompatibility = '1.8' @@ -36,6 +34,8 @@ sourceSets { repositories { mavenCentral() + maven { url "https://jitpack.io" } + maven { url 'https://repo.spring.io/release' } } configurations { @@ -44,10 +44,21 @@ configurations { } dependencies { - embed 'com.typesafe:config:1.4.1' + implementation 'org.pf4j:pf4j:3.6.0' + annotationProcessor 'org.pf4j:pf4j:3.6.0' + + embed 'commons-io:commons-io:2.11.0' + embed 'org.apache.commons:commons-lang3:3.12.0' + + implementation 'org.apache.logging.log4j:log4j-api:2.17.1' + implementation('de.griefed.serverpackcreator:serverpackcreator:b3b4b85') { + version { + branch = 'webservice' + } + } // Testing - testImplementation 'org.mockito:mockito-core:4.2.0' + testImplementation 'org.mockito:mockito-core:4.3.1' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' } @@ -94,51 +105,19 @@ jar { //noinspection GroovyAssignabilityCheck manifest { attributes( - "Main-Class" : "de.griefed.serverpackcreatoraddonexample.Main", - "Class-Path" : configurations.embed.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }, - "Description" : "Example addon for ServerPackCreator", - "Built-By" : System.getProperty("user.name"), - "Build-Timestamp": new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()), - "Created-By" : "Gradle ${gradle.gradleVersion}", - "Build-Jdk" : "${System.getProperty('java.version')} (${System.getProperty('java.vendor')} ${System.getProperty('java.vm.version')})", - "Build-OS" : "${System.getProperty('os.name')} ${System.getProperty('os.arch')} ${System.getProperty('os.version')}", + "Main-Class" : "de.griefed.serverpackcreatoraddonexample.ExamplePlugin", + "Class-Path" : configurations.embed.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }, + "Description" : "Example plugin for ServerPackCreator", + "Built-By" : System.getProperty("user.name"), + "Build-Timestamp" : new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()), + "Created-By" : "Gradle ${gradle.gradleVersion}", + "Build-Jdk" : "${System.getProperty('java.version')} (${System.getProperty('java.vendor')} ${System.getProperty('java.vm.version')})", + "Build-OS" : "${System.getProperty('os.name')} ${System.getProperty('os.arch')} ${System.getProperty('os.version')}", + "Plugin-Class" : "de.griefed.serverpackcreatoraddonexample.ExamplePlugin", + "Plugin-Id" : "example-plugin", + "Plugin-Provider" : "Griefed", + "Plugin-Version" : "0.0.1", + "Plugin-Description" : "Example plugin for ServerPackCreator", ) } - exclude ( - 'META-INF/org', - 'META-INF/org/**', - 'META-INF/versions', - 'META-INF/versions/**', - 'META-INF/DEPENDENCIES', - 'META-INF/LICENSE', - 'META-INF/NOTICE', - 'META-INF/CHANGES', - 'META-INF/LICENSE.txt', - 'META-INF/NOTICE.txt', - 'META-INF/README.md', - 'Log4j-**' - ) -} - -// Publish the package with passed version to GHPR. Use ./gradlew -Pversion=${NEW_VERSION} publish, for example. -publishing { - repositories { - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/Griefed/serverpackcreatorexampleaddon") - credentials { - username = System.getenv("GITHUB_ACTOR") - password = System.getenv("GITHUB_TOKEN") - } - } - } - publications { - //noinspection GroovyAssignabilityCheck - gpr(MavenPublication) { - //noinspection GroovyAssignabilityCheck - artifactId='serverpackcreatorexampleaddon' - //noinspection GroovyAssignabilityCheck - from (components.java) - } - } } \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 27364262e700d4ed8613953a6fa219af63eee8f4..62459811ada69af421b5f7cc8cff56f34472671c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,6 @@ -rootProject.name = 'serverpackcreatorexampleaddon' \ No newline at end of file +sourceControl { + gitRepository("https://github.com/Griefed/ServerPackCreator.git") { + producesModule("de.griefed.serverpackcreator:serverpackcreator") + } +} +rootProject.name = 'serverpackcreatorexampleaddon' diff --git a/src/main/java/de/griefed/serverpackcreatoraddonexample/ExamplePlugin.java b/src/main/java/de/griefed/serverpackcreatoraddonexample/ExamplePlugin.java new file mode 100644 index 0000000000000000000000000000000000000000..bb61292f075681600c343efc16aaf876a8291982 --- /dev/null +++ b/src/main/java/de/griefed/serverpackcreatoraddonexample/ExamplePlugin.java @@ -0,0 +1,259 @@ +package de.griefed.serverpackcreatoraddonexample; + +import de.griefed.serverpackcreator.ApplicationProperties; +import de.griefed.serverpackcreator.ConfigurationModel; +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 de.griefed.serverpackcreator.utilities.ConfigUtilities; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.pf4j.Extension; +import org.pf4j.Plugin; +import org.pf4j.PluginWrapper; + +import javax.swing.*; +import java.awt.*; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class ExamplePlugin extends Plugin { + + private static final Logger LOG_ADDONS = LogManager.getLogger("AddonsLogger"); + + /* + You should provide and read all these from the manifest. + */ + public static final String NAME = "ServerPackCreatorExampleAddon"; + public static final String DESCRIPTION = "This is an example addon for ServerPackCreator showcasing all, currently 4, aspects of" + + "ServerPackCreators addon functionality. In this example you see code which gets executed before a server pack is generated," + + "code that gets executed after a server pack was generated but before the ZIP-archive is created, code that gets executed" + + "after this ZIP-archive was created, as well as code adding a new tabbed pane to the GUI."; + public static final String AUTHOR = "Griefed"; + public static final String VERSION = "0.0.1"; + + public ExamplePlugin(PluginWrapper wrapper) { + super(wrapper); + } + + @Override + public void start() { + LOG_ADDONS.info("Starting ExamplePlugin..."); + LOG_ADDONS.info("This methods should prepare the environment for anything you want to do with it."); + LOG_ADDONS.info("You could download some files. Create or replace some files. Basically you can do whatever you want."); + /* + Write all your preparation code here.. + */ + } + + @Extension(ordinal = 1) + public static class ExampleStartExtension implements PreGenExtension { + + @Override + public void run(ApplicationProperties applicationProperties, ConfigurationModel configurationModel, String destination) throws Exception { + LOG_ADDONS.info("This would run before a server pack generation."); + LOG_ADDONS.info("Received destination: " + destination); + LOG_ADDONS.info("We recieved the following configurationModel: " + configurationModel.toString()); + LOG_ADDONS.info("We received the following applicationProperties: " + applicationProperties.toString()); + StringUtils.upperCase("some text in lower case"); + //Create example file in server pack + try { + Files.createFile(Paths.get(String.format("%s/%s",destination, this.getClass().getSimpleName()))); + } catch (Exception ignored) {} + /* + Write all your pre-gen stuff here... + */ + } + + @Override + public String getName() { + return NAME; + } + + @Override + public String getDescription() { + return DESCRIPTION; + } + + @Override + public String getAuthor() { + return AUTHOR; + } + + @Override + public String getVersion() { + return VERSION; + } + } + + @Extension(ordinal = 1) + public static class ExampleCreatedExtension implements PreZipExtension { + + @Override + public void run(ApplicationProperties applicationProperties, ConfigurationModel configurationModel, String destination) throws Exception { + LOG_ADDONS.info("This would run after a server pack was generated, but BEFORE the ZIP-archive would be generated."); + LOG_ADDONS.info("Received destination: " + destination); + LOG_ADDONS.info("We recieved the following configurationModel: " + configurationModel.toString()); + LOG_ADDONS.info("We received the following applicationProperties: " + applicationProperties.toString()); + StringUtils.upperCase("some text in lower case"); + //Create example file in server pack + try { + FileUtils.createParentDirectories(new File(destination + "/some/folder/with/a/name")); + } catch (Exception ex) { + LOG_ADDONS.info("Error occurred creating parent directories.", ex); + } + + new ConfigUtilities(null,null,null,applicationProperties, null) + .writeConfigToFile(configurationModel, new File(destination + "/serverpackcreator.conf")); + /* + Write all your post-gen-pre-zip stuff here... + */ + } + + @Override + public String getName() { + return NAME; + } + + @Override + public String getDescription() { + return DESCRIPTION; + } + + @Override + public String getAuthor() { + return AUTHOR; + } + + @Override + public String getVersion() { + return VERSION; + } + } + + @Extension(ordinal = 1) + public static class ExampleArchiveExtension implements PostGenExtension { + + @Override + public void run(ApplicationProperties applicationProperties, ConfigurationModel configurationModel, String destination) throws Exception { + LOG_ADDONS.info("This would run after the server pack ZIP-archive was created."); + LOG_ADDONS.info("Received destination: " + destination); + LOG_ADDONS.info("We recieved the following configurationModel: " + configurationModel.toString()); + LOG_ADDONS.info("We received the following applicationProperties: " + applicationProperties.toString()); + //Create example file in server pack + try { + Files.createFile(Paths.get(String.format("%s/%s",destination, this.getClass().getSimpleName()))); + } catch (Exception ignored) {} + + /* + Write all your post-archive stuff here... + */ + } + + @Override + public String getName() { + return NAME; + } + + @Override + public String getDescription() { + return DESCRIPTION; + } + + @Override + public String getAuthor() { + return AUTHOR; + } + + @Override + public String getVersion() { + return VERSION; + } + } + + @Extension(ordinal = 1) + public static class ExampleAddTabExtension extends JComponent implements TabExtension { + + @Override + public JComponent getTab() { + JComponent jComponent = new JPanel(false); + jComponent.setLayout(new GridBagLayout()); + + GridBagConstraints gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.fill = GridBagConstraints.NONE; + gridBagConstraints.anchor = GridBagConstraints.CENTER; + gridBagConstraints.gridwidth = 1; + gridBagConstraints.gridheight = 1; + gridBagConstraints.weightx = 1; + gridBagConstraints.weighty = 1; + + JLabel jLabel = new JLabel("This is a label"); + jLabel.setToolTipText("Some label tooltip"); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 1; + jComponent.add(jLabel, gridBagConstraints); + + JButton jButton = new JButton("Some button"); + jButton.setToolTipText("This could do anything"); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 2; + jComponent.add(jButton, gridBagConstraints); + + return jComponent; + } + + @Override + public Icon getTabIcon() { + /* + * other default icons can be: + * OptionPane.errorIcon + * OptionPane.warningIcon + * OptionPane.questionIcon + */ + return UIManager.getIcon("OptionPane.informationIcon"); + } + + @Override + public String getTabTitle() { + return "Some title text"; + } + + @Override + public String getTabTooltip() { + return "Some tooltip text"; + } + + @Override + public void run(ApplicationProperties applicationProperties, ConfigurationModel configurationModel, String destination) throws Exception { + /* + So far, the run(...) method for AddTab extensions never gets called. + There is no point in writing code here with the intention of + ServerPackCreator executing it. + */ + } + + @Override + public String getName() { + return NAME; + } + + @Override + public String getDescription() { + return DESCRIPTION; + } + + @Override + public String getAuthor() { + return AUTHOR; + } + + @Override + public String getVersion() { + return VERSION; + } + } +} diff --git a/src/main/java/de/griefed/serverpackcreatoraddonexample/Main.java b/src/main/java/de/griefed/serverpackcreatoraddonexample/Main.java deleted file mode 100644 index 4764ff78140dd86033792eb4818eb14429e4b489..0000000000000000000000000000000000000000 --- a/src/main/java/de/griefed/serverpackcreatoraddonexample/Main.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (C) 2021 Griefed - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.griefed.serverpackcreatoraddonexample; - -import de.griefed.serverpackcreatoraddonexample.configuration.AddonConfiguration; -import de.griefed.serverpackcreatoraddonexample.configuration.ConfigurationHandler; -import de.griefed.serverpackcreatoraddonexample.configuration.ConfigurationModel; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Arrays; - -/** - * Main class of this example. We create our instances of {@link ConfigurationHandler}, {@link ConfigurationModel} and - * {@link AddonConfiguration} so we can do with them whatever we want.<br> - * The creation of an instance of {@link ConfigurationHandler} writes the values passed from ServerPackCreator into an - * instance of {@link ConfigurationModel} so we can work with said configuration however we want to.<br> - * The creation of an instance of {@link AddonConfiguration} reads the example config from the <code>addon.conf</code>-file - * to demonstrate how to work with addon-specific configurations, independant from the configuration passed by ServerPackCreator. - * @author Griefed - */ -public class Main { - - /** - * Main method which instantiates {@link ConfigurationModel} and {@link ConfigurationHandler}.<br> - * Passes the passed configuration from ServerPackCreator to {@link ConfigurationHandler#ConfigurationHandler(String[], ConfigurationModel)} - * which sets {@link ConfigurationModel} to the respective values. - * @author Griefed - * @param args Array of arguments passed from ServerPackCreator containing the configuration with which a server pack - * was generated. - */ - public static void main(String[] args) { - - // Create an instance of ConfigurationModel for later use. - ConfigurationModel configurationModel = new ConfigurationModel(); - - /* - * Creates an instance of ConfigurationHandler, passes the args received from ServerPackCreator and the newly created - * instance of ConfigurationModel. ConfigurationHandler writes the contents of args to our ConfigurationModel, so - * we can then start working with it. - */ - ConfigurationHandler configurationHandler = new ConfigurationHandler(args, configurationModel); - - /* - * Create an instance of AddonConfiguration. This parses the addon.conf-file in the JAR-file. This allows us to - * access all configurations inside the configuration-file by either calling addonConfiguration.getString("config-key") - * or by writing dedicated methods, such as getAddonConfiguration(), which returns the String - * "This is an example for working with the addon.conf-file." from the key "someconfig" in the config-file. - */ - AddonConfiguration addonConfiguration = new AddonConfiguration(); - - try { - //Create an example in the work/temp/<addon_name> directory - Files.createFile(Paths.get("This_is_an_example_file")); - } catch (IOException ex) { - ex.printStackTrace(); - } - - // Print the entire configuration, after parsing, to the console to see that everything works as intended. - System.out.println("We have recieved the following configuration: " + Arrays.toString(args)); - System.out.println(""); - System.out.println("Configuration passed from ServerPackCreator, processed and now usable however we wish."); - System.out.println(""); - System.out.println("Modpack directory: " + configurationModel.getModpackDir()); - System.out.println("Clientside-only mods: " + configurationModel.getClientMods()); - System.out.println("Directories to copy to server pack: " + configurationModel.getCopyDirs()); - System.out.println("Path to Java installation: " + configurationModel.getJavaPath()); - System.out.println("Minecraft version: " + configurationModel.getMinecraftVersion()); - System.out.println("Specified modloader: " + configurationModel.getModLoader()); - System.out.println("Specified modloader version: " + configurationModel.getModLoaderVersion()); - System.out.println("Whether to install the modloader server: " + configurationModel.getIncludeServerInstallation()); - System.out.println("Whether to copy the server-icon.png: " + configurationModel.getIncludeServerIcon()); - System.out.println("Whether to copy the server.properties: " + configurationModel.getIncludeServerProperties()); - System.out.println("Whether to create a ZIP-archive of the server pack:" + configurationModel.getIncludeZipCreation()); - System.out.println(""); - // Print the example config "someconfig" from our addon.conf file to see that everything works as intended. - System.out.println("Example addon configuration for someconfig: " + addonConfiguration.exampleConfig()); - System.out.println(""); - // Print the location of ServerPackCreator, so we know how to access server packs and the like. - System.out.println("Base path for ServerPackCreator: " + args[12]); - } - -} diff --git a/src/main/java/de/griefed/serverpackcreatoraddonexample/configuration/AddonConfiguration.java b/src/main/java/de/griefed/serverpackcreatoraddonexample/configuration/AddonConfiguration.java deleted file mode 100644 index 86fedcf1f8d830cb95e11e65f74a0beedddb4bec..0000000000000000000000000000000000000000 --- a/src/main/java/de/griefed/serverpackcreatoraddonexample/configuration/AddonConfiguration.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (C) 2021 Griefed - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.griefed.serverpackcreatoraddonexample.configuration; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import de.griefed.serverpackcreatoraddonexample.Main; - -import java.net.MalformedURLException; -import java.net.URL; - -/** - * Example class for reading the addon.conf-file and getting values from it. - * @author Griefed - */ -public class AddonConfiguration { - - private final Config ADDONCONFIGURATION; - - /** - * Constructor for the AddonConfiguration.class which automatically parses the addon.conf-file in the JAR-file. - * @author Griefed - */ - public AddonConfiguration() { - - URL urlToConfig = null; - - String addonLocation = null; - - try { - addonLocation = Main.class.getProtectionDomain().getCodeSource().getLocation().getFile(); - urlToConfig = new URL(String.format("jar:file:%s!/addon.conf", addonLocation)); - } catch (MalformedURLException ex) { - ex.printStackTrace(); - } - - assert urlToConfig != null; - this.ADDONCONFIGURATION = ConfigFactory.parseURL(urlToConfig); - - } - - /** - * Getter for the addon configuration. - * @author Griefed - * @return Config. Returns the {@link Config} object which was initiated in the constructor of this class. - */ - public Config getAddonConfiguration() { - return ADDONCONFIGURATION; - } - - /** - * Uses {@link #getAddonConfiguration()} to retrieve the string from a config parameter in the addon.conf-file. - * @author Griefed - * @return String. Returns the value of <code>serverpackcreator.addon.someconfig</code> giving an example on how to - * work with the addon.conf-file. - */ - public String exampleConfig() { - return getAddonConfiguration().getString("someconfig"); - } - -} diff --git a/src/main/java/de/griefed/serverpackcreatoraddonexample/configuration/ConfigurationHandler.java b/src/main/java/de/griefed/serverpackcreatoraddonexample/configuration/ConfigurationHandler.java deleted file mode 100644 index 3fcbd4edd22e0217427759cd0ebe78aabed83da4..0000000000000000000000000000000000000000 --- a/src/main/java/de/griefed/serverpackcreatoraddonexample/configuration/ConfigurationHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (C) 2021 Griefed - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.griefed.serverpackcreatoraddonexample.configuration; - -import java.util.Arrays; - -/** - * Handler for the configuration which got passed to us from ServerPackCreator. - * @author Griefed - */ -public class ConfigurationHandler { - - private ConfigurationModel CONFIGURATIONMODEL; - - /** - * Constructor for our class. Parses the configuration passed by ServerPackCreator and writes it into a new instance - * of {@link ConfigurationModel}. - * @author Griefed - * @param args Configuration list passed by ServerPackCreator. - * @param injectedConfigurationModel An instance of {@link ConfigurationModel}. - */ - public ConfigurationHandler(String[] args, ConfigurationModel injectedConfigurationModel) { - - if (injectedConfigurationModel == null) { - this.CONFIGURATIONMODEL = new ConfigurationModel(); - } else { - this.CONFIGURATIONMODEL = injectedConfigurationModel; - } - - CONFIGURATIONMODEL.setModpackDir(args[0]); - CONFIGURATIONMODEL.setClientMods(Arrays.asList(args[1].split(", "))); - CONFIGURATIONMODEL.setCopyDirs(Arrays.asList(args[2].split(", "))); - CONFIGURATIONMODEL.setJavaPath(args[3]); - CONFIGURATIONMODEL.setMinecraftVersion(args[4]); - CONFIGURATIONMODEL.setModLoader(args[5]); - CONFIGURATIONMODEL.setModLoaderVersion(args[6]); - CONFIGURATIONMODEL.setIncludeServerInstallation(Boolean.valueOf(args[7])); - CONFIGURATIONMODEL.setIncludeServerIcon(Boolean.valueOf(args[8])); - CONFIGURATIONMODEL.setIncludeServerProperties(Boolean.valueOf(args[9])); - CONFIGURATIONMODEL.setIncludeZipCreation(Boolean.valueOf(args[10])); - } -} diff --git a/src/main/java/de/griefed/serverpackcreatoraddonexample/configuration/ConfigurationModel.java b/src/main/java/de/griefed/serverpackcreatoraddonexample/configuration/ConfigurationModel.java deleted file mode 100644 index 7b15c994483d3c26f754a3b887d1aa9b6243570e..0000000000000000000000000000000000000000 --- a/src/main/java/de/griefed/serverpackcreatoraddonexample/configuration/ConfigurationModel.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (C) 2021 Griefed - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.griefed.serverpackcreatoraddonexample.configuration; - -import java.util.List; - -/** - * The model for the configuration which is passed to us by ServerPackCreator. It is filled by {@link ConfigurationHandler} - * during the beginning of {@link de.griefed.serverpackcreatoraddonexample.Main} and from then on available for use. - * @author Griefed - */ -public class ConfigurationModel { - - private List<String> clientMods; - private List<String> copyDirs; - - private String modpackDir; - private String javaPath; - private String minecraftVersion; - private String modLoader; - private String modLoaderVersion; - - private Boolean includeServerInstallation; - private Boolean includeServerIcon; - private Boolean includeServerProperties; - private Boolean includeZipCreation; - - /** - * Getter for the list of clientside-only mods. - * @author Griefed - * @return String List. Returns the list of clientside-only mods. - */ - public List<String> getClientMods() { - return clientMods; - } - - /** - * Setter for the list of clientside-only mods. - * @author Griefed - * @param clientMods String List. The list of clientside-only mods to store. - */ - public void setClientMods(List<String> clientMods) { - this.clientMods = clientMods; - } - - /** - * Getter for the list of directories to copy to the server pack. - * @author Griefed - * @return String List. Returns the list of directories to copy to server pack. - */ - public List<String> getCopyDirs() { - return copyDirs; - } - - /** - * Setter for the direcories to copy to the server pack. - * @author Griefed - * @param copyDirs String List. The list of directories to copy to the server pack to store. - */ - public void setCopyDirs(List<String> copyDirs) { - this.copyDirs = copyDirs; - } - - /** - * Getter for the modpack directory. - * @author Griefed - * @return String. The directory where the modpack resides. - */ - public String getModpackDir() { - return modpackDir; - } - - /** - * Setter for the modpack directory. - * @author Griefed - * @param modpackDir String. The path of the modpack directory to store. - */ - public void setModpackDir(String modpackDir) { - this.modpackDir = modpackDir; - } - - /** - * Getter for the path to the Java installation. - * @author Griefed - * @return String. The path to the Java installation. - */ - public String getJavaPath() { - return javaPath; - } - - /** - * Setter for the path to the Java installation. - * @author Griefed - * @param javaPath String. The path to the Java installation to store. - */ - public void setJavaPath(String javaPath) { - this.javaPath = javaPath; - } - - /** - * Getter for the Minecraft version the modpack uses. - * @author Griefed - * @return String. The Minecraft version to store. - */ - public String getMinecraftVersion() { - return minecraftVersion; - } - - /** - * Setter for the Minecraft version the modpack uses. - * @author Griefed - * @param minecraftVersion String. The Minecraft version to store. - */ - public void setMinecraftVersion(String minecraftVersion) { - this.minecraftVersion = minecraftVersion; - } - - /** - * Getter for the modloader the modpack uses. - * @author Griefed - * @return String. The modloader the modpack uses. - */ - public String getModLoader() { - return modLoader; - } - - /** - * Setter for the modloader the modpack uses. - * @author Griefed - * @param modLoader String. The modloader the modpack uses to store. - */ - public void setModLoader(String modLoader) { - this.modLoader = modLoader; - } - - /** - * Getter for the modloader version the modpack uses. - * @author Griefed - * @return String. The modloader version the modpack uses. - */ - public String getModLoaderVersion() { - return modLoaderVersion; - } - - /** - * Setter for the modloader version the modpack uses. - * @author Griefed - * @param modLoaderVersion String. The version of the modloader the modpack uses. - */ - public void setModLoaderVersion(String modLoaderVersion) { - this.modLoaderVersion = modLoaderVersion; - } - - /** - * Getter for whether the modloader server should be installed. - * @author Griefed - * @return Boolean. Whether the modloader server should be installed in the server pack. - */ - public Boolean getIncludeServerInstallation() { - return includeServerInstallation; - } - - /** - * Setter for whether the modloader server should be installed. - * @author Griefed - * @param includeServerInstallation Boolean. Value of whether the modloader server should be installed to store. - */ - public void setIncludeServerInstallation(Boolean includeServerInstallation) { - this.includeServerInstallation = includeServerInstallation; - } - - /** - * Getter for whether the server-icon.png should be copied to the server pack. - * @author Griefed - * @return Boolean. Whether the server-icon.png should be copied to the server pack. - */ - public Boolean getIncludeServerIcon() { - return includeServerIcon; - } - - /** - * Setter for whether the server-icon.png should be copied to the server pack. - * @author Griefed - * @param includeServerIcon Boolean. Value of whether the server-icon.png should be copied to the server pack. - */ - public void setIncludeServerIcon(Boolean includeServerIcon) { - this.includeServerIcon = includeServerIcon; - } - - /** - * Getter for whether the server.properties should be copied to the server pack. - * @author Griefed - * @return Boolean. Whether the server.properties should be copied to the server pack. - */ - public Boolean getIncludeServerProperties() { - return includeServerProperties; - } - - /** - * Setter for whether the server.properties should be copied to the server pack. - * @author Griefed - * @param includeServerProperties Boolean. Value of whether the server.properties should be copied to the server pack to store. - */ - public void setIncludeServerProperties(Boolean includeServerProperties) { - this.includeServerProperties = includeServerProperties; - } - - /** - * Getter for whether a ZIP-archive of the server pack should be created. - * @author Griefed - * @return Boolean. Whether a ZIP-archive of the server pack should be created. - */ - public Boolean getIncludeZipCreation() { - return includeZipCreation; - } - - /** - * Setter for whether a ZIP-archive of the server pack should be created. - * @author Griefed - * @param includeZipCreation Boolean. Value of whether a ZIP-archive of the server pack should created to store. - */ - public void setIncludeZipCreation(Boolean includeZipCreation) { - this.includeZipCreation = includeZipCreation; - } - - /** - * Override of toString to get a list of all configuration values as a concatenated string. - * @author Griefed - * @return A concatenated string of the full configuration. - */ - @Override - public String toString() { - return "ConfigurationModel{" + - "clientMods=" + clientMods + - ", copyDirs=" + copyDirs + - ", modpackDir='" + modpackDir + '\'' + - ", javaPath='" + javaPath + '\'' + - ", minecraftVersion='" + minecraftVersion + '\'' + - ", modLoader='" + modLoader + '\'' + - ", modLoaderVersion='" + modLoaderVersion + '\'' + - ", includeServerInstallation=" + includeServerInstallation + - ", includeServerIcon=" + includeServerIcon + - ", includeServerProperties=" + includeServerProperties + - ", includeZipcreation=" + includeZipCreation + - '}'; - } -} diff --git a/src/main/resources/addon.conf b/src/main/resources/addon.conf deleted file mode 100644 index 2d9eed584d3b49e2b025bfb6859aad16e58a638c..0000000000000000000000000000000000000000 --- a/src/main/resources/addon.conf +++ /dev/null @@ -1,3 +0,0 @@ -# Valid values are 'serverpack' -addontype="serverpack" -someconfig="This is an example for working with the addon.conf-file." \ No newline at end of file diff --git a/src/test/java/de/griefed/serverpackcreatorexampleaddon/configuration/ConfigurationHandlerTest.java b/src/test/java/de/griefed/serverpackcreatorexampleaddon/configuration/ConfigurationHandlerTest.java deleted file mode 100644 index 9bbb6fb611a2874722af1a07249bb221e1b6dfd8..0000000000000000000000000000000000000000 --- a/src/test/java/de/griefed/serverpackcreatorexampleaddon/configuration/ConfigurationHandlerTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (C) 2021 Griefed - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.griefed.serverpackcreatorexampleaddon.configuration; - -import de.griefed.serverpackcreatoraddonexample.configuration.ConfigurationHandler; -import de.griefed.serverpackcreatoraddonexample.configuration.ConfigurationModel; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class ConfigurationHandlerTest { - - private final ConfigurationHandler configurationHandler; - private final ConfigurationModel configurationModel; - - ConfigurationHandlerTest() { - List<String> clientMods = new ArrayList<>(Arrays.asList( - "AmbientSounds", - "BackTools", - "BetterAdvancement", - "BetterPing", - "cherished", - "ClientTweaks", - "Controlling", - "DefaultOptions", - "durability", - "DynamicSurroundings", - "itemzoom", - "jei-professions", - "jeiintegration", - "JustEnoughResources", - "MouseTweaks", - "Neat", - "OldJavaWarning", - "PackMenu", - "preciseblockplacing", - "SimpleDiscordRichPresence", - "SpawnerFix", - "TipTheScales", - "WorldNameRandomizer" - )); - List<String> copyDirs = new ArrayList<>(Arrays.asList( - "config", - "mods", - "scripts", - "seeds", - "defaultconfigs" - )); - String modpackDir = "/some/path/to/a/dir"; - String javaPath = "/path/to/some/java/installation/bin/java"; - String minecraftVersion = "1.16.5"; - String modLoader = "Forge"; - String modLoaderVersion = "36.2.2"; - boolean includeServerInstallation = true; - boolean includeServerIcon = true; - boolean includeServerProperties = true; - boolean includeStartScripts = true; - boolean includeZipCreation = true; - String[] args = new String[12]; - args[0] = clientMods.toString(); - args[1] = copyDirs.toString(); - args[2] = modpackDir; - args[3] = javaPath; - args[4] = minecraftVersion; - args[5] = modLoader; - args[6] = modLoaderVersion; - args[7] = String.valueOf(includeServerInstallation); - args[8] = String.valueOf(includeServerIcon); - args[9] = String.valueOf(includeServerProperties); - args[10] = String.valueOf(includeStartScripts); - args[11] = String.valueOf(includeZipCreation); - this.configurationModel = new ConfigurationModel(); - this.configurationHandler = new ConfigurationHandler(args, configurationModel); - } - - @Test - void configurationHandlerTest() { - Assertions.assertNotNull(configurationModel); - } -} diff --git a/src/test/java/de/griefed/serverpackcreatorexampleaddon/configuration/ConfigurationModelTest.java b/src/test/java/de/griefed/serverpackcreatorexampleaddon/configuration/ConfigurationModelTest.java deleted file mode 100644 index c8a41fdb3503878742f1206a667393999256f74a..0000000000000000000000000000000000000000 --- a/src/test/java/de/griefed/serverpackcreatorexampleaddon/configuration/ConfigurationModelTest.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (C) 2021 Griefed - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.griefed.serverpackcreatorexampleaddon.configuration; - -import de.griefed.serverpackcreatoraddonexample.configuration.ConfigurationModel; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -@SuppressWarnings("ConstantConditions") -public class ConfigurationModelTest { - - private final ConfigurationModel configurationModel; - - ConfigurationModelTest() { - configurationModel = new ConfigurationModel(); - } - - @Test - void getsetClientModsTest() { - List<String> clientMods = new ArrayList<>(Arrays.asList( - "AmbientSounds", - "BackTools", - "BetterAdvancement", - "BetterPing", - "cherished", - "ClientTweaks", - "Controlling", - "DefaultOptions", - "durability", - "DynamicSurroundings", - "itemzoom", - "jei-professions", - "jeiintegration", - "JustEnoughResources", - "MouseTweaks", - "Neat", - "OldJavaWarning", - "PackMenu", - "preciseblockplacing", - "SimpleDiscordRichPresence", - "SpawnerFix", - "TipTheScales", - "WorldNameRandomizer" - )); - configurationModel.setClientMods(clientMods); - Assertions.assertNotNull(configurationModel.getClientMods()); - Assertions.assertEquals(clientMods, configurationModel.getClientMods()); - } - - @Test - void getsetCopyDirsTest() { - List<String> copyDirs = new ArrayList<>(Arrays.asList( - "config", - "mods", - "scripts", - "seeds", - "defaultconfigs" - )); - configurationModel.setCopyDirs(copyDirs); - Assertions.assertNotNull(configurationModel.getCopyDirs()); - Assertions.assertEquals(copyDirs, configurationModel.getCopyDirs()); - } - - @Test - void getsetModpackDirTest() { - String modpackDir = "/some/path/to/a/dir"; - configurationModel.setModpackDir(modpackDir); - Assertions.assertNotNull(configurationModel.getModpackDir()); - Assertions.assertEquals(modpackDir, configurationModel.getModpackDir()); - } - - @Test - void getsetJavaPathTest() { - String javaPath = "/path/to/some/java/installation/bin/java"; - configurationModel.setJavaPath(javaPath); - Assertions.assertNotNull(configurationModel.getJavaPath()); - Assertions.assertEquals(javaPath, configurationModel.getJavaPath()); - } - - @Test - void getsetMinecraftVersionTest() { - String minecraftVersion = "1.16.5"; - configurationModel.setMinecraftVersion(minecraftVersion); - Assertions.assertNotNull(configurationModel.getMinecraftVersion()); - Assertions.assertEquals(minecraftVersion, configurationModel.getMinecraftVersion()); - } - - @Test - void getsetModLoaderTest() { - String modLoader = "Forge"; - configurationModel.setModLoader(modLoader); - Assertions.assertNotNull(configurationModel.getModLoader()); - Assertions.assertEquals(modLoader, configurationModel.getModLoader()); - } - - @Test - void getsetModLoaderVersionTest() { - String modLoaderVersion = "36.2.2"; - configurationModel.setModLoaderVersion(modLoaderVersion); - Assertions.assertNotNull(configurationModel.getModLoaderVersion()); - Assertions.assertEquals(modLoaderVersion, configurationModel.getModLoaderVersion()); - } - - @Test - void getsetIncludeServerInstallationTest() { - boolean includeServerInstallation = true; - boolean includeServerInstallationFalse = false; - configurationModel.setIncludeServerInstallation(includeServerInstallation); - Assertions.assertNotNull(configurationModel.getIncludeServerInstallation()); - Assertions.assertTrue(configurationModel.getIncludeServerInstallation()); - configurationModel.setIncludeServerInstallation(includeServerInstallationFalse); - Assertions.assertNotNull(configurationModel.getIncludeServerInstallation()); - Assertions.assertFalse(configurationModel.getIncludeServerInstallation()); - } - - @Test - void getsetIncludeServerIconTest() { - boolean includeServerIcon = true; - boolean includeServerIconFalse = false; - configurationModel.setIncludeServerIcon(includeServerIcon); - Assertions.assertNotNull(configurationModel.getIncludeServerIcon()); - Assertions.assertTrue(configurationModel.getIncludeServerIcon()); - configurationModel.setIncludeServerIcon(includeServerIconFalse); - Assertions.assertNotNull(configurationModel.getIncludeServerIcon()); - Assertions.assertFalse(configurationModel.getIncludeServerIcon()); - } - - @Test - void getsetIncludeServerPropertiesTest() { - boolean includeServerProperties = true; - boolean includeServerPropertiesFalse = false; - configurationModel.setIncludeServerProperties(includeServerProperties); - Assertions.assertNotNull(configurationModel.getIncludeServerProperties()); - Assertions.assertTrue(configurationModel.getIncludeServerProperties()); - configurationModel.setIncludeServerProperties(includeServerPropertiesFalse); - Assertions.assertNotNull(configurationModel.getIncludeServerProperties()); - Assertions.assertFalse(configurationModel.getIncludeServerProperties()); - } - - @Test - void getsetIncludeZipCreationTest() { - boolean includeZipCreation = true; - boolean includeZipCreationFalse = false; - configurationModel.setIncludeZipCreation(includeZipCreation); - Assertions.assertNotNull(configurationModel.getIncludeZipCreation()); - Assertions.assertTrue(configurationModel.getIncludeZipCreation()); - configurationModel.setIncludeZipCreation(includeZipCreationFalse); - Assertions.assertNotNull(configurationModel.getIncludeZipCreation()); - Assertions.assertFalse(configurationModel.getIncludeZipCreation()); - } - - @Test - void toStringTest() { - List<String> clientMods = new ArrayList<>(Arrays.asList( - "AmbientSounds", - "BackTools", - "BetterAdvancement", - "BetterPing", - "cherished", - "ClientTweaks", - "Controlling", - "DefaultOptions", - "durability", - "DynamicSurroundings", - "itemzoom", - "jei-professions", - "jeiintegration", - "JustEnoughResources", - "MouseTweaks", - "Neat", - "OldJavaWarning", - "PackMenu", - "preciseblockplacing", - "SimpleDiscordRichPresence", - "SpawnerFix", - "TipTheScales", - "WorldNameRandomizer" - )); - List<String> copyDirs = new ArrayList<>(Arrays.asList( - "config", - "mods", - "scripts", - "seeds", - "defaultconfigs" - )); - String modpackDir = "/some/path/to/a/dir"; - String javaPath = "/path/to/some/java/installation/bin/java"; - String minecraftVersion = "1.16.5"; - String modLoader = "Forge"; - String modLoaderVersion = "36.2.2"; - boolean includeServerInstallation = true; - boolean includeServerInstallationFalse = false; - boolean includeServerIcon = true; - boolean includeServerIconFalse = false; - boolean includeServerProperties = true; - boolean includeServerPropertiesFalse = false; - boolean includeStartScripts = true; - boolean includeStartScriptsFalse = false; - boolean includeZipCreation = true; - boolean includeZipCreationFalse = false; - configurationModel.setClientMods(clientMods); - configurationModel.setCopyDirs(copyDirs); - configurationModel.setModpackDir(modpackDir); - configurationModel.setJavaPath(javaPath); - configurationModel.setMinecraftVersion(minecraftVersion); - configurationModel.setModLoader(modLoader); - configurationModel.setModLoaderVersion(modLoaderVersion); - configurationModel.setIncludeServerInstallation(includeServerInstallation); - configurationModel.setIncludeServerIcon(includeServerIcon); - configurationModel.setIncludeServerProperties(includeServerProperties); - configurationModel.setIncludeZipCreation(includeZipCreation); - String toString = "ConfigurationModel{" + - "clientMods=" + clientMods + - ", copyDirs=" + copyDirs + - ", modpackDir='" + modpackDir + '\'' + - ", javaPath='" + javaPath + '\'' + - ", minecraftVersion='" + minecraftVersion + '\'' + - ", modLoader='" + modLoader + '\'' + - ", modLoaderVersion='" + modLoaderVersion + '\'' + - ", includeServerInstallation=" + includeServerInstallation + - ", includeServerIcon=" + includeServerIcon + - ", includeServerProperties=" + includeServerProperties + - ", includeZipcreation=" + includeZipCreation + - '}'; - Assertions.assertNotNull(configurationModel.toString()); - Assertions.assertEquals(toString, configurationModel.toString()); - configurationModel.setIncludeServerInstallation(includeServerInstallationFalse); - configurationModel.setIncludeServerIcon(includeServerIconFalse); - configurationModel.setIncludeServerProperties(includeServerPropertiesFalse); - configurationModel.setIncludeZipCreation(includeZipCreationFalse); - String toStringFalse = "ConfigurationModel{" + - "clientMods=" + clientMods + - ", copyDirs=" + copyDirs + - ", modpackDir='" + modpackDir + '\'' + - ", javaPath='" + javaPath + '\'' + - ", minecraftVersion='" + minecraftVersion + '\'' + - ", modLoader='" + modLoader + '\'' + - ", modLoaderVersion='" + modLoaderVersion + '\'' + - ", includeServerInstallation=" + includeServerInstallationFalse + - ", includeServerIcon=" + includeServerIconFalse + - ", includeServerProperties=" + includeServerPropertiesFalse + - ", includeZipcreation=" + includeZipCreationFalse + - '}'; - Assertions.assertNotNull(configurationModel.toString()); - Assertions.assertEquals(toStringFalse, configurationModel.toString()); - } -}