-
Notifications
You must be signed in to change notification settings - Fork 1
Installation
This library isn't a plugin, nor does it need to be installed on a server for your plugin to work with it. Our library unfortunately or fortunately isn't that relevant for servers to care to install it just for your plugin to work.
Instead, you compile it into your Java plugin's classpath using a shade plugin for your build automation tool of choice, since the library is rather lightweight.
Add the library as a compiled JitPack dependency via a build automation tool that you're using, such as Maven, Gradle, sbt, etc. See all releases, snapshots and guides at the official JitPack website of this project.
Shade the dependency library using JAR minimization to exclude unused features from being compiled with your plugin, which will decrease the file size impact of the dependency while keeping your plugin lightweight. Even though the dependency is small, this process ensures efficient packaging by eliminating unnecessary code.
Here's how you can configure it using Maven Shade Plugin, by adding inside Maven <plugins>...</plugins>:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>VERSION</version> <!-- Replace VERSION with the latest plugin version -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<!-- Replace the "Tag" with the latest release version -->
<includes>com.github.CosimoTiger:plugin-utilities:Tag</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>I don't use Gradle, but here's how you can most likely configure it using the Gradle Shadow plugin (Groovy):
plugins {
id 'java'
// Replace the "VERSION" with the latest release available at https://github.com/GradleUp/shadow
id 'com.gradleup.shadow' version 'VERSION'
}
shadowJar {
archiveClassifier.set('all')
manifest {
attributes 'Main-Class': 'path.to.your.PluginMain'
}
dependencies {
// Replace the "Tag" with the latest release version
include dependency('com.github.CosimoTiger:plugin-utilities:Tag')
}
}Start writing your code. Here's the typical plugin initialization code example:
import com.cosimo.utilities.file.YamlFile;
import com.cosimo.utilities.menu.manager.MenuManager;
import org.bukkit.plugin.java.JavaPlugin;
public class ExamplePlugin extends JavaPlugin {
@Override
public void onEnable() {
MenuManager.setInstance(new MenuManager(this));
final var config = new YamlFile(this, "command-config.yml").reloadFile().getMemory();
getCommand("example").setExecutor(new ExampleCommand(config.getConfigurationSection("commands.example")));
}
}In this example, once our plugin is enabled through onEnable() being called, we:
- Register a singleton instance of the
MenuManagerso that it can run in the background and handle all of our menus that we create, without having to ever call it again. - We create a YAML file handler for the
command-config.ymlfile and immediately check for its existence in theplugins/ExamplePlugindirectory; if it doesn't exist, it's copied from our bundledresourcesdirectory and placed in the first directory. This is all done in thereloadFile()call, and finally we read it into aFileConfigurationusinggetMemory(). - We pass the
FileConfiguration'sConfigurationSectionthat's a path in the configuration file, potentially containing some configurable behaviour of ourexamplecommand by the server owner.