[GO] Build a Minecraft plugin development environment in Eclipse

Introduction

I posted Article on building Minecraft multi-server environment on VPS more than a year ago. This time it's a sequel to it.

I had the opportunity to study Java because of my work, so I decided to make a Minecraft plug-in. Actually, I had the opportunity to go to Java Day Tokyo a few months ago, and I bought a book like this there.

"Set up a multi-server with Minecraft! (Think IT Books)"

This book was made into a book by Think IT serialization by ecolight. This book introduces how to use NetBeans as a plugin development environment. The explanation is easy to understand and recommended.

In this article, I will leave it as a memorandum of plug-in development environment maintenance using Eclipse that I usually use. ** In my first year as an engineer, the development was only for amateurs to grow hair, so please let me know what is wrong. ** **

*** We are looking for people to co-develop plugins ***

Overview

First, as a continuation of the last time, I will introduce how to introduce the server mod "Spigot". Next, make the initial settings for plug-in development using Eclipse and Maven. Finally, let's build the test plugin and run it on the server.

Introduction of Spigot

Let's start with the assumption that the vanilla server (official server) is already running. For information on how to install a vanilla server, please refer to Article I wrote last time (However, since I wrote it more than a year ago, the information is available. It may be out of date). I think this is a familiar task for those who have used server mods, so please skip it as appropriate.

git installation

