Java 在项目上单击两次,而不是单击一次
我得到了一个gui,当我点击MaterialCoal时,我需要再次点击它来激活代码。 这是我的清单ClickEventJava 在项目上单击两次,而不是单击一次,java,bukkit,Java,Bukkit,我得到了一个gui,当我点击MaterialCoal时,我需要再次点击它来激活代码。 这是我的清单ClickEvent String stripname = ChatColor.stripColor(e.getClickedInventory().getName()); if(stripname.equals("Upgrade Spawner".toUpperCase())) { if(e.getCursor()!=null) {
String stripname = ChatColor.stripColor(e.getClickedInventory().getName());
if(stripname.equals("Upgrade Spawner".toUpperCase()))
{
if(e.getCursor()!=null)
{
if(e.getCursor().getType()!=null)
{
Material item = e.getCursor().getType();
if(item.equals(Material.STAINED_GLASS_PANE)) e.setCursor(null);
else if(item.equals(Material.COAL))
{
if(checkBalance(e.getWhoClicked(), config.getInt("Coal Cost")))
{
takeAwayMoney(e.getWhoClicked(), config.getInt("Coal Cost"));
e.getWhoClicked().closeInventory();
e.getWhoClicked().sendMessage(ChatColor.GREEN + "Iron Golems now drop coal!");
} else
{
e.getWhoClicked().closeInventory();
e.getWhoClicked().sendMessage(ChatColor.RED + "You do not have the requirment amount of money! You need " + getMoneyNeeded(e.getWhoClicked(), config.getInt("Coal Cost")) + " more!");
}
}
}
}
}
因为
getCursor
返回播放器在光标中保存的项目,并且您正在检查该项目是否为空-所以第一次单击将该项目移动到光标,然后下一次单击光标将不为空,代码将执行。改用
getCurrentItem
。您是否已使用IDE调试器逐步完成了代码?您发现了什么?什么是IDE调试器?调试器是一次运行一行代码以查看失败或值更改的地方;它可以帮助你知道哪里可能出了问题。你用什么软件来编写代码?我用的是Eclipse