Bats down spawn in the right location...

Discussion in 'Plugin Development' started by maxben34, Oct 27, 2013.

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

    maxben34

    I have a code where an entity is dropped and after 2 seconds it spawns bats at the entities location.
    The bats spawn at where the entity is dropped from and I can't seem to figure out why.

    Here's my code.
    Code:java
    1. @EventHandler
    2. public void onPumpkinPlace (final BlockPlaceEvent e){
    3. if(!(e.getPlayer() instanceof Player)){
    4. return;
    5. }else{
    6. Location loc = (Location) e.getBlockPlaced().getLocation();
    7. World w = Bukkit.getServer().getWorld("world");
    8. double y = loc.getY() - 3;
    9. double y1 = loc.getY()-2;
    10. double x = loc.getX();
    11. double z = loc.getZ();
    12. final Location anvilloc = new Location(w,x,y,z);
    13. double y2 = loc.getY();
    14. double x1 = loc.getX() -1;
    15. final Location tnt = new Location (w,x,y1,z);
    16. Location anvildestroy = new Location (w,x,y2,z);
    17. Location update = new Location(w,x1,y,z);
    18. if(e.getBlockPlaced().getType() == Material.WOOL && anvilloc.getBlock().getType() == Material.AIR){
    19. Player placer = (Player) e.getPlayer();
    20. anvildestroy.getBlock().setType(Material.AIR);
    21. placer.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Halloween Anvil Successfully Dropped!");
    22. anvilloc.getBlock().setType(Material.ANVIL);
    23. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    24. public void run(){
    25. tnt.getWorld().spawnFallingBlock(tnt, Material.WOOL, (byte) 1);
    26. }
    27. },5);
    28. final Entity b = (Entity) e.getPlayer().getWorld().spawnFallingBlock(tnt, Material.WOOL, (byte) 1);
    29. update.getBlock().setType(Material.GLASS);
    30. update.getBlock().setType(Material.AIR);
    31. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    32. @SuppressWarnings("deprecation")
    33. public void run(){
    34. b.getLocation().getWorld().spawnCreature(b.getLocation(), EntityType.BAT);
    35. Entity bat = (Entity) b.getLocation().getWorld().spawnCreature(b.getLocation(), EntityType.BAT);
    36.  
    37. b.getLocation().getWorld().spawnCreature(b.getLocation(), EntityType.BAT);
    38.  
    39. b.getLocation().getWorld().spawnCreature(b.getLocation(), EntityType.BAT);
    40.  
    41. b.getLocation().getWorld().playSound(e.getBlock().getLocation(), Sound.GHAST_MOAN, 10, 5);
    42.  
    43. }}, 40);
    44.  
    45.  
     
Thread Status:
Not open for further replies.

Share This Page