gpt4 book ai didi

Java "TRAP"断言错误

转载 作者:行者123 更新时间:2023-11-30 06:59:13 24 4
gpt4 key购买 nike

我正在为 Spigot 编写一个类,它定义了许多新的制作配方。然而,当我调用一个事件时,它有时会抛出一个断言错误:TRAP。我进行了很多研究,但没有发现任何有用的提示或任何东西。

项目.java

package com.myththewolf.omnomnom.lib;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.SkullType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;

public class Items {
private static HashMap<ItemStack,Integer> items = new HashMap<ItemStack,Integer>();
private static List<ShapedRecipe> itemC = new ArrayList<ShapedRecipe>();
public ItemStack setMeta(ItemStack material, String name, List<String> lore)
{
if (((material == null) || material.getType() == Material.AIR) || ((name == null && lore == null)))
{
return null;
}
ItemMeta im = material.getItemMeta();
if (name != null)
{
im.setDisplayName(name);
}
if (lore != null)
{
im.setLore(lore);
}
material.setItemMeta(im);
return material;
}

public static void makeRecipies()
{

ItemStack skull;
skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
SkullMeta SM;
SM = (SkullMeta) skull.getItemMeta();
SM.setOwner("MHF_CHEST");
skull.setItemMeta(SM);
addRecipie(3, "CCC", "BAB", "CCC", skull, Material.COOKED_BEEF, Material.BREAD, Material.AIR);
for(ShapedRecipe sr : itemC)
{
Bukkit.getServer().addRecipe(sr);
}
}

public static HashMap<ItemStack,Integer> getItems()
{
return items;
}

public static void addRecipie(int hung,String patA, String patB, String patC, ItemStack out, Material a, Material b, Material c)
{
ShapedRecipe rec = new ShapedRecipe(out);
rec.shape(patA,patB,patC);
rec.setIngredient('A', a);
rec.setIngredient('B', b);
rec.setIngredient('C', c);
items.put(out, hung);
itemC.add(rec);
}
}

RightClickEvent.java

package com.myththewolf.omnomnom.event;

import java.util.HashMap;

import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import com.myththewolf.omnomnom.lib.Items;

public class RightClickEvent implements Listener {
@EventHandler

public void onInteractEvent(PlayerInteractEvent e)
{
Action a= e.getAction();


if(a == Action.RIGHT_CLICK_BLOCK || a== Action.RIGHT_CLICK_AIR)
{

final HashMap<ItemStack,Integer> items = Items.getItems();
if(items.containsKey(e.getItem()))
{
int foodL = e.getPlayer().getFoodLevel();

e.getPlayer().setFoodLevel(foodL + items.get(e.getItem()));
ItemStack hand = e.getPlayer().getItemInHand();
int amount = hand.getAmount();
if (amount > 1) {
hand.setAmount(amount - 1);
e.getPlayer().setItemInHand(hand);
} else {
e.getPlayer().setItemInHand(new ItemStack(Material.AIR));
}
}
}
}
}

这是堆栈跟踪:

[22:50:18 FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.AssertionError: TRAP
at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_101]
at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_101]
at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:47) [spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:739) [spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:675) [spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:574) [spigot.jar:git-Spigot-f950f8e-4f47972]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]
Caused by: java.lang.AssertionError: TRAP
at net.minecraft.server.v1_11_R1.ItemStack.F(ItemStack.java:86) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.ItemStack.setCount(ItemStack.java:814) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.ItemStack.add(ItemStack.java:818) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.ItemStack.subtract(ItemStack.java:822) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.ItemSkull.a(ItemSkull.java:79) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.ItemStack.placeItem(ItemStack.java:152) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.PlayerInteractManager.a(PlayerInteractManager.java:491) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:897) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:37) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:1) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_101]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_101]
at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
... 5 more

这个错误到底是什么?

我做错了什么吗?

最佳答案

看起来您允许将要放置的方 block 替换为玩家手中的空气。在 Minecraft 中不可能放置空气,因此会抛出 AssertionError

解决方案是取消 PlayerInteractEvent

关于Java "TRAP"断言错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41235190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com