Ir para conteúdo
  • 0

Código retornando all


Ducky

Pergunta

Olá meus queridos, tenho esse código:

 

 

E ao clicar em um dos itens ele executa todos os outros, como resolvo?

EventHandler
public void onClick(InventoryClickEvent e){
Player p = (Player)e.getWhoClicked();
if (e.getInventory().getName().equalsIgnoreCase(Main.instance.getConfig().getString("Inventario.Dados.Nome")));
e.setCancelled(true);
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Mulher.Material"))) {
Bukkit.dispatchCommand(p, "mulher");
p.closeInventory();
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Assassino.Material"))) {
Bukkit.dispatchCommand(p, "assassino");
p.closeInventory();
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Empresario.Material"))) {
Bukkit.dispatchCommand(p, "empresario");
p.closeInventory();
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Mercenario.Material"))) {
Bukkit.dispatchCommand(p, "mercenario"); 
p.closeInventory();
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Piedoso.Material"))) {
Bukkit.dispatchCommand(p, "piedoso"); 
p.closeInventory();
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Pacifico.Material"))) {
Bukkit.dispatchCommand(p, "pacifico"); 
p.closeInventory();
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Mortifero.Material"))) {
Bukkit.dispatchCommand(p, "mortifero"); 
p.closeInventory();
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.VidaLoka.Material"))) {
Bukkit.dispatchCommand(p, "vidaloka"); 
p.closeInventory();
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Reparador.Material"))) {
Bukkit.dispatchCommand(p, "reparador"); 
p.closeInventory();
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Construtor.Material"))) {
Bukkit.dispatchCommand(p, "construtor"); 
p.closeInventory();
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Remover.Material"))) {
Bukkit.dispatchCommand(p, "remover"); 
p.closeInventory();
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.List.Material"))) {
Bukkit.dispatchCommand(p, "taglist"); 
p.closeInventory();
}
else
{
e.setCancelled(false);
}
}
}
Editado por Burpo
Link para o comentário
Compartilhar em outros sites

10 respostass a esta questão

Posts Recomendados

Você deveria estar usando:
 

if () {

} else if () {

} else if () {

}....

Mas se quiser não pegar nenhum outro valor quando você pegar um, adicione o return; na linha, tipo:

 

entHandler
public void onClick(InventoryClickEvent e){
Player p = (Player)e.getWhoClicked();

if (e.getInventory().getName().equalsIgnoreCase(Main.instance.getConfig().getString("Inventario.Dados.Nome")) {
e.setCancelled(true);
return;
}

if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Mulher.Material")) {
Bukkit.dispatchCommand(p, "mulher");
p.closeInventory();
return;
}

if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Assassino.Material")) {
Bukkit.dispatchCommand(p, "assassino");
p.closeInventory();
return;
}

if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Empresario.Material")) {
Bukkit.dispatchCommand(p, "empresario");
p.closeInventory();
return;
}

if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Mercenario.Material")) {
Bukkit.dispatchCommand(p, "mercenario"); 
p.closeInventory();
return;
}

if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Piedoso.Material")) {
Bukkit.dispatchCommand(p, "piedoso"); 
p.closeInventory();
return;
}
if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Pacifico.Material")) {
Bukkit.dispatchCommand(p, "pacifico"); 
p.closeInventory();
}

if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Mortifero.Material")) {
Bukkit.dispatchCommand(p, "mortifero"); 
p.closeInventory();
return;
}

if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.VidaLoka.Material"))) {
Bukkit.dispatchCommand(p, "vidaloka"); 
p.closeInventory();
return;
}

if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Reparador.Material")) {
Bukkit.dispatchCommand(p, "reparador"); 
p.closeInventory();
return;
}

if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Construtor.Material")) {
Bukkit.dispatchCommand(p, "construtor"); 
p.closeInventory();
return;
}

if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.Remover.Material")) {
Bukkit.dispatchCommand(p, "remover"); 
p.closeInventory();
return;
}

if (e.getCurrentItem().getType() == Material.getMaterial(Main.instance.getConfig().getString("Inventario.List.Material")) {
Bukkit.dispatchCommand(p, "taglist"); 
p.closeInventory();
return;
}

else
{
e.setCancelled(false);
return;
}
}
}
Link para o comentário
Compartilhar em outros sites

Além que você colocou um ; a seguir a um if, o seu else lá de baixo só está "ligado" ao último if.

int numero = 0;
if(numero == 0)
  // é zero
else if(numero == 1)
  // é um
else
  // não é 0 nem 1

Como você não fez isso..

Além que mesmo que fizesse o else if, se algum material fosse igual a outro, eles os dois iam ser executados mesmo com else if porque supostamente ficaria assim

int numero = 0;
if(numero == 0)
  // faz isto
else if(numero == 0)
  // faz aquilo
else
  // não faz nem isto nem aquilo

O código executaria "isto" e "aquilo"

 

O certo é verificar o slot.

Link para o comentário
Compartilhar em outros sites

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