Need help with bats!

Discussion in 'Plugin Development' started by VictoryShot, Nov 16, 2014.

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

    VictoryShot

    Alright so my code here: http://hastebin.com/hiveyujere.avrasm

    There is a problem here:

    Code:java
    1. public void run()
    2. {
    3. ArrayList batList = BatBlaster.this._bats.get(event.getPlayer().getUniqueId().toString());
    4. for (Bat bat : batList) {
    5. bat.getWorld().playEffect(bat.getLocation(), Effect.SMOKE, 1);
    6. bat.remove();
    7. Bukkit.getScheduler().cancelTask(task.intValue());
    8. }
    9.  
    10. BatBlaster.this._bats.remove(event.getPlayer());
    11. }
    12. }
    13. , 40L);
    14.  
    15. for (int i = 0; i < 16; i++)
    16. ((ArrayList)this._bats.get(player)).add((Bat)player.getWorld().spawn(player.getEyeLocation(), Bat.class));
    17. }


    Where the for (Bat bat : batList) {
    there is a problem saying "Type mismatch: cannot convert from element type Object to Bat"
     
  2. Offline

    Skionz

    The _bats hash map contains Players and Bats, not Strings.
     
  3. Offline

    VictoryShot

    So how do I fix it?
     
  4. Offline

    000nick

    Instead of:


    Code:java
    1. ArrayList batList = BatBlaster.this._bats.get(event.getPlayer().getUniqueId().toString());
    2. for (Bat bat : batList) {



    Use:

    Code:java
    1. ArrayList<Bat> batList = BatBlaster.this._bats.get(event.getPlayer().getUniqueId().toString());
    2. for (Bat bat : batList) {
     
  5. Offline

    ChipDev

    Thats spoon feeding' a little bit.
    VictoryShot you state an ArrayList with no parameters, so it automatically goes to object unless you state <Bat>
     
    000nick likes this.
  6. Offline

    000nick

    ChipDev Sometimes you need real code to understand it :p
     
    ChipDev likes this.
  7. Offline

    xepisolonxx

    VictoryShot Save bats to hashmap and remove them once you are done old code example:
    Code:
      public void onPlayerDead (final PlayerDeathEvent e) {
                if (e.getEntity() instanceof Player) {   
        final Player p = (Player)e.getEntity();
                   
        Damageable dtarget = (Damageable)p;
                   
                    dtarget.setHealth(20.0);
                    for (Player players : Bukkit.getOnlinePlayers())
     
                    players.hidePlayer(p);
                    //p.teleport(e.getEntity().getKiller().getLocation());
                       
                int bat = 30;
                while (bat >= 1) {
                   
                    final Bat b = (Bat) p.getWorld().spawnEntity(p.getLocation(), EntityType.BAT);
                    b.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,80,7));
                    b.setMaxHealth(4.0);
                    b.setVelocity(new Vector(random.nextDouble()-0.5, random.nextDouble()/2.0, random.nextDouble()-0.5));
     
                  bat--;
                  final FireworkEffect fb = FireworkEffect.builder().with(Type.BALL_LARGE).withColor(Color.BLACK).trail(true).build();
     
                  final FireworkEffect fe = FireworkEffect.builder().with(Type.BURST).withColor(Color.BLACK).trail(true).build();
     
                      final FireworkEffectPlayer fplayer = new FireworkEffectPlayer();
                    try {
                        fplayer.playFirework(p.getWorld(), p.getLocation() , fb);
                    } catch (Exception e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
     
                          Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                            public void run() {
                                for (Player players : Bukkit.getOnlinePlayers()){
                                    players.showPlayer(p);
                                      try {
                                        fplayer.playFirework(p.getWorld(), b.getLocation() , fe);
                                    } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
     
                                b.remove();
                                b.getWorld().playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
                                }
                            }
                    }, 40);
                         
        }
                }
                }
                   
                  }
    i realize i didnt use hashmap here because this is like a year ago so sorry but i recommend hashmap
     
Thread Status:
Not open for further replies.

Share This Page