How to make Spigot plugin (for Java beginners)

Overview

Here, we will create a Spigot plugin in Java. Since it is for Java beginners, we will explain from the basic knowledge of Java. If you have used Java before, please skip it as appropriate. Also, here we will use JDK8, which is the current recommended environment for Minecraft.

Preparation for preparation

-[] JDK8: here Please install the one that suits your OS.

-[] IntelliJ IDEA: Here Please install the one that suits your OS. The Community version is fine (Ultimate is charged).

Caution JDK8: A development kit for a programming language called Java that makes Minecraft. This time I will use version 8. IntelliJ IDEA: An integrated development environment (IDE) software used to write programs. (Hereafter IDEA) There are other things such as Eclipse and NetBeans, but since the author uses IDEA, we will also use IDEA in this course. Please refer to here etc. for Japanese localization. Since the author's environment is in Japanese, menu items etc. will be explained with Japanese names. The author is a Windows environment. You should be able to follow the same procedure on a Mac, but the details are unknown, so please check for yourself.

Preparation

When you start IDEA, the following screen will appear (The first time you start it, you will be asked if you want to import the settings, but "Do not import" under the options is okay.) IDEA.トップ画面 Press "Plug-in" from "Configuration" of the lower right gear. An input field will appear, so search for "minecraft". image.png Here, please install "Minecraft Development" displayed in the upper left. After installation, you will be asked to restart IDEA, so restart it.

If you don't see it, try "Search from repository". Minecraft Development installed here is an extension of IDEA that helps you create templates such as Spigot plugins.

Make a template

Initial setting

Now it's time to write the program. Press Create New Project. If the "Project SDK" at the top is none, select the java_home folder from "New". (For Windows, C: \ Program Files \ Java \ jdk1.8.0_181 etc.) If you have successfully installed Minecraft Development, you should see an item called "Minecraft" in the list on the left, click on it. image.png From here, check the Spigot Plugin and press Next.

Build settings

image.png On this screen, you will configure the build settings.

Group ID

Group ID specifies the group to which the plug-in belongs. Groups can be divided by author, function, etc., but anything is fine as long as you don't overlap with other people. Here, it is com.github.rona_tombo from the reverse order of the author's GitHub domain name. Only single-byte alphanumeric characters, periods ., and underscores _ can be used as cautions.

Artifact ID

The artifact ID is the ID that distinguishes the project. Normally, it is okay to use the plugin name.

version

Anything will be fine Gradle The selection menu at the bottom right has changed from the default Maven to Gradle. I can make plugins in either case, but it's my hobby.

Difference between Maven and Gradle Both are called dependency resolution tools, which allow you to manage the version of a program created by another person. Maven is set with XML, which is difficult for humans to read, so the author is not good at it. There are many things that Gradle can do.

Spigot Settings image.png Here, we will set the plug-in itself. Plugin Name Set the name of the plugin. Only half-width alphanumeric characters can be used.

Plugin version

Anything will be fine Main Class Name Specify the main class (described later) of the plugin. If you don't know, you can leave the default settings. Minecraft Version Specify the target Minecraft version. The current latest version is 1.13.2, but I still feel that it is unstable, so I will develop it with 1.12.2 here.

Optional Setting The following works without setting, but it is better to set it when distributing or publishing.

Description

Literally a description of the plugin. Only half-width alphanumeric characters can be used. Authors The name of the author. If there are multiple characters, separate them with a single-byte comma ,. WebSite Specify the URL where the plug-in is published. LogPrefox Specify the prefix at the beginning of the log. If empty, the plugin name will be used. Load Before Specify the plug-in name. This plugin will be loaded before the plugin specified here. If you specify more than one, separate them with single-byte commas ,. Depend Specifies the plugin on which this plugin depends. The plugin specified here will be loaded before this plugin. If the plug-in specified here is not installed, an error will occur when starting the server. Soft Depend The main function is the same as Depend. However, the difference is that no error will occur even if the plug-in specified here is not installed. Load at Set when the plugin is loaded. When all the worlds have been read in Post World It is when the server is started in Startup (before reading the world).

Project settings

image.png If you set only the project name, you can leave it as it is.

If you press Finish here, the following screen will appear. image.png

It's OK as it is.

Write code

