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

Merge branch 'rewriteWithPlf4j' into 'master'

Rewrite with plf4j

See merge request !24
parents 611d9fce ab71fa11
No related branches found
No related tags found
1 merge request!24Rewrite with plf4j
Showing
with 386 additions and 1011 deletions
......@@ -13,4 +13,5 @@
out
*.ipr
*.iws
*.iml
\ No newline at end of file
*.iml
/libs/
This diff is collapsed.
......@@ -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
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'
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;
}
}
}
/*
* 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]);
}
}
/*
* 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");
}
}
/*
* 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]));
}
}
/*
* 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 +
'}';
}
}
# Valid values are 'serverpack'
addontype="serverpack"
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.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 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());
}
}
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