[SOLVED] Stopping the particle trail on entity hit

Discussion in 'Programming' started by TheL0w3R, May 30, 2016.

Thread Status:
Not open for further replies.
  1. Hi, i'm recoding my plugin, before I was using p.getLineOfSight() to loop through blocks, playing particles and checking if there were an entity whithin 1.5 blocks of the block iteration, if that was true, I wa simply stopping the loop and of course, the particle trail (because the particle were been played in the loop).

    The problem of that was that when you point to an entity facing diagonal blocks, the particle trail looks confusing (like a stairs of particles), it doesn't look like a line, so, now i'm planning to use vectors, the problem of this is that I can't find a way to stop the particle loop, here's the code, hope you guys understood me and sorry for my bad english):

    Code (Text):
    @Override
        public boolean castSpell(Player p, Wizard wizard, int cooldown) {
            SpellInfo info = this.getClass().getAnnotation(SpellInfo.class);
            try {
                boolean hitSomething = false;
                if(cd.isOverFor(p.getName())) {
                    Location start = p.getEyeLocation();
                    Vector increase = start.getDirection();
                    for(int counter = 0; counter < info.range(); counter++) {
                        Location point = start.add(increase);
                        ParticleEffect.HAPPY_VILLAGER.sendToPlayers(Bukkit.getOnlinePlayers(), point, 0F ,0F, 0F, 1, 5);
                    }
                    for(Block block : p.getLineOfSight((Set<Material>) null, info.range())) {
                        if(!hitSomething) {
                            for (Entity entity : block.getChunk().getEntities()) {
                                if (!(entity instanceof LivingEntity) || entity == p)
                                    continue;
                                LivingEntity le = (LivingEntity) entity;
                                if (le.getLocation().distance(block.getLocation()) <= 1.5) {
                                    boolean isCitizensNPC = entity.hasMetadata("NPC");
                                    if(!isCitizensNPC) {
                                        Vector vec = p.getLocation().getDirection();
                                        vec.distance(vec);
                                        vec.setY(0.6);
                                        vec.multiply(2D);
                                        le.damage(0.1D, p);
                                        le.setVelocity(vec);
                                        ParticleEffect secondEffect = ParticleEffect.INSTANT_SPELL;
                                        secondEffect.sendToPlayers(Bukkit.getOnlinePlayers(), block.getLocation(), 0.5f, 0.5f, 0.5f, 1, 80);
                                        p.getWorld().playSound(p.getLocation(), Sound.NOTE_PIANO, 1, 1);
                                        hitSomething = true;
                                    } else {
                                        return true;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    int rest = p.getLineOfSight((Set<Material>) null, info.range()).size() - info.range();
                    p.sendMessage("" + rest);
                    cd.startCooldownFor(p.getName(), cooldown);
                    return true;
                } else {
                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', (lm.getValue("spells.cooldown")).replaceAll("%spell%", info.name()).replaceAll("%cooldown%", Long.toString(cd.getRest(p.getName())))));
                    return false;
                }
            }catch (Exception e1) {
                e1.printStackTrace();
            }
            return false;
        }
    EDIT: Okay, oficially, i'm stupid, spigot doesn't allow me to remove this so I'll explain how i fixed it for people that may need it.

    I just removed the LineofSight loop and calculated the entity radius using the particle location loop.
    Sorry for being so impacient and posting things without thinking first.
     
    #1 TheL0w3R, May 30, 2016
    Last edited: May 30, 2016
Thread Status:
Not open for further replies.