I want to make a plug-in for Minecraft. But I don't want to use Eclipse, for those who want to use VS Code Spigot MC official wiki Is a rough Japanese translation. Please note that there are some translations and changes to work the parts that did not work in my environment [^ 1].
Create a workspace with VS Coede and configure it. You can change the settings from the window menu or by editing default.code-workspace.
files.autoGuestEncoding: Check the check box. [^ 2]
files.encoding: Specify utf8.
java.home: Specify the absolute path of OpenJDK.
java.jdt.ls.vmargs: Set additional Java VM arguments to start the Java Language Server. Set to "-Dfile.encoding = UTF-8". [^ 2]
javac-linter.javac: Sets the executable javac. Specify "-Dfile.encoding = UTF-8" as an argument of javac. [^ 2]
In the end, "default.code-workspace" should look like the one below.
{ "folders": [ { "path": "." } ], "settings": { "files.autoGuessEncoding": true, "files.encoding": "utf8", "java.home": "C:\openjdk-1.8.0", "java.jdt.ls.vmargs": "-Dfile.encoding=UTF-8", "javac-linter.javac": "javac -Dfile.encoding=UTF-8" } }
## Creating an empty plugin
Right-click on the workspace directory and click "Generate from Maven Archetype".
Click "maven-archetype-quickstart" from the menu that appears at the top of the VS Code window. [^ 3]
If the version selection screen appears, select the latest version (2.0).
Explorer opens, so select a workspace.
The terminal will ask you for some project settings.
**groupId**:
Enter the package name
**artifactId**:
Enter the name of the plugin without the version number
**version**:
Enter the version number of the plugin. If you press Enter without entering anything, it will be "1.0-SNAPSHOT".
**package**:
It is recommended to just press Enter to use the default. The default is groupId.
After that, Maven will ask you to confirm the settings of the Maven project.
If it is correct, press Y or Enter to confirm.
When the sentence "BUILD SUCCESS" appears in the terminal, open pom.xml from the plugin directory and edit it as follows.
** Note: The following is the case when the groupId is set to “dev.cibmc.spigot.blankplugin” **
>```
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev.cibmc.spigot.blankplugin</groupId>
<artifactId>BlankPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>plugin.yml</include>
</includes>
</resource>
</resources>
</build>
</project>
Of course, you can change the version of the Spigot API.
Create a resources directory in [projectBaseDir] / src / main and create plugin.yml in it. Below is an example of plugin.yml.
main: dev.cibmc.spigot.blankplugin.App name: BlankPlugin version: 0.1
---
This is a part not in the original article
However, in my environment [^ 1], the contents of versin had to be enclosed in double quotes, and the items api and api-version were needed.
api specifies the Minecraft version (eg 1.16.2) and api-version specifies the Spigot API version (eg 1.16).
Therefore, it operates normally by doing the following. (For version 1.16.2)
>```
main: dev.cibmc.spigot.blankplugin.App
name: BlankPlugin
version: "0.1"
api: 1.16.2
api-version: 1.16
At this point, your workspace's directory tree should look like this: BlankPlugin ┣ src ┃ ┣ main ┃ ┃ ┣ java ┃ ┃ ┃ ┗ dev ┃ ┃ ┃ ┗ cibmc ┃ ┃ ┃ ┗ spigot ┃ ┃ ┃ ┗ blankplugin ┃ ┃ ┃ ┗ App.java ┃ ┃ ┗ resources ┃ ┃ ┗ plugin.yml ┃ ┗ test ┣ target ┗ pom.xml
Right-click on "Brank Plugin" from the MAVEN panel and select "install" from the menu. Confirm that "BUILD SUCCESS" is displayed in the terminal.
** Note: The groupId provided as an example, "dev.cibmc.spigot.blankplugin", should be changed to your own groupId when you create a plugin. ** **
** Note 2: If you don't want to use APP in the name of the main class, rename the file, rename the class and change the definition of main in plugin.yml. ** **
Open the App.java file in the directory created in the previous chapter. (Or if you renamed the file, that file) Below is an example code.
package dev.cibmc.spigot.blankplugin; import org.bukkit.plugin.java.JavaPlugin; public class App extends JavaPlugin { @Override public void onEnable() { getLogger().info("Hello, SpigotMC!"); } @Override public void onDisable() { getLogger().info("See you again, SpigotMC!"); } }
When "Classpath is incomplete. Only syntax errors will be reported." Appears in the lower right corner of VS Code, right-click "BrankPlugin" from the MAVEN panel and select "custom goals ..." from the menu.
Then type "eclipse: eclipse" in the input field at the top of the VS Code window and press Enter.
Finally, right-click on "Brank Plugin" from the MAVEN panel and select "install" again.
If the build is successful, the Spigot plugin will be generated in the target directory.
## Run blank plugin
Copy the created plugin to the plugin directory and start the server.
Then, the server log as below is displayed.
>```
[HH:MM:SS] [Server thread/INFO]: [BlankPlugin] Enabling BlankPlugin v1.0-SNAPSHOT
[HH:MM:SS] [Server thread/INFO]: [BlankPlugin] Hello, SpigotMC!
When I run the stop command on the console, I see a log like the one below.
[HH:MM:SS] [Server thread/INFO]: [BlankPlugin] Disabling BlankPlugin v1.0-SNAPSHOT [HH:MM:SS] [Server thread/INFO]: [BlankPlugin] See you again, SpigotMC!
# References
Spigot MC official wiki (https://www.spigotmc.org/wiki/creating-a-blank-spigot-plugin-in-vs-code/)
[^ 1]: windows10, Minecraft ver1.16.x
[^ 2]: In my case, it worked well even if I didn't put it on.
[^ 3]: There may be jdk-8 etc. behind, but you don't have to worry about it.
Recommended Posts