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 ***
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.
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.
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
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
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).
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
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.
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.
If the installation is successful, the following screen will appear.
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.
We will create a Maven project. Select menu bar-> File-> New-> Other or Ctrl + N to display the new creation screen.
Since there is Maven Project in Maven, select it and click Next.
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.
** 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.
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.)
Since there is a description of both Spigot API and Bukkit API, only the Spigot API part is used.
When you update pom.xml, the package file will be automatically downloaded in Maven Dependency.
First, create a package. Right-click src / main / java in Package Explorer-> New-> Package. For ** name **, enter the same Group Id you entered earlier.
Next, we will create the main class. Right-click on net.ttk1 in Package Explorer-> New-> Class. Create a Test class.
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!");
}
}
}
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.
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.
The following screen is displayed.
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.
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.
*** Welcome to my world! *** is displayed!
Was it a little difficult this time?
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. ** **
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