Player based problem with For Looping

Discussion in 'Plugin Development' started by Acer_Mortem, Jan 20, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Acer_Mortem

    What I'm trying to do is have a Skill, where when the method is called, all the nearby entities are damaged slightly and some effects are put on them. But for some reason, it never loops through all of the entities. It works for some Players (found in parameters of the method), but not for others. Any idea why?
    Where for loop method is called:
    Code:
    public void timeFlux3(final String name){
            plugin.getLogger().info(name + "this");
            final Player p = Bukkit.getPlayer(name);
            plugin.getLogger().info(p + "whatever");
            final ItemStack hand = p.getItemInHand();
            if (System.currentTimeMillis()
                    - (timefluxcount.containsKey(p.getName()) ? timefluxcount
                            .get(p.getName()) : 0) >= 48000) {
                if(plugin.hmm.EnoughMana(name, 75) == false){
                    p.sendMessage(ChatColor.RED + "You don't have enough " + ChatColor.GOLD + "Mana" + ChatColor.RED + " to use this skill!");
                    return;
                }
                if(hand.containsEnchantment(Enchantment.ARROW_DAMAGE)){
                    hand.removeEnchantment(Enchantment.ARROW_DAMAGE);
                }
                if(hand != null){
                    if(hand.hasItemMeta()){
                        if(hand.getItemMeta().hasDisplayName()){
                            int CDrunning = dfs.getCustomConfig().getInt(name + ".CDrunning");
                            plugin.cd.runCountdown(p, 48, hand.getItemMeta().getDisplayName(), CDrunning);
                        }
                    }
                }
                final List<Entity> nearbyEnts = p.getNearbyEntities(10, 10, 10);
                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
                    public void run(){
                        plugin.getLogger().info("xcc");
                        nearbyEntsMethod(p, p.getNearbyEntities(10, 10, 10));
                    }
                }, 180L);
                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
                    public void run(){
                        for(Entity ent : nearbyEnts){
                            if(ent instanceof Player){
                                Player pent = (Player) ent;
                                String pentname = pent.getName();
                                if(timeflux.contains(pentname)){
                                    timeflux.remove(pentname);
                                    pent.sendMessage(ChatColor.GREEN + "You have been released from the " + ChatColor.AQUA + "Strong Time Flux");
                                }
                            }
                        }
                    }
                }, 400L);
                timefluxplayer.add(name);
                p.sendMessage(ChatColor.BLUE + "You prepare to send out a Time Flux!");
                timefluxcount.put(p.getName(), System.currentTimeMillis());
                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
                    public void run(){
                        timefluxcount.remove(p.getName());
                        p.sendMessage(ChatColor.BLUE + "Time Flux III" + ChatColor.GREEN + " is off of cooldown!");
                        for(ItemStack i : p.getInventory()){
                            if(i == null){
                                continue;
                            }
                            else{
                            if(i.hasItemMeta()){
                                if(i.getItemMeta().hasDisplayName()){
                                    if(i.getItemMeta().getDisplayName().equals(ChatColor.GOLD + "Ultimate: " + ChatColor.BLUE + "Time Flux III")){
                                    if(!i.containsEnchantment(Enchantment.ARROW_DAMAGE)){
                                        i.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 1);
                                    }
                                }
                                }
                            }
                            }
                        }
                    }
                }, 960L);
            }
            else{
                p.sendMessage(ChatColor.BLUE + "Time Flux III " + ChatColor.RED + "is on cooldown!");
            }
        }
    Where for loop is occuring:
    Code:
    public void nearbyEntsMethod(Player p, List<Entity> nearbyEnts2){
            String name = p.getName();
            if(timefluxplayer.contains(name)){
                timefluxplayer.remove(name);
                p.getWorld().playEffect(p.getLocation(), Effect.ENDER_SIGNAL, 3);
                p.getWorld().playSound(p.getLocation(), Sound.ENDERMAN_SCREAM, 5, 5);
                p.getWorld().playSound(p.getLocation(), Sound.ENDERMAN_SCREAM, 5, 5);
                p.getWorld().playSound(p.getLocation(), Sound.ENDERMAN_SCREAM, 5, 5);
                for(Entity ent : nearbyEnts2){
                    plugin.getLogger().info(nearbyEnts2.size() + "-");
                    if(ent instanceof Player){
                        Player pent = (Player) ent;
                        String pentname = pent.getName();
                        LivingEntity lent = (LivingEntity)ent;
                        if(gc.checkGuildAndInstance(p, lent) == false){
                            if(!(timeflux.contains(pentname))){
                                timeflux.add(pentname);
                                pent.sendMessage(ChatColor.RED + "You have been put into a " + ChatColor.AQUA + "Time Flux " + ChatColor.RED + "by " + name);
                                pent.sendMessage(ChatColor.RED + "You feel strange due to the Time Flux!");
                                pent.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 0));
                                pent.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 120, 2));
                                pent.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 140, 2));
                            }
                        }
                    }
                    else{
                        if(ent instanceof LivingEntity){
                            ((LivingEntity) ent).damage(20, p);
                        }
                    }
                    continue;
                }
            }
        }
     
  2. Can't find the definition of gc, what is it?
     
  3. Offline

    Acer_Mortem

    hapm

    That's a path to another class. That works perfectly fine. The problem is, is that the for loop found in the second code works or Player A fine, but for Player B (who runs the method after Player A), the method one runs through one Entity in nearbyEnts2
     
Thread Status:
Not open for further replies.

Share This Page