Hello im makin a gun and the particle effects wont work heres my code: Code (Text): @EventHandler public void onPlayerInteract(PlayerInteractEvent e) { if(!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; if(!(e.getItem().getType() == Material.DIAMOND_HOE)) return; if (!(e.getItem().getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Gun"))) return; Snowball s = e.getPlayer().launchProjectile(Snowball.class); s.setVelocity(s.getVelocity().multiply(3)); e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.BLAZE_HIT, 2F, 1F); } @EventHandler public void onEntityDamage(EntityDamageByEntityEvent e) { if (e.getDamager() instanceof Snowball) { Snowball s = (Snowball) e.getDamager(); if (s.getShooter() instanceof Player) { Player shooter = (Player) s.getShooter(); if (shooter.getItemInHand().getType()== Material.DIAMOND_HOE) { if (shooter.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Gun")){ e.setDamage(5.0); s.getWorld().playEffect(s.getLocation(), Effect.SMOKE, 100); } } } } }
I think its because when EntityDamageByEntityEvent is called the player may no longer have the diamond hoe in their hand So the smoke particles never show that's probably why Using the fact that all entities have a UUID, store the shooter UUID and snowball entity UUID in a map with the entity UUID FIRST: Map<UUID,UUID> Do this on shoot and then when a player gets hit check if the snowball UUID is a key in the Map sns if it is get the player UUID associated with it. This should work perfectly And please use UUIDs not entire classes or else woth multiple people shooting automatic guns your server will become laggy Can u show me In code?
I'm on my phone sorry but I'll do my best private Map<UUID,UUID> bullets... @EventHandler public void onInteract(PlayerInteractEvent e) { if (e.getAction ==Action.RIGHT_CLICK_AIR) { If(e.getPlayer.getItemInHand().getType() == Material.DIAMOND_HOE) { Check name... Snowball proj = (snowball launch code) UUID uuid = proj.getUniqueIdentifier(); UUID player = player.getUniqueIdentifier(); bullets.put(uuid,player); } } Try to do the other half