Skip to content

Installation

Cosimo edited this page Jan 6, 2025 · 1 revision

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.

1. Adding plugin-utilities as a dependency

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.

2. Maven shading

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')
   }
}

3. Library initialization

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:

  1. Register a singleton instance of the MenuManager so that it can run in the background and handle all of our menus that we create, without having to ever call it again.
  2. We create a YAML file handler for the command-config.yml file and immediately check for its existence in the plugins/ExamplePlugin directory; if it doesn't exist, it's copied from our bundled resources directory and placed in the first directory. This is all done in the reloadFile() call, and finally we read it into a FileConfiguration using getMemory().
  3. We pass the FileConfiguration's ConfigurationSection that's a path in the configuration file, potentially containing some configurable behaviour of our example command by the server owner.
Clone this wiki locally