/*
 * Copyright 2015 CrystalCraftMC
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.crystalcraftmc.crystaleggfactory;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;

public class CakeAnimation {
	private Block globalB;
	private Timer tim;
	private int accumulator;
	public final int NUMCAKES = 5; //MAY CHANGE NUMBER - will also automatically check NUMCAKES blocks
									//above the PlayerInteractEvent to make sure clear before proceeding
	
	private final int CAKEFRAMERATE = 153; //cakes show up CAKEFRAMERATE milliseconds inbetween eachother
	
//####################################################################
	public CakeAnimation(Block b) {
		globalB = b;
		accumulator = 0;
		tim = new Timer(CAKEFRAMERATE, new CakeUpdateListener());
		tim.start();
	}
	public CakeAnimation() {
		//to create a low-resource accessFields object in EggThrowListener class
	}
	private class CakeUpdateListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			accumulator++;
			Location loc = globalB.getLocation();
			loc.setY(globalB.getLocation().getY()+accumulator);
			Block bbb = loc.getBlock();
			bbb.setType(Material.CAKE_BLOCK);
			
			if(accumulator >= NUMCAKES)
				stopTim();
		}
	}
	public void stopTim() {
		tim.stop();
	}
}

@@ -928,16 +928,51 @@
 er tim;%0A
+%09private CrystalEggFactory plugin;%0A
 %09private
@@ -989,16 +989,16 @@
 ulator;%0A
-
 %09public 
@@ -1374,19 +1374,69 @@
 (Block b
-) %7B
+, CrystalEggFactory plugin) %7B%0A%09%09this.plugin = plugin;
 %0A%09%09globa
@@ -1870,16 +1870,22 @@
 or);%0A%09%09%09
+final 
 Block bb
@@ -1911,45 +1911,218 @@
 %0A%09%09%09
-bbb.setType(Material.CAKE_BLOCK);%0A%09%09%09
+plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() %7B%0A                public void run() %7B%0A                    bbb.setType(Material.CAKE_BLOCK);%0A                %7D%0A            %7D, 5L);
 %0A%09%09%09
@@ -2168,16 +2168,20 @@
 ();%0A%09%09%7D%0A
+%09%09%09%0A
 %09%7D%0A%09publ
@@ -2200,16 +2200,16 @@
 Tim() %7B%0A
-
 %09%09tim.st
@@ -2217,10 +2217,37 @@
 p();%0A%09%7D%0A
+%09public void hop() %7B%0A%09%09%0A%09%7D%0A
 %7D%0A

Make cake in Sync thread