[JAVA] Write Spigot in VS Code

Write Spigot in VS Code

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].

Prerequisites

  1. VSCode has java Extension pack installed.
  2. OpenJDK is included. (The java Extension pack requires OpenJDK.)
  3. You also need Apache Maven.
  4. Have a basic knowledge of java.
  5. Be able to have a unique name, such as the plugin's groupID, an internet domain that can be used for the package, or part of an email address.

Workspace preparation

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. ** **

Create blank plugin

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

Write Spigot in VS Code
Write standard input in code
Write selenium test code in python
Write python-like code
VS Code settings
(For myself) Put Flask in VS Code
Pass PYTHONPATH in 1 minute with VS Code
Use Python in Anaconda environment with VS Code
Write Python-like code (dictionary)
Write Pulumi in Go
Write DCGAN in Keras
Write decorator in class
Write Python in MySQL
I want to write in Python! (1) Code format check
Add auto-completion to EV3 Micropyhon programming in VS Code
Allow real-time code checking in Python development with VS Code
VS Code settings for developing in Python with completion
VS Code says there is an error in cv2
Revive symbol search in Python workspace with VS Code
Expose settings.json for efficient Python coding in VS Code
Clearly write code that increases conditional branching in multiplication
Python with VS Code (Windows 10)
Write Pandoc filters in Python
Write beta distribution in Python
Write python in Rstudio (reticulate)
How to use VS Code in venv environment on windows
Write data in HDF format
Set VS Code to PyCharm.
Debug Python with VS Code
Generate QR code in Python
Write Spider tests in Scrapy
UpNext2 Development Record # 1 Build Python CI environment in VS Code
I want to be able to run Python in VS Code
Character code learned in Python
Create a Python environment for professionals in VS Code on Windows
Comfortable shortcut operations such as Ctrl + P in VS Code terminal
I wrote the code to write the code of Brainf * ck in python
Debug settings in virtual environment when using Pipenv with VS Code
Write a binary search in Python
Write a table-driven test in C
Write & compile & run code at codeanywhere.com
[Python] Generate QR code in memory
Write JSON Schema in Python DSL
How to write soberly in pandas
Automatically format Python code in Vim
Write an HTTP / 2 server in Python
Write AWS Lambda function in Python
VS Code snippets for data analysts
Write A * (A-star) algorithm in Python
[Maya] Write custom nodes in Open Maya 2.0
[Note] VS Code cv2 intellisense error
Resolve VS Code unresolved import error
Write foreign key constraints in Django
Write a pie chart in Python
Write a vim plugin in Python
Try running Jupyter with VS Code
Write a depth-first search in Python
Python unittest module execution in vs2017
To maintain code quality in PyCharm
Code: 2 "Hello World" in "Choregraphe-Python script"
Install VS Code on your Chromebook