You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Minecraft插件适配1.13+版本消除WHITE_STAINED_GLASS_PANE报错咨询

Minecraft插件消除org.bukkit.plugin.AuthorNagException报错方案

我正在开发一款Minecraft插件,已针对1.13前后版本完成WHITE_STAINED_GLASS_PANE的适配代码编写,代码可正常运行,但启动时出现org.bukkit.plugin.AuthorNagException报错,提示未在plugin.yml中定义1.13+的api-version。使用Maven编译,寻求消除该错误的代码修改方案。

相关代码片段

主类代码片段

public static ItemStack createItem(String name, String legacy, short color) {
   return IS_LEGACY ? new ItemStack(Material.valueOf(legacy), 1, color) : new ItemStack(Material.valueOf(name));
}
public final static ItemStack WHITE_STAINED_GLASS_PANE = createItem("WHITE_STAINED_GLASS_PANE", "STAINED_GLASS_PANE", (short) 0);

plugin.yml配置

name: name
author: autext
description: A plugin of Minecraft
main: me.autext.abcde.ABCDE
version: ${project.version}

IS_LEGACY定义

class VersionString {

    private final int major;
    private final int minor;
    private final int patch;

    public VersionString(String version) {
        String[] parts = version.split("\\.");
        this.major = Integer.parseInt(parts[0]);
        this.minor = Integer.parseInt(parts[1]);
        this.patch = parts.length > 2 ? Integer.parseInt(parts[2]) : 0;
    }

    public boolean isLowerThan(String otherVersion) {
        VersionString other = new VersionString(otherVersion);
        if (this.major < other.major) {
            return true;
        }
        if (this.major > other.major) {
            return false;
        }
        if (this.minor < other.minor) {
            return true;
        }
        if (this.minor > other.minor) {
            return false;
        }
        return this.patch < other.patch;
    }
}
private final static Boolean IS_LEGACY = new VersionString(Bukkit.getVersion().replaceAll("[^0-9.]", "")).isLowerThan("1.13");

报错消除方案

1. 核心修改:在plugin.yml中添加api-version字段

报错的直接原因是未声明插件适配的API版本,只需在plugin.yml中添加api-version: 1.13即可消除该异常:

name: name
author: autext
description: A plugin of Minecraft
main: me.autext.abcde.ABCDE
version: ${project.version}
api-version: 1.13

这个字段明确告知Bukkit插件是基于1.13及以上版本的API开发,即使做了向下兼容适配,也需要声明该字段来避免启动时的 nag 提示。

2. 可选优化:修正IS_LEGACY的初始化时机

当前IS_LEGACY作为静态常量在类加载阶段直接调用Bukkit.getVersion(),存在Bukkit API未初始化完成的风险。建议改为在插件启动方法中延迟初始化:

private static Boolean IS_LEGACY;

@Override
public void onEnable() {
    // 初始化版本判断标记
    IS_LEGACY = new VersionString(Bukkit.getVersion().replaceAll("[^0-9.]", "")).isLowerThan("1.13");
    // 其他插件初始化逻辑...
}

这样能确保在Bukkit环境完全准备好后再进行版本检测,避免类加载阶段出现意外错误。

内容的提问来源于stack exchange,提问作者user26978467

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 09:02:27