/FileExtraction/Java_unseen/Wind-Development_WindSpigot/WindSpigot-Server/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java
package org.bukkit.craftbukkit.block;

import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Dispenser;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource;
import org.bukkit.inventory.Inventory;
import org.bukkit.projectiles.BlockProjectileSource;

import net.minecraft.server.BlockDispenser;
import net.minecraft.server.BlockPosition;
import net.minecraft.server.Blocks;
import net.minecraft.server.TileEntityDispenser;

public class CraftDispenser extends CraftBlockState implements Dispenser {
	private final CraftWorld world;
	private final TileEntityDispenser dispenser;

	public CraftDispenser(final Block block) {
		super(block);

		world = (CraftWorld) block.getWorld();
		dispenser = (TileEntityDispenser) world.getTileEntityAt(getX(), getY(), getZ());
	}

	public CraftDispenser(final Material material, final TileEntityDispenser te) {
		super(material);
		world = null;
		dispenser = te;
	}

	@Override
	public Inventory getInventory() {
		return new CraftInventory(dispenser);
	}

	@Override
	public BlockProjectileSource getBlockProjectileSource() {
		Block block = getBlock();

		if (block.getType() != Material.DISPENSER) {
			return null;
		}

		return new CraftBlockProjectileSource(dispenser);
	}

	@Override
	public boolean dispense() {
		Block block = getBlock();

		if (block.getType() == Material.DISPENSER) {
			BlockDispenser dispense = (BlockDispenser) Blocks.DISPENSER;

			dispense.dispense(world.getHandle(), new BlockPosition(getX(), getY(), getZ()));
			return true;
		} else {
			return false;
		}
	}

	@Override
	public boolean update(boolean force, boolean applyPhysics) {
		boolean result = super.update(force, applyPhysics);

		if (result) {
			dispenser.update();
		}

		return result;
	}

	@Override
	public TileEntityDispenser getTileEntity() {
		return dispenser;
	}
}
