Skip to content
Snippets Groups Projects
Commit 68b01e06 authored by Griefed's avatar Griefed :joystick:
Browse files

Initial commit. Provide base example of an addon for ServerPackCreator with...

Initial commit. Provide base example of an addon for ServerPackCreator with documentation and tests.
parents
No related branches found
No related tags found
No related merge requests found
Showing
with 1291 additions and 0 deletions
# gradle
/tests
/build
/.gradle
gradlew
gradlew.bat
# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
out
*.ipr
*.iws
*.iml
\ No newline at end of file
LICENSE 0 → 100644
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.
\ No newline at end of file
# Example Addon for ServerPackCreator
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.
This example provides JavaDocs and tests.
# 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.
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.
**Hence, the addon functionality.**
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!
# 2. How
## 2.1 Values to work with
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
* includeStartScripts
* includeZipCreation
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.
## 2.2 Where to get values from
Working with this example, you can simply call any `get`-method in the `ConfigurationModel`-class and use it to do your
operations.
## 2.3 Working directory
All addons are run in the <code>work/temp</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!
## 2.4 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.
# 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.
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
addon does and a link to the GitHub repository as well. I will add it to a list in the README of ServerPackCreator.
**NOTE: I only add addons which are open source. I will NOT add any direct download links to any file. People must be able
to check your code before they download and install your addon, and as such, I will only add a link to your addon-respository
along with a small description, if you provided one.
Example:
| Addon | Creator | Description |
| :---- | :------ | :---------- |
| [ExampleAddon]() | Griefed | An example addon providing a starting point for addon development. |
\ No newline at end of file
import java.text.SimpleDateFormat
plugins {
id 'java'
id 'idea'
}
group 'de.griefed'
version '1.0-SNAPSHOT'
//noinspection GroovyUnusedAssignment
sourceCompatibility = targetCompatibility = '1.8'
repositories {
mavenCentral()
}
configurations {
embed
implementation.extendsFrom(embed)
}
dependencies {
embed 'com.typesafe:config:1.4.1'
// Testing
testImplementation 'org.mockito:mockito-core:3.11.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
}
test {
useJUnitPlatform()
// Mention test result in logs
testLogging {
events "passed",
"skipped",
"failed"
}
}
// Include specific files in resources folder, like the license and readme.
tasks.register('about', Copy) {
dependsOn tasks.named('clean')
from layout.projectDirectory.file("LICENSE") into layout.projectDirectory.dir("src/main/resources")
from layout.projectDirectory.file("README.md") into layout.projectDirectory.dir("src/main/resources")
}
tasks.withType(Javadoc) {
options.addStringOption('encoding', 'UTF-8')
}
javadoc {
options.memberLevel = JavadocMemberLevel.PRIVATE
classpath = sourceSets.main.runtimeClasspath
}
java {
withSourcesJar()
withJavadocJar()
}
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from {
configurations.embed.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
}
//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')}",
)
}
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-**'
)
}
\ No newline at end of file
File added
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
rootProject.name = 'ServerPackCreatorExampleAddon'
/*
* 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.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) {
String configurationWeReceived = Arrays.toString(args);
ConfigurationModel configurationModel = new ConfigurationModel();
ConfigurationHandler configurationHandler = new ConfigurationHandler(args, configurationModel);
AddonConfiguration addonConfiguration = new AddonConfiguration(null);
System.out.println("We have recieved the following configuration: " + configurationWeReceived);
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 copy the start scripts: " + configurationModel.getIncludeStartScripts());
System.out.println("Whether to create a ZIP-archive of the server pack:" + configurationModel.getIncludeZipCreation());
System.out.println("");
System.out.println("Example addon configuration for serverpackcreator.addon.someconfig: " + addonConfiguration.exampleConfig());
}
}
/*
* 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 java.io.File;
import java.util.Objects;
/**
* 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
* @param injectedAddonConfiguration Either instantiate this class with your own {@link Config} object, or let it create
* one using the addon.conf-file.
*/
public AddonConfiguration(Config injectedAddonConfiguration) {
if (injectedAddonConfiguration == null) {
ClassLoader classLoader = getClass().getClassLoader();
File addonConfigFile = new File(Objects.requireNonNull(classLoader.getResource("addon.conf")).getFile());
this.ADDONCONFIGURATION = ConfigFactory.parseFile(addonConfigFile);
} else {
this.ADDONCONFIGURATION = injectedAddonConfiguration;
}
}
/**
* 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("serverpackcreator.addon.someconfig");
}
}
/*
* 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.setIncludeStartScripts(Boolean.valueOf(args[10]));
CONFIGURATIONMODEL.setIncludeZipCreation(Boolean.valueOf(args[11]));
}
}
/*
* 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 includeStartScripts;
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 the start scripts should be copied to the server pack.
* @author Griefed
* @return Boolean. Whether the start scripts should be copied to the server pack.
*/
public Boolean getIncludeStartScripts() {
return includeStartScripts;
}
/**
* Setter for whether the start scripts should be copied to the server pack.
* @author Griefed
* @param includeStartScripts Boolean. Value of whether the start scripts should be copied to the server pack.
*/
public void setIncludeStartScripts(Boolean includeStartScripts) {
this.includeStartScripts = includeStartScripts;
}
/**
* 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 +
", includeStartScripts=" + includeStartScripts +
", includeZipcreation=" + includeZipCreation +
'}';
}
}
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.
\ No newline at end of file
# Example Addon for ServerPackCreator
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.
# 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.
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.
**Hence, the addon functionality.**
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!
# 2. How
## 2.1 Values to work with
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
* includeStartScripts
* includeZipCreation
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.
## 2.2 Where to get values from
Working with this example, you can simply call any `get`-method in the `ConfigurationModel`-class and use it to do your
operations.
## 2.3 Working directory
All addons are run in the <code>work/temp</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!
## 2.4 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.
# 3. Building
1. Fork and clone this repository
2. Make your changes and additions.
3. Build with `gradlew about build`.
4. Copy the JAR-file from `build/libs` to the addons-directory created by ServerPackCreator.
5. Run ServerPackCreator!
## 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
addon does and a link to the GitHub repository as well. I will add it to a list in the README of ServerPackCreator.
**NOTE: I only add addons which are open source. I will NOT add any direct download links to any file. People must be able
to check your code before they download and install your addon, and as such, I will only add a link to your addon-respository
along with a small description, if you provided one.
Example:
| Addon | Creator | Description |
| :---- | :------ | :---------- |
| [ExampleAddon]() | Griefed | An example addon providing a starting point for addon development. |
\ No newline at end of file
# Valid values are 'serverpack'
serverpackcreator.addon.type=serverpack
serverpackcreator.addon.someconfig="This is an example for working with the addon.conf-file."
\ No newline at end of file
/*
* 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.AddonConfiguration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class AddonConfigurationTest {
private final AddonConfiguration addonConfiguration;
AddonConfigurationTest() {
this.addonConfiguration = new AddonConfiguration(null);
}
@Test
void getAddonConfigurationTest() {
Assertions.assertNotNull(addonConfiguration.getAddonConfiguration());
}
@Test
void exampleConfigTest() {
Assertions.assertEquals("This is an example for working with the addon.conf-file.", addonConfiguration.getAddonConfiguration().getString("serverpackcreator.addon.someconfig"));
}
}
/*
* 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);
}
}
/*
* 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 getsetIncludeStartScriptsTest() {
boolean includeStartScripts = true;
boolean includeStartScriptsFalse = false;
configurationModel.setIncludeStartScripts(includeStartScripts);
Assertions.assertNotNull(configurationModel.getIncludeStartScripts());
Assertions.assertTrue(configurationModel.getIncludeStartScripts());
configurationModel.setIncludeStartScripts(includeStartScriptsFalse);
Assertions.assertNotNull(configurationModel.getIncludeStartScripts());
Assertions.assertFalse(configurationModel.getIncludeStartScripts());
}
@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.setIncludeStartScripts(includeStartScripts);
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 +
", includeStartScripts=" + includeStartScripts +
", includeZipcreation=" + includeZipCreation +
'}';
Assertions.assertNotNull(configurationModel.toString());
Assertions.assertEquals(toString, configurationModel.toString());
configurationModel.setIncludeServerInstallation(includeServerInstallationFalse);
configurationModel.setIncludeServerIcon(includeServerIconFalse);
configurationModel.setIncludeServerProperties(includeServerPropertiesFalse);
configurationModel.setIncludeStartScripts(includeStartScriptsFalse);
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 +
", includeStartScripts=" + includeStartScriptsFalse +
", includeZipcreation=" + includeZipCreationFalse +
'}';
Assertions.assertNotNull(configurationModel.toString());
Assertions.assertEquals(toStringFalse, configurationModel.toString());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment