为什么我的recpie会显示此错误?

时间:2018-02-01 15:20:54

标签: java minecraft bukkit

我曾尝试为我的朋友开发Minecraft插件,所以我一直试图尝试项目配方示例,但是当我重新加载时,这个错误出现在我的控制台上:

[17:10:41 ERROR]: Error occurred while enabling test vbeta0.1 (Is it up to date?)
java.lang.IllegalArgumentException: Symbol does not appear in the shape:87
        at org.apache.commons.lang.Validate.isTrue(Validate.java:93) ~[spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.inventory.ShapedRecipe.setIngredient(ShapedRecipe.java:121) ~[spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.inventory.ShapedRecipe.setIngredient(ShapedRecipe.java:107) ~[spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at codemineman.test.minecraft.CustomRecpie.customItem(CustomRecpie.java:18) ~[?:?]
        at codemineman.test.minecraft.Main.onEnable(Main.java:14) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.reload(CraftServer.java:752) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.Bukkit.reload(Bukkit.java:525) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:648) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchServerCommand(CraftServer.java:634) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at net.minecraft.server.v1_12_R1.DedicatedServer.aP(DedicatedServer.java:444) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:407) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot1.12.jar:git-Spigot-4bd94dc-015bda4]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_161]

CustomRecpies.java:

package codemineman.test.minecraft;

import java.util.ArrayList;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;

public class CustomRecpie implements Listener {
    public ItemStack item = new ItemStack(Material.ANVIL,3);
    public ItemMeta meta;
    private Plugin plugin = Main.getPlugin(Main.class);

    @SuppressWarnings("deprecation")
    public void customItem() {
        ItemStack item = new ItemStack(Material.DIAMOND_AXE, 1);
        ItemMeta meta = item.getItemMeta();

        meta.setDisplayName(ChatColor.AQUA + "AXE OF ZEUS");
        ArrayList<String> lore = new ArrayList<String>();
        lore.add(ChatColor.WHITE + "Used by Zeus in the great god battle");
        meta.setLore(lore);
        meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
        item.setItemMeta(meta);
        ShapedRecipe r = new ShapedRecipe(item);

        r.shape("#% ", "#$ ", " $ ");
        r.setIngredient('#', Material.DIAMOND);
        r.setIngredient('%', Material.IRON_INGOT);
        r.setIngredient('$', Material.STICK);

        plugin.getServer().addRecipe(r);   
    }
}

Main.java:

package codemineman.test.minecraft;

import org.bukkit.plugin.java.JavaPlugin;

import net.md_5.bungee.api.ChatColor;

public class Main extends JavaPlugin{

    public void onEnable() {
        getServer().getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "\n\nTest plugin have been enabled.\n\n");
        getServer().getPluginManager().registerEvents(new EventsClass(), this);

        CustomRecpie items = new CustomRecpie();
        items.customItem();
    }

    public void onDisable() {
       getServer().getConsoleSender().sendMessage(ChatColor.DARK_RED + "\n\nTest plugin have been disabled.\n\n");
    }
}

我真的找不到出错的原因,我在我的家用电脑上托管我的测试服务器,在控制台错误地说:&#34;它是Up到目前为止?&#34;我想我可能使用了较旧的外部插口jar文件,我不确定。

2 个答案:

答案 0 :(得分:0)

在看了一下代码之后,我发现了问题:

private Plugin plugin = Main.getPlugin(Main.class); 

recpie代码没有任何问题我发现这样做,制作一个新的插件使插件崩溃。无论如何,谢谢你的帮助。

答案 1 :(得分:0)

private Plugin plugin = Main.getPlugin(Main.class);

这不是你获得插件实例的方式。 (我想这就是你想要的)

请阅读this。它将帮助您理解Java对象和类。

解决方案非常简单。在Main课程中执行此操作:

private static Main instance;
public static Main getInstance() {
    return instance;
}
@Override
public void onLoad() {
    instance = this;
}

如果你想获得JavaPlugin个实例,只需执行Main.getInstance()即可。很简单。