Discussion in 'Spigot Plugin Development' started by Bravecity, May 24, 2015.

  1. Hello im makin a gun and the particle effects wont work

    heres my code:
    Code (Text):
        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);
            e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.BLAZE_HIT, 2F, 1F);
        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")){
                            s.getWorld().playEffect(s.getLocation(), Effect.SMOKE, 100);
  2. 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?
    #2 belknapkid, May 24, 2015
    Last edited by a moderator: May 24, 2015
  3. I'm on my phone sorry but I'll do my best

    private Map<UUID,UUID> bullets...

    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();

    Try to do the other half
  4. yES