Setting up a Project Poseidon Plugin: Difference between revisions

From RetroMC
Jump to navigation Jump to search
(Created page with "Category:Guides {{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. {{user|zavdav}} will be using IntelliJ IDEA and the Azul Zulu OpenJDK build for this guide.}} # Open your IDE and create a new Maven project #: thumb|none|400px #: When creating a project, choose a Group ID. In most cases, it should look like this:<br><...")
 
(Add links)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:Guides]]
[[Category:Guides]]
{{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.
{{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.
{{user|zavdav}} will be using IntelliJ IDEA and the Azul Zulu OpenJDK build for this guide.}}
{{user|zavdav}} will be using [https://www.jetbrains.com/idea/ IntelliJ IDEA] and the [https://www.azul.com/downloads/ Azul Zulu OpenJDK] build for this guide. <br><br>
You can also use the pre-made [https://github.com/project-poseidon-plugin-devs/project-poseidon-plugin-template template], which includes instructions on how to set it up.}}


# Open your IDE and create a new Maven project
# Open your IDE and create a new Maven project
#: [[File:poseidonplugin1.png|thumb|none|400px]]
#: [[File:poseidonplugin1.png|thumb|none|350px]]
#: When creating a project, choose a Group ID. In most cases, it should look like this:<br><code>me.<yourname>.<pluginname></code><br>For more information, go to https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html
#: When creating a project, choose a Group ID. In most cases, it should look like this:<br><code>me.yourname.pluginname</code><br>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:
#: After creating the project, your project structure should look like this:
#: [[File:poseidonplugin2.png|thumb|none|300px]]
#: [[File:poseidonplugin2.png|thumb|none|300px]]
# Go into the <code>resources</code> folder and create a new file called <code>plugin.yml</code>
# Go into the <code>src/main/resources</code> directory and create a new file called <code>plugin.yml</code>
# In <code>plugin.yml</code>, insert these values:
# In <code>plugin.yml</code>, insert these values:
#* name: The name of the plugin
#* name: The name of the plugin
Line 14: Line 15:
#* version: The version of the plugin
#* version: The version of the plugin
#: [[File:poseidonplugin3.png|thumb|none|350px]]
#: [[File:poseidonplugin3.png|thumb|none|350px]]
# in the <code>src/main/java</code> folder, create a new package with the same name as your Group ID.
# In the <code>src/main/java</code> directory, create a new package with the same name as your Group ID.
#: [[File:poseidonplugin4.png|thumb|none|300px]]
#: [[File:poseidonplugin4.png|thumb|none|300px]]
# In this package, create a new class with the same name as specified in <code>plugin.yml</code>.
# In this package, create a new class with the same name as specified in <code>plugin.yml</code>.
Line 81: Line 82:
</project>
</project>
</pre>
</pre>
<dl><dd>This will tell Maven to use the source files from the Project Poseidon repository when compiling and to compile the plugin in Java 8.<br>
<dl><dd>This will tell Maven to use the source files from the [[Project Poseidon]] repository when compiling and to compile the plugin in Java 8.<br>
Make sure to replace <code><groupId></code>, <code><artifactId></code> and <code><name></code> according to your project structure.
Make sure to replace the values in <code><groupId></code>, <code><artifactId></code> and <code><name></code> according to your project structure.
[[File:poseidonplugin6.png|thumb|none|600px]]
[[File:poseidonplugin6.png|thumb|none|550px]]
</dd></dl>
</dd></dl>
<ol start="7">
<ol start="7">
Line 103: Line 104:
</li></ol>
</li></ol>
<br>
<br>
Upon starting the server, the "Hello World! message can be seen in the server console.
Upon starting the server, the "Hello World!" message can be seen in the server console.
<dl><dd>[[File:poseidonplugin11.png|thumb|none|600px]]</dd><dl>
<dl><dd>[[File:poseidonplugin11.png|thumb|none|600px]]</dd><dl>

Latest revision as of 08:06, 10 November 2024

ℹ️ 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.

You can also use the pre-made template, which includes instructions on how to set it up.

  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 src/main/resources directory 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 directory, 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 the values in <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.