Guide Getting started with Intellij to code your own Plugins! (Outdated)

Envoia

Community Champion

Status

offline

Posts

688

Likes

5,828

Bits Credits

195

LEVEL

10

2,465 XP

* This guide will be using Windows - macOS and Linux might be added later*
** Pictures will be added later **
*** This guide wont be going over plugin coding, just how to get started with IntelliJ and Plugins. I plan on posting beginner coding guides in the future. ***


Installing Intelli
Start by downloading IntelliJ HERE.
Once on the site, click on the blue or black download button. These will redirect you to the download page where you can pick between Windows, macOS and Linux operating systems. You'll find there's Ultimate and Community. (Feel free to purchase Ultimate, but it's not needed.) Under Community, click on the download button to get the installer.

Setting up IntelliJ
If you already have IntelliJ installed, I recommend you uninstall; then delete the hidden ".IDEA" and ".imi" files in any project folder.
You can locate the hidden files in "%APPDATA%\JetBrains\" and "%LOCALAPPDATA%\JetBrains".

Before we start with the plugin itself, we'll be editing global settings on IntelliJ. It's recommended you apply all these settings to save time.
You should now be on the "Welcome to IntelliJ IDEA." If you already have a project opened, close the project to show the screen. Adjusting the settings from the welcome screen ensures all projects (current/new) receive these settings. Now click on "Customize" and click on "All Settings" at the bottom. In your settings, open the Keymap section. Here will be adding a keymap to close your active tab. Set this to whatever you want, but I recommend CTRL+W. Search "Keymap", then open that up and search "Close Active Tab". We'll now be adjusting the plugins used by IntelliJ. Clear your search for Keymap, and Plugins will appear below Editor.

Install the following plugins:
Save Actions
Fast-Scrolling
DO NOT install Minecraft Development. It's unnecessary and will restrict what versions of Minecraft your plugins support.

Increasing performance with IntelliJ.
Disable the following plugins:
Andriod Selection
Code Coverage Section
HTML and XML Section
Groovy
Plugin Development Section
Test Tools Section
Version Controls Section (Optional if you don't want to use GitHub. If you plan on using GitHub disable this)
Code With ME
Completion Stats Collector
Copyright
Grazie
IDE Features Trainer (Optional, but you probably won't need it)
Kotlin
Task Management
Once finished, click on OK and restart IntelliJ

Configuring plugins
Open Settings > Other Settings > Save Actions and enable the following entries:
Generation section:
Activate save actions on save

Formatting actions:
Optimize Imports
Reformat file

Build actions:
Reload files in running debugger

Java Inspect and quick fix:
Add missing @override annotations
Remove final from private method
Remove explicit generic type for diamond
Remove unnecessary semicolon

Build projects automatically
Open Settings > Build, Execution and Deployment > Compiler
Select "Build project automatically" and also increase "Share build process heap size (Mbytes)" to 1500 if your computer allows for it.
Inside the same settings menu, go to Build Tools > Maven > Importing. Enable "Automatically download" for "Sources" and "Documentation".

Enhance your editor settings
Open Settings > Editor > Code Style > Java > Tabs and Indents
Enable "Use tab character".
Open Settings > Editor > Inspections
Search "typo" and untick "Typo" option for proofreading and UI form sections.
Search "Static Methods Declared Final" and untick that option.
Open Settings > Editor > General > Auto Import
Enable "Optimize Imports on the fly" and "Add unambiguous import on the fly".
Open Settings > Editor > General > Code Completion
Untick "Match case" setting.
Enable "Show the documentation popup" and set it to "500"
Enable "Show Parameter name hints on completion"
Open Settings > Editor > General > Code Folding
In Java section untick "One-line methods" and "Closures"
Open Settings > Editor > General > Editor Tabs
Tick "Mark modified(*)"
Open Settings > Editor > General > Smart Keys
Untick "Use "CamelHumps" words".

Now close that out and create a new project. Upon clicking create a new project, you'll need to change "Build system" to Maven and select your JDK. If you don't have one already, it's okay since IntelliJ can download it. I recommend Java 17 as Minecraft now requires it. Now you may choose the name of your project, but try not to use spaces. It will make your life harder.

Setting up pom.xml
Before we start, you need to decide on an API version HERE
Now, open up the pom.xml file and paste the text at the bottom above "</project>".
Code:
<repositories>

        <!-- This adds the Spigot Maven repository to the build -->

        <repository>

            <id>spigot-repo</id>

            <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>

        </repository>

    </repositories>



    <dependencies>

        <!--This adds the Spigot API artifact to the build -->

        <dependency>

            <groupId>org.spigotmc</groupId>

            <artifactId>spigot-api</artifactId>

            <version>PUT API VERSION HERE</version>

            <scope>provided</scope>

        </dependency>

    </dependencies>

Afterwards replace "PUT API VERSION HERE" with the one you chose from the Spigot site. Now IntelliJ already should automatically download the sources from the settings above, but it's always good to double check. To confirm everything downloaded, right-click on the pom.xml file, navigate to "Maven", and click on "Download Sources and Documentation".

Package and Class Setup
Under your project files, you should see the ".idea" and "src" folders. Everything involving the plugin itself will go under the "src" folder, so open that up. Now open the "main" folder you'll find a folder called "java". Right-click the "Java" folder and create a new package. I recommend naming it something like "com.yourname.pluginname". Now right-click the package to create a Java Class. This will be the main class file of the plugin. Some people name it "Main", but I go with whatever I'm calling the plugin.

Class File Setup
When opening your class file, you should see something similar depending on your package and class names.

Java:
package net.nullforums.tutorial;

public class NFTutorial {
}

Copy the text below and do NOT replace your class or package name. Failure to follow this step will result in errors.

Java:
package net.nullforums.tutorial;

public class NFTutorial extends JavaPlugin { //Extend the JavaPlugin so we can implement internal methods.
    public void onEnable() { //Code used when plugin is loaded

    }

    public void onDisable() { //Code used when plugin is unloaded

    }
}

Plugin.yml Setup
Under the "src" and "main" folders, you should see a "resources" folder. Here we'll be creating the plugin.yml, which can be done by right-clicking the resources folder and create a new file. Make sure to name it "plugin.yml", as this is needed for plugins to work. Copy the text below into the file you just created.
Code:
main: net.nullforums.tutorial.NFTutorial //Replace with package and class name
name: NFTutorial //Replace with plugin name
version: 1.0
api-version: PUT API VERSION HERE //Same as pom.xml file

Compiling and Testing
At the top right of IntelliJ you'll see an "Add Configuration" button. Click on that and click the plus, located in the top left corner of the new window. Select Maven and name it whatever. Inside you'll see a "Run" section with a "Command line" text box. Inside the text box type "clean install" and hit apply. You can now close out of that window. You'll now see a green arrow to the right of where it used to say "Add Configuration"(Should be replaced with NAME [clean, install]). Once your plugin is ready clicking on that green arrow will compile the plugin.

With that you're now ready to start coding your first plugin.​
 
Last edited:

FateKid

DEVIL DID IT

Admin

Status

offline

Posts

14,947

Likes

130,140

Resources

3,398

Bits Credits

495

LEVEL

11

5,910 XP

Amazing write-up. I learned SO MANY THINGS that I wish I'd modified sooner in my Java workflow.
Tweaking my InteliJ settings is definitely going to speed up my overal IDE times. Just goes to show that making software work for you works for everyone.

As I've said, I am still learning Java. What exactly is the purpose of the POM? Does it function the same way another IDE may categorize a Linker to function?
I would assume it's just a map of what goes where and what is required within the project, similar to application manifests in C.

Thanks again for the write-up! Members, take note. This may be someone you want on your next Java project in the near future ;)

200.gif
 

Status

offline

Posts

58

Likes

1,657

Resources

28

Bits Credits

0

LEVEL

0

140 XP

Very good initial tutorial, the truth is that I have been programming simple plugins for a while, but I have always done the part of the manual pom, importing the paper jar and the javadoc and creating a custom artifact for the compilation of the jar. I never knew how the pom.xml works and well, in your tutorial I have understood something of it, although honestly I don't even know where it is located 🤣
 
Liked by:

Envoia

Community Champion

Status

offline

Posts

688

Likes

5,828

Bits Credits

195

LEVEL

10

2,465 XP

Very good initial tutorial, the truth is that I have been programming simple plugins for a while, but I have always done the part of the manual pom, importing the paper jar and the javadoc and creating a custom artifact for the compilation of the jar. I never knew how the pom.xml works and well, in your tutorial I have understood something of it, although honestly I don't even know where it is located 🤣
The pom saves you time as it will download everything needed if set up correctly. You can even use it to download APIs from other plugins that you want to hook into for compatibility.
Depending on your IntelliJ set-up, the pom file will automatically generate upon the project creation. I've attached a picture of where to locate it.

Screenshot_247.png
 
Liked by:

Envoia

Community Champion

Status

offline

Posts

688

Likes

5,828

Bits Credits

195

LEVEL

10

2,465 XP

As I've said, I am still learning Java. What exactly is the purpose of the POM? Does it function the same way another IDE may categorize a Linker to function?
I would assume it's just a map of what goes where and what is required within the project, similar to application manifests in C.
It's similar to how a linker works. The overall purpose of the pom is that it contains information about the project and configuration details used by Maven to build the project. For example, if you wanted placeholder API support, you'll add the following to your pom file.

Code:
<repository>
    <id>placeholderapi</id>
    <url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
        
<dependency>
    <groupId>me.clip</groupId>
    <artifactId>placeholderapi</artifactId>
    <version>2.10.9</version>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Adding your repositories and dependencies overall makes your life way easier.
 

Status

offline

Posts

58

Likes

1,657

Resources

28

Bits Credits

0

LEVEL

0

140 XP

The pom saves you time as it will download everything needed if set up correctly. You can even use it to download APIs from other plugins that you want to hook into for compatibility.
Depending on your IntelliJ set-up, the pom file will automatically generate upon the project creation. I've attached a picture of where to locate it.

View attachment 9666
I know that it also works for dependencies, since most of the plugins that let you use their API brought the line of code to use the pomo.xml but I had never used it, I tell you that I didn't even know what it was for.

And then my configuration when creating a project does not generate the pom for that reason I did not know where it was located.

I am currently learning something about the Fabric API.
 

Latest threads

Forum statistics

Threads
57,954
Messages
88,951
Members
54,795
Latest member
kaimadeinfuture
Top Bottom