我的世界插件开发【IDEA自动热重载】

最近,在研究我的世界插件开发,遇到的最大问题就是构建完成之后需要手动重载插件很是麻烦,所以就利用Maven插件和自己写的一个我的世界插件进行自动重载。

利用Maven的exec-maven-plugin和maven-jar-plugin执行命令和自定义jar包输出路径。

pom.xml

  <build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.2.0</version>
            <executions>
                <execution>
                    <id>unload</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>Script</mainClass>
                        <arguments>
                            <argument>8888</argument>
                            <argument>unload</argument>
                            <argument>PluginName</argument>
                        </arguments>
                    </configuration>
                </execution>
                <execution>
                    <id>load</id>
                    <phase>package</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>Script</mainClass>
                        <arguments>
                            <argument>8888</argument>
                            <argument>load</argument>
                            <argument>PluginName</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
                <!-- jar包输出路径 -->
                <outputDirectory>F:\Game\Minecraft\plugins</outputDirectory>
                <excludes>
                    <exclude>**/*.properties</exclude>
                    <exclude>**/*.xml</exclude>
                    <exclude>static/**</exclude>
                    <exclude>templates/**</exclude>
                    <exclude>**/Script.class</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

Script.java

import java.io.IOException;
import java.net.Socket;

public class Script {
    public static void main(String[] args) {
        try (Socket socket = new Socket("localhost", Integer.parseInt(args[0]))) {
            socket.getOutputStream().write(("develop " + args[1] + " " + args[2]).getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

重载插件

GitHub项目:Develop

也可以使用 Plugman 改一下 Script.java。

posted @ 2024-02-29 22:08  liert  阅读(206)  评论(0)    收藏  举报