Setting up a Project Poseidon Plugin

From RetroMC
Revision as of 08:48, 3 September 2024 by Zavdav (talk | contribs)
Jump to navigation Jump to search

ℹ️ Notice: Before following this guide, make sure you have a Java IDE installed which supports creating Maven projects. It is also recommended to use a Java 8 OpenJDK build.

16.png zavdav will be using IntelliJ IDEA and the Azul Zulu OpenJDK build for this guide.

  1. Open your IDE and create a new Maven project
    When creating a project, choose a Group ID. In most cases, it should look like this:
    me.<yourname>.<pluginname>
    For more information, go to https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html
    After creating the project, your project structure should look like this:
  2. Go into the resources folder and create a new file called plugin.yml
  3. In plugin.yml, insert these values:
    • name: The name of the plugin
    • main: The main class of the plugin (has to inherit org.bukkit.plugin.java.JavaPlugin)
    • version: The version of the plugin
  4. In the src/main/java folder, create a new package with the same name as your Group ID.
  5. In this package, create a new class with the same name as specified in plugin.yml.
  6. Open the file called pom.xml and paste the following text into the file:
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>me.yourname.pluginname</groupId>
    <artifactId>ProjectName</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>PluginName</name>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>johnymuffin-nexus-releases</id>
            <url>https://repository.johnymuffin.com/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.legacyminecraft.poseidon</groupId>
            <artifactId>poseidon-craftbukkit</artifactId>
            <version>1.1.8</version>
        </dependency>
    </dependencies>

</project>
This will tell Maven to use the source files from the Project Poseidon repository when compiling and to compile the plugin in Java 8.
Make sure to replace <groupId>, <artifactId> and <name> according to your project structure.
  1. Go into your IDE's terminal and run mvn clean package
  2. Reload your Maven project
  3. Write some code
    For demonstration purposes, 16.png zavdav has added a simple "Hello World!" message that will be displayed in the server console.
  4. Run mvn clean package in the terminal
    The compiled jar file should be in the target directory inside your project.
  5. Copy the jar file into the plugins folder of your Project Poseidon server.


Upon starting the server, the "Hello World! message can be seen in the server console.