Ir para conteúdo
  • 0

[Resolvido] Pegar Item Que Foi Clicado No GUI !


LuizB

Pergunta

Como faço pra pegar o item Clicado No gui Eu Uso Assim:

 

if (e.getCurrentItem().getType() == Material.EMERALD_BLOCK) {
			}else {
				return;
			}

Só que diz que da erro no If no console


 

org.bukkit.event.EventException
	at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
	at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
	at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-db6de12-18fbb24]
	at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-db6de12-18fbb24]
	at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1630) [spigot.jar:git-Spigot-db6de12-18fbb24]
	at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:31) [spigot.jar:git-Spigot-db6de12-18fbb24]
	at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:9) [spigot.jar:git-Spigot-db6de12-18fbb24]
	at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_91]
	at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_91]
	at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
	at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
	at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
	at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
	at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
Caused by: java.lang.NullPointerException
	at me.cuthmf.pretender.VPFrame.menuvipantclic(VPFrame.java:47) ~[?:?]
	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_91]
	at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
	... 15 more

O linha 47 é onde ta o if 

Link para o comentário
Compartilhar em outros sites

6 respostass a esta questão

Posts Recomendados

Usa esse maneira eu acho muito melhor.

@EventHandler
public void onClick(InventoryClickEvent e){
Player p = (Player) e.getWhoClicked();
if(e.getInventory().getName().equals(<nome do inv>)){
e.setCancelled(true);
if(e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR){
return;
}
switch(e.getCurrentItem().getType()){
case <material>:
<cod>
break;
case <material>:
<cod>
break;
default:
break;
}
}
Editado por jetta
Link para o comentário
Compartilhar em outros sites

Tenta assim meu jovem 

	@EventHandler
	void clicar(InventoryClickEvent e) {
		if ((e.getInventory().getTitle().equalsIgnoreCase("§cNome do inventario")) && (e.getCurrentItem() != null)) {
			if (e.getCurrentItem().getType() == Material.APPLE) {
				//Caso queira cancelar quando ele click na apple
				e.setCancelled(true);
				//CODIGO
				return;
			}
		}
	}
Link para o comentário
Compartilhar em outros sites

Se tu não clicar em nenhum item o e.getCurrentItem() vai ser nulo, por isso ta tando erro,

você precisa checar se ele é nulo ou não antes de pegar o tipo e tals.

 

Ex:

 

ItemStack itemClicado = e.getCurrentItem();

 

if (itemClicado != null && itemClicado.getType() == Material.EMERALD) {

   // você clicou em uma esmeralda.

}

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...