image.png Please wait, this is the place to write the program from now on. In fact, Minecraft Develop has already written the minimum required code without changing the code. In other words ... ** It already works as a plugin ** (although it's a plugin that doesn't do anything because it doesn't write any features, of course).

Now let's study the basics of Java.

Tutorial.java


package com.github.rona_tombo.tutorial;

This indicates that a class called Tutorial (described later) belongs to a package (a collection of classes) called com.github.rona_tombo.tutorial.

Tutorial.java


import org.bukkit.plugin.java.JavaPlugin;

It is a declaration that we will use the class ʻorg.bukkit.plugin.java.JavaPlugin`. In this way, the package name is used for import etc.

Tutorial.java


public final class Tutorial extends JavaPlugin{
}

This is the class declaration that appeared earlier. A class is a unit of Java's basic functionality. Classes can have members such as methods (discussed below) and fields (discussed below). public can be accessed from anywhere, final is a class that cannot be" inherited "(described later), Tutorial is a name, and extends is a class called JavaPlugin.

Inheritance is the process of creating a class based on a certain class and adding or rewriting functions to the class. (If you explain in detail, it will take up space, so I will take another opportunity)

Tutorial.java



	@Override
	public void onEnable(){
		// Plugin startup logic

	}

	@Override
	public void onDisable(){
		// Plugin shutdown logic
	}

This is in the Tutorial class, isn't it? This is the method. The method is the part that is defined in the class and actually performs the processing. These two methods are defined in JavaPlugin which is the inheritance source of Tutorial class, but the process is rewritten by adding @Override. public means you can use it from anywhere, void means it won't return any results after it's done. () Is attached at the end of each method, but in some cases, information used for processing is passed here as an argument.

So let's actually play with the code here. Change onEnable and onDisable as follows.

Tutorial.java


    @Override
    public void onEnable(){
        // Plugin startup logic
        getLogger().info("The plugin is enabled!");
    }

    @Override
    public void onDisable(){
        // Plugin shutdown logic
        getLogger().info("The plugin is disabled!");
    }

getLogger is a method for logging to the console. Ordinary methods use instance variables that instantiate a class (it's easier to remember that). Instance variable name.method name (argument); However, the methods defined in your class or your parent class can be called by just the method name without instantiation. The return value of the method (the value returned after processing) can be packed in a variable, and further methods can be connected from there. Here, when loading the plug-in, "The plug-in is enabled!" And when disabling it, "The plug-in is disabled!" Is left as a log.

If you can do this, let's actually execute it. For Windows, there is one thing to do here. image.png Double-click build.gradle from the tree on the left to open it. Add the following below the target Compatibility.

build.gradle


tasks.withType(AbstractCompile)*.options*.encoding = tasks.withType(GroovyCompile)*.groovyOptions*.encoding = 'UTF-8'

If you can, click the triangle near the top right of the window. image.png

This will start building the plugin. When the message BUILD SUCCESS FUL is displayed, the build is complete. If you keep the default, you should have a jar file called Pluginname-Version.jar inC: \ Users \ Username \ IDEA Projects \ Projectname \ build \ lib \, so 1.12 Try launching Spigot in the .2 Spigot plugins folder. Also, try stopping the server with / stop. If the log is displayed on the console, it is successful.

Summary

Did you understand the basic knowledge of Java? This time I'm only doing the very simple thing of displaying logs on the console, but from the next time I will respond to commands, when I hit a block, etc. I want to do various things. Until the end Thank you for reading. We look forward to your continued support in this series.

Recommended Posts

How to make Spigot plugin (for Java beginners)
Spigot (Paper) Introduction to how to make a plug-in for 2020 # 01 (Environment construction)
How to make Python faster for beginners [numpy]
[Blender] How to make a Blender plugin
How to make a dialogue system dedicated to beginners
How to use data analysis tools for beginners
How to make a QGIS plugin (package generation)
How to make Substance Painter Python plugin (Introduction)
[For beginners] How to study programming Private memo
How to convert Python # type for Python super beginners: str
[For beginners] How to study Python3 data analysis exam
How to make unit tests Part.2 Class design for tests
Python # How to check type and type for super beginners
How to study Bukkit Plugin
~ Tips for beginners to Python ③ ~
Tips for Python beginners to use the Scikit-image example for themselves 7 How to make a module
[For beginners] How to read Numerai's HP + Submit + Convenient links
[For beginners] How to use for statements on Linux (variables, etc.)
How to implement 100 data science knocks for data science beginners (for windows10 Home)
How to learn TensorFlow for liberal arts and Python beginners
How to make a Python package (written for an intern)
How to convert Python # type for Python super beginners: int, float
For beginners, how to deal with common errors in keras
How to make a Japanese-English translation
[For non-programmers] How to walk Kaggle
How to make a slack bot
How to make a crawler --Advanced
How to make a recursive function
How to make a deadman's switch
[Blender] How to make Blender scripts multilingual
How to make a crawler --Basic
[For beginners] How to implement O'reilly sample code in Google Colab
[For beginners] How to register a library created in Python in PyPI
How to make a unit test Part.1 Design pattern for introduction
[Unity] How to run ML-Agents Release 8 even for transcendental beginners [Windows]
How to study for the Deep Learning Association G test (for beginners) [2020 version]
How to make Word Cloud characters monochromatic
How to make Selenium as light as possible
How to make a model for object detection using YOLO in 3 hours
[Python] How to make a class iterable
How to create * .spec files for pyinstaller.
[Python] Organizing how to use for statements
[Cocos2d-x] How to make Script Binding (Part 2)
How to install Windows Subsystem For Linux
Beginners read "Introduction to TensorFlow 2.0 for Experts"
How to use Pylint for PyQt5 apps
How to make multi-boot USB (Windows 10 compatible)
How to use "deque" for Python data
How to make a Backtrader custom indicator
How to make a Pelican site map
[Cocos2d-x] How to make Script Binding (Part 1)
How to use fingerprint authentication for KDE
Let's make a Backend plugin for Errbot
Memo # 4 for Python beginners to read "Detailed Python Grammar"
The fastest way for beginners to master Python
How to specify the launch browser for JupyterLab 3.0.0
An introduction to object-oriented programming for beginners by beginners
For beginners to build an Anaconda environment. (Memo)
How to make an embedded Linux device driver (8)
How to make an embedded Linux device driver (1)
Python for super beginners Python for super beginners # Easy to get angry