The executable file of spigot, which is a server mod, has not been released due to problems such as licensing (I don't know the details). Instead, it takes the form of generating an executable file from the source code that the user has published. A tool "BuildTools" for generating an executable file is also available.

First, install the tool "git" to download the source code.

[root@host-150-95-181-84 ~]# yum install git -y

Download Buildtools

You can download BuildTools from here (https://hub.spigotmc.org/jenkins/job/BuildTools/). The download URL for the latest version is [https://hub.spigotmc.org/jenkins/job/BuildTools/lastStableBuild/artifact/target/BuildTools.jar](https://hub.spigotmc.org/jenkins/job/BuildTools/ lastStableBuild / artifact / target / BuildTools.jar).

[root@host-150-95-181-84 ~]# wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastStableBuild/artifact/target/BuildTools.jar

Run build

Use Buildtools to generate the server executable. Running Buildtools will generate multiple files, so you may want to do it in a separate folder.

[root@host-150-95-181-84 ~]# mkdir buildtools
[root@host-150-95-181-84 ~]# mv BuildTools.jar buildtools/
[root@host-150-95-181-84 ~]# cd buildtools/
[root@host-150-95-181-84 buildtools]#

The command to run Buildtools can be found on this page (https://www.spigotmc.org/wiki/buildtools/). If you specify the version,

java -jar BuildTools.jar --rev 1.12.1

To do. If you want to get the latest version

java -jar BuildTools.jar --rev latest

To do. I don't care about the version this time, so I will use the latest version. When you execute the command, the source code is automatically downloaded and built, and the server executable file is generated.

[root@host-150-95-181-84 buildtools]# java -jar BuildTools.jar --rev latest
~~Omitted (it takes a lot of time)~~
Success! Everything compiled successfully. Copying final .jar files now.
Copying craftbukkit-1.12.2-R0.1-SNAPSHOT.jar to /root/buildtools/.
  - Saved as craftbukkit-1.12.2.jar
Copying spigot-1.12.2-R0.1-SNAPSHOT.jar to /root/buildtools/.
  - Saved as spigot-1.12.2.jar
[root@host-150-95-181-84 buildtools]# ls
apache-maven-3.5.0  BuildTools.log.txt  craftbukkit-1.12.2.jar  work
BuildData           Bukkit              Spigot
BuildTools.jar      CraftBukkit         spigot-1.12.2.jar
[root@host-150-95-181-84 buildtools]#

If the executable file spigot-1.12.2.jar is generated, the build is successful (currently the latest version is 1.12.2).

Launch Spigot

Copy the Spigot executable file to the server directory and start it. This area is the same as the vanilla server.

[root@host-150-95-181-84 buildtools]# cd ..
[root@host-150-95-181-84 ~]# mkdir server
[root@host-150-95-181-84 ~]# cp buildtools/spigot-1.12.2.jar server/
[root@host-150-95-181-84 ~]# cd server/
[root@host-150-95-181-84 server]java -jar spigot-1.12.2.jar nogui
Loading libraries, please wait...
[01:53:34 INFO]: Starting minecraft server version 1.12.2
[01:53:34 WARN]: To start the server with more ram, launch it as "java -Xmx1024M -Xms1024M -jar minecraft_server.jar"
[01:53:34 INFO]: Loading properties
[01:53:34 WARN]: server.properties does not exist
[01:53:34 INFO]: Generating new properties file
[01:53:34 WARN]: Failed to load eula.txt
[01:53:34 INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
[01:53:34 INFO]: Stopping server

As with the vanilla server, you need to make changes to eula.txt.

#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
#Mon Sep 25 01:53:34 JST 2017
eula=true

Run Spigot again. You should be able to start it this time.

[root@host-150-95-181-84 server]# java -Xmx512M -Xms512M -jar spigot-1.12.2.jar nogui

Once started, unlike the vanilla server, a folder called plugins is created. From the next time onward, if there is a plug-in file in this folder at startup, it will be read.

[root@host-150-95-181-84 server]# ls
banned-ips.json      commands.yml  logs             plugins            spigot.yml      world
banned-players.json  eula.txt      ops.json         server.properties  usercache.json  world_nether
bukkit.yml           help.yml      permissions.yml  spigot-1.12.2.jar  whitelist.json  world_the_end

Plugin development environment construction

Eclipse installation

The installation installer is available here (https://eclipse.org/home/index.php). In the Windows version, the following screen will appear when you start it. image.png

This time I will use Maven, so you should select the top. (I have never used anything else) You'll see a screen where you can decide where to put your workspace, but if you don't mind, you can leave the defaults. Please change as appropriate when linking with Git.

Creating a Maven project

If the installation is successful, the following screen will appear. image.png

First, change the default text encoding to UTF-8. Select Menu Bar-> Window-> Preferences, change the Text file encoding of General-> Workspace on the settings screen to UTF-8, and click Apply and Close.

image.png

We will create a Maven project. Select menu bar-> File-> New-> Other or Ctrl + N to display the new creation screen.

image.png

Since there is Maven Project in Maven, select it and click Next.

image.png

Check ** Create a simple project **. If you leave it unchecked, you can use the project template called archetype, but this time I will not use it. Click Next to display the next screen.

image.png

** Group Id ** is a name that uniquely identifies the project. It seems that it is common to use the root package name. In order to avoid duplication with other Ids, it seems better to use the original domain in reverse order. (In my case, I have ttk1.net, so I use net.ttk1.) If you don't publish it, you don't have to worry about duplication.

** Artifact Id ** is the name of the generated executable file. This time it will be test_plugin. By default, ** Version ** is 0.0.1-SNAPSHOT and ** Packaging ** is jar, so the generated file will be "test_plugin-0.0.1-SNAPSHOT.jar". Leave the default this time.

Click Finish to generate an empty project.

Description of pom.xml

You need to download the package file to use the Spigot API. In Maven project, it will be downloaded automatically by describing the necessary package file information in the pom.xml file. The description for the Spigot API can be found here [https://www.spigotmc.org/wiki/spigot-maven/). Copy the part surrounded by the red line in the image below. However, ** version ** must be the same as the Spigot server. (This time it is 1.12.2-R0.1-SNAPSHOT, so copy it as it is.)

image.png

Since there is a description of both Spigot API and Bukkit API, only the Spigot API part is used.

image.png

When you update pom.xml, the package file will be automatically downloaded in Maven Dependency.

Creating a main class

First, create a package. Right-click src / main / java in Package Explorer-> New-> Package. For ** name **, enter the same Group Id you entered earlier.

image.png

Next, we will create the main class. Right-click on net.ttk1 in Package Explorer-> New-> Class. Create a Test class.

image.png

As a test, create a class that displays the message "Welcome to my world!" When you log in. This time, I will omit the explanation of the program contents, but the description of Test.java is as follows.

package net.ttk1;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class Test extends JavaPlugin {
    @Override
    public void onEnable() {
    	//Login message display settings
    	getServer().getPluginManager().registerEvents(new LoginMsg(), this);
    	//Log output at start
        getLogger().info("test enable");
    }

    @Override
    public void onDisable() {
    	//Log output when stopped
        getLogger().info("test disable");
    }
    
    class LoginMsg implements Listener {
    	@EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
        	event.getPlayer().sendMessage("Welcome to my world!");
        }
    }
}

Description of plugin.yml

plugin.yml is the file that the Spigot server needs to load the plugin. You can read more about it here [https://bukkit.gamepedia.com/Plugin_YAML). It seems that three items, ** name **, ** version **, and ** main **, are required. name is the name that identifies the plugin and is also used as the directory name on the server where the plugin's data is stored. version is the version of the plugin. Let's also include the version of the Maven project. For main, enter the fully qualified name of the main class (Test class this time).

name: test_plugin
version: 0.0.1
main: net.ttk1.Test

Create plugin.yml in "src / main / resources". Right-click src / main / resources in Package Explorer-> New-> File.

image.png image.png

Build and run test plugin

Let's build the project. Select Menu Bar-> Run-> Run Configurations and the following screen will be displayed. Right-click "Maven Build" and select New.

image.png

The following screen is displayed.

image.png

When you click the workspace surrounded by the red line, the project selection screen will appear, so select "test_plugin". Then, the character string is entered in ** Base directory **.

For ** Goals **, enter "package".

*** If you do not specify the JDK, the build will fail. Content is being revised ***

Click Run to start the build. If the following message is displayed, the build is successful.

image.png

WARNING is displayed, but this is in <project> ~ </ project> of pom.xml

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

It disappears when you add.

Upload the resulting plugin to your server's plugins folder. The plugin is stored in the location shown on the Building jar: line.

You can save the upload to Dropbox or Google Drive and wget the shared link from the server, but the scp command is the quickest way.

$ scp C:/Users/tama/eclipse-workspace/test_plugin/target/test_plugin-0.0.1-SNAPSHOT.jar [email protected]:./server/plugins
[email protected]'s password:
test_plugin-0.0.1-SNAPSHOT.jar                100% 3245   299.0KB/s   00:00

Let's start the Spigot server.

[root@150-95-181-84 server]#java -Xmx512M -Xms512M -jar spigot-1.12.2.jar nogui
Loading libraries, please wait...
[03:44:26 INFO]: Starting minecraft server version 1.12.2
~~Omission~~
[03:44:27 INFO]: [test_plugin] Loading test_plugin v0.0.1
~~Omission~~
[03:44:31 INFO]: [test_plugin] Enabling test_plugin v0.0.1
[03:44:31 INFO]: [test_plugin] test enable
[03:44:31 INFO]: Server permissions file permissions.yml is empty, ignoring it
[03:44:31 INFO]: Done (4.552s)! For help, type "help" or "?"
>

The plugin seems to load without any problems. Let's connect from the Minecraft client.

image.png

*** Welcome to my world! *** is displayed!

Was it a little difficult this time?

Summary

I built a plug-in development environment using Eclipse and Maven. This time it wasn't the purpose of making a plugin, so I made a simple plugin, but the Spigot API has more features. Let's make a convenient plug-in and liven up Minecraft.

** There may be incorrect information, inappropriate expressions, and typographical errors due to the momentum. Please point out those who have noticed. ** **

reference

From installation to project creation, a convenient development environment called Eclipse + Maven Set up a multi-server with Minecraft! (Think IT Books) Series: Let's set up a multi-server with Minecraft! Basics of plug-in development

Recommended Posts

Build a Minecraft plugin development environment in Eclipse
Build a Python development environment in Eclipse (add HTML editor)
Easily build a development environment with Laragon
Build a LAMP environment in a very short time
Build a C language development environment with a container
[Python] Build a Django development environment with Docker
Build a Django environment with Vagrant in 5 minutes
Build a Django development environment with Doker Toolbox
Build a Kubernetes environment for development on Ubuntu
Development environment in Python
Build a mruby development environment for ESP32 (Linux)
Build a Python development environment on Raspberry Pi
Flutter in Docker-How to build and use a Flutter development environment inside a Docker container
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build a Django development environment using pyenv-virtualenv on Mac
Build a local development environment for Laravel6.X on Mac
Build a GVim-based Python development environment on Windows 10 (1) Installation
I want to easily build a model-based development environment
Build a Python development environment on Mac OS X
Build a machine learning application development environment with Python
How to build a development environment for TensorFlow (1.0.0) (Mac)
Build a Python development environment using pyenv on MacOS
Build a development environment with Poetry Django Docker Pycharm
Build a lightweight Fast API development environment using Docker
Collaborate in a remote environment
Build a LAMP environment [CentOS 7]
[ev3dev × Python] Build ev3dev development environment
Build a machine learning environment
Build a Python environment offline
Build Azure Pipelies with Azure DevOps in a Linux self-hosted environment
[Memo] Build a development environment for Django + Nuxt.js with Docker
Build a Go development environment with VS Code's Remote Containers
Building a development environment for Android apps-creating Android apps in Python
[Django] Build a Django container (Docker) development environment quickly with PyCharm
Build a GVim-based Python development environment on Windows 10 (2) Basic settings
Build a comfortable development environment with VSCode x Remote Development x Pipenv
How to build a python2.7 series development environment with Vagrant
Build a Flask development environment at low cost using Docker
UpNext2 Development Record # 1 Build Python CI environment in VS Code
Run eclipse in Docker environment (noVNC)
Build a go environment using Docker
Write a vim plugin in Python
Build a python3 environment on CentOS7
Build a Selenium environment on Amazon Linux 2 in the shortest time
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
Install Django in a pipenv virtual environment
Method to build Python environment in Xcode 6
How to build a sphinx translation environment
Build a python environment on MacOS (Catallina)
Build a Tensorflow environment with Raspberry Pi [2020]
Build a Fast API environment with docker-compose
Build a development environment using Jupyter and Flask with Python in Docker (supports both VS Code / code-server)
Build WordPress on CentOS 8 in LAMP environment
[Linux] Build a jenkins environment with Docker
Write a simple Vim Plugin in Python 3
Build a python virtual environment with pyenv
Build Python development environment (pythonz, virtualenv, direnv)
Build a Python + OpenCV environment on Cloud9
I tried to build a Mac Python development environment with pythonz + direnv
Creating a virtual environment in an Anaconda environment
Install CaboCha in a non-Anaconda environment (Win)