我正在制作 Minecraft 的插件。
public final static ItemStack WHITE_STAINED_GLASS_PANE = (IS_LEGACY ? new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 0) : new ItemStack(Material.WHITE_STAINED_GLASS_PANE));
我已经适配了版本。但是当我运行插件时,出现错误:
Fatal error trying to convert ***.class
org.bukkit.plugin.AuthorNagException: No legacy enum constant for WHITE_STAINED_GLASS_PANE. Did you forget to define a modern (1.13+) api-version in your plugin.yml?
我的代码可以顺利运行,但我想删除这个错误信息,我应该插入什么代码?
@Elikill58
更新了代码。
我使用 maven 进行编译。
以下是我认为与此问题相关的代码片段:
// the main class snippet
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);
# src/main/resources/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");