zToodi Postado Outubro 28, 2018 Denunciar Compartilhar Postado Outubro 28, 2018 Gostaria de saber o método que verificar se tal mob foi morto por um jogador segurando uma espada de diamante ex: Se eu matar um porco com uma espada de diamante vai me enviar qualquer mensagem Link para o comentário Compartilhar em outros sites More sharing options...
NiotGG Postado Outubro 28, 2018 Denunciar Compartilhar Postado Outubro 28, 2018 (editado) 27 minutos atrás, レオナルド disse: Gostaria de saber o método que verificar se tal mob foi morto por um jogador segurando uma espada de diamante ex: Se eu matar um porco com uma espada de diamante vai me enviar qualquer mensagem Cara tu pode usar o evento EntityDeathEvent e verificar se a entidade que matou instanceof a entidade Player se sim vc vai pega e pega essa entidade usando um cast exemplo: if (e.getEntity().getKiller() instanceof Player) { Player p = (Player) e.getEntity().getKiller(); } ai vc pega o item que ta na mão do player exemplo: if (e.getEntity().getKiller() instanceof Player) { Player p = (Player) e.getEntity().getKiller(); ItemStack iteminhand = p.getItemInHand(); } ai depois so vc verificar se o iteminhand é igual ao item que tu quer if (e.getEntity().getKiller() instanceof Player) { Player p = (Player) e.getEntity().getKiller(); ItemStack iteminhand = p.getItemInHand(); if (iteminhand.isSimiliar(new ItemStack(Material.DIAMOND_SWORD)) { p.sendMessage("MENSAGEM"); } } Na vd n precisa de verificar se o Killer instanceof um Player pq em si o metodo getKiller retorna um player puis so por costume kkkkk Mas é isso espero ter ajudado Editado Outubro 28, 2018 por NiotGG Link para o comentário Compartilhar em outros sites More sharing options...
zToodi Postado Outubro 31, 2018 Autor Denunciar Compartilhar Postado Outubro 31, 2018 Em 28/10/2018 em 20:30, NiotGG disse: Cara tu pode usar o evento EntityDeathEvent e verificar se a entidade que matou instanceof a entidade Player se sim vc vai pega e pega essa entidade usando um cast exemplo: if (e.getEntity().getKiller() instanceof Player) { Player p = (Player) e.getEntity().getKiller(); } ai vc pega o item que ta na mão do player exemplo: if (e.getEntity().getKiller() instanceof Player) { Player p = (Player) e.getEntity().getKiller(); ItemStack iteminhand = p.getItemInHand(); } ai depois so vc verificar se o iteminhand é igual ao item que tu quer if (e.getEntity().getKiller() instanceof Player) { Player p = (Player) e.getEntity().getKiller(); ItemStack iteminhand = p.getItemInHand(); if (iteminhand.isSimiliar(new ItemStack(Material.DIAMOND_SWORD)) { p.sendMessage("MENSAGEM"); } } Na vd n precisa de verificar se o Killer instanceof um Player pq em si o metodo getKiller retorna um player puis so por costume kkkkk Mas é isso espero ter ajudado Ja que não precisa verificar se o instanceof é um player é so fazer assim? Link para o comentário Compartilhar em outros sites More sharing options...
VictorHeaven Postado Outubro 31, 2018 Denunciar Compartilhar Postado Outubro 31, 2018 @EventHandler public void on(EntityDeathEvent e) { if (e.getEntity() instanceof Pig && e.getEntity().getKiller() instanceof Player) { ItemStack itemStack = e.getEntity().getKiller().getItemInHand(); if (itemStack != null && itemStack.getType().equals(Material.DIAMOND_SWORD)) { e.getEntity().getKiller().sendMessage("Você matou um porco com uma Espada de Diamante!"); } } } Link para o comentário Compartilhar em outros sites More sharing options...
NiotGG Postado Outubro 31, 2018 Denunciar Compartilhar Postado Outubro 31, 2018 @レオナルド Mano exatamente oque o @Victor. falou Link para o comentário Compartilhar em outros sites More sharing options...
Reset Postado Dezembro 15, 2018 Denunciar Compartilhar Postado Dezembro 15, 2018 Seu tópico foi marcado como Inativo. Para reverter está ação, entre em contato com a equipe de Moderação. Link para o comentário Compartilhar em outros sites More sharing options...
Posts Recomendados