Ducky Postado Outubro 21, 2017 Denunciar Postado Outubro 21, 2017 (editado) 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 Outubro 21, 2017 por Burpo
Atlvntis. Postado Outubro 21, 2017 Denunciar Postado Outubro 21, 2017 Faz um debug, printa todas as paradas que tu puxa do arquivo pro console e manda aqui.
Ducky Postado Outubro 21, 2017 Autor Denunciar Postado Outubro 21, 2017 Faz um debug, printa todas as paradas que tu puxa do arquivo pro console e manda aqui. Não sei fazer isso
Naghtrion Postado Outubro 21, 2017 Denunciar Postado Outubro 21, 2017 todos os materiais na config estao o mesmo? usa if(...){ } else if (){ } else if() { } else { }
jeta Postado Outubro 21, 2017 Denunciar Postado Outubro 21, 2017 https://www.youtube.com/watch?v=E4JZ8leWhkA&list=PLxQNfKs8YwvGhXHbHtxtoB-tRRv6r3Rlr&index=23
Kees_T Postado Outubro 21, 2017 Denunciar Postado Outubro 21, 2017 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; } } }
VictorHeaven Postado Outubro 21, 2017 Denunciar Postado Outubro 21, 2017 Recomendo que verifique por slot e não por material. Aliás, se os materiais forem iguais, irá retornar todos, por isso pode estar causando isso, de novo, verifique por slot.
zAth Postado Outubro 21, 2017 Denunciar Postado Outubro 21, 2017 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.
TequilAxBr Postado Outubro 28, 2017 Denunciar Postado Outubro 28, 2017 Faz um else if ai que resolve.
Ducky Postado Outubro 28, 2017 Autor Denunciar Postado Outubro 28, 2017 Faz um else if ai que resolve. Já está resolvido a um tempão, já.. Malz @TOPIC Pode fechar.
zAth Postado Outubro 28, 2017 Denunciar Postado Outubro 28, 2017 Sua dúvida foi marcada como [Resolvido] e movido à área de dúvidas resolvidas. Atenciosamente, Gamer's Board
Pergunta
Ducky
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 Burpo10 respostass a esta questão
Posts Recomendados