提醒一下,这个插件本身有效,只是在击中时会出错。
我试图彻底改变在天文学中工作的方式。在我的插件中,当你打开它们时,它们会给你一个项目然后消失,这已经有效但是有一个问题。
我调用PlayerInteractEvent并使用if语句查看块类型是否为胸部,如果是,则会取消该事件,使胸部消失并给玩家一个项目。但是当主类将事件传递给ChestRewards类时,它似乎也传递了命中事件或者从预期的PlayerInteractEvent中进行的冲击动作,但这就是为什么我使用if语句只使用块传递的事件类型是胸部。但是它似乎在控制台中出错而无法通过事件,请帮忙!
@EventHandler
public void catchChestOpen(PlayerInteractEvent event) {
Entity p = event.getPlayer();
Player player = (Player) p;
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.PHYSICAL || event.getAction() == Action.LEFT_CLICK_BLOCK){
// TODO: 2016-12-06 Nothing
}
if (event.getClickedBlock().getType() == Material.CHEST) {
event.getClickedBlock().setType(Material.AIR);
event.setCancelled(true);
int rando = (int) (Math.random() * 10);
//---------------------------------------------------------------------------------
if (rando == 1) {
ItemStack Axe = new ItemStack(Material.DIAMOND_AXE, 1);
ItemMeta meta = Axe.getItemMeta();
List<String> lores = new ArrayList<String>();
lores.add(ChatColor.DARK_PURPLE + "The axe of a long lost survivor");
meta.setDisplayName(ChatColor.DARK_RED + "Survivor Axe");
meta.addEnchant(Enchantment.DAMAGE_ALL, 2, true);
meta.addEnchant(Enchantment.DURABILITY, 2, true);
meta.setLore(lores);
Axe.setItemMeta(meta);
Axe.setDurability((short) 800);
player.getInventory().addItem(Axe);
player.sendMessage(ChatColor.GOLD + "You opened a" + ChatColor.AQUA + " RARE " + ChatColor.GOLD + "loot chest!");
}
//---------------------------------------------------------------------------------
if (rando > 1) {
ItemStack IronSword = new ItemStack(Material.IRON_SWORD, 1);
ItemMeta meta2 = IronSword.getItemMeta();
List<String> lores2 = new ArrayList<String>();
lores2.add(ChatColor.DARK_PURPLE + "A reliable iron sword");
meta2.setDisplayName(ChatColor.DARK_RED + "Reliable Iron Sword");
meta2.addEnchant(Enchantment.DURABILITY, 3, true);
meta2.setLore(lores2);
IronSword.setItemMeta(meta2);
IronSword.setDurability((short) 800);
player.getInventory().addItem(IronSword);
player.sendMessage(ChatColor.GOLD + "You opened a loot chest!");
}
//---------------------------------------------------------------------------------
}
}
这是错误本身
[09:32:00 ERROR]: Could not pass event PlayerInteractEvent to Apocalypse v1.0
答案 0 :(得分:0)
如果public void onListItemClick(ListView l, View v, int position, long id) {
}
不是Action
或RIGHT_CLICK_BLOCK
,您就不会停止执行代码,那么当您致电{LEFT_CLICK_BLOCK
时,event.getClickedBlock()
将为空如果玩家离开或右击空气,则将它与胸部进行比较。
我建议您添加一项检查以查看该操作是否与块有关。下面的代码片段将检查播放器是左侧还是右侧点击胸部:
block.getType()