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.
-[] 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.
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.) Press "Plug-in" from "Configuration" of the lower right gear. An input field will appear, so search for "minecraft". 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.
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.
From here, check the Spigot Plugin and press Next.
On this screen, you will configure the build settings.
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.
The artifact ID is the ID that distinguishes the project. Normally, it is okay to use the plugin name.
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 Here, we will set the plug-in itself. Plugin Name Set the name of the plugin. Only half-width alphanumeric characters can be used.
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.
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).
If you set only the project name, you can leave it as it is.
If you press Finish here, the following screen will appear.
It's OK as it is.
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.
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.
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.
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