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

import org.bukkit.Art;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftArt;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Painting;

import net.minecraft.server.EntityPainting;
import net.minecraft.server.EntityPainting.EnumArt;
import net.minecraft.server.WorldServer;

public class CraftPainting extends CraftHanging implements Painting {

	public CraftPainting(CraftServer server, EntityPainting entity) {
		super(server, entity);
	}

	@Override
	public Art getArt() {
		EnumArt art = getHandle().art;
		return CraftArt.NotchToBukkit(art);
	}

	@Override
	public boolean setArt(Art art) {
		return setArt(art, false);
	}

	@Override
	public boolean setArt(Art art, boolean force) {
		EntityPainting painting = this.getHandle();
		EnumArt oldArt = painting.art;
		painting.art = CraftArt.BukkitToNotch(art);
		painting.setDirection(painting.direction);
		if (!force && !painting.survives()) {
			// Revert painting since it doesn't fit
			painting.art = oldArt;
			painting.setDirection(painting.direction);
			return false;
		}
		this.update();
		return true;
	}

	@Override
	public boolean setFacingDirection(BlockFace face, boolean force) {
		if (super.setFacingDirection(face, force)) {
			update();
			return true;
		}

		return false;
	}

	private void update() {
		WorldServer world = ((CraftWorld) getWorld()).getHandle();
		EntityPainting painting = new EntityPainting(world);
		painting.blockPosition = getHandle().blockPosition;
		painting.art = getHandle().art;
		painting.setDirection(getHandle().direction);
		getHandle().die();
		getHandle().velocityChanged = true; // because this occurs when the painting is broken, so it might be important
		world.addEntity(painting);
		this.entity = painting;
	}

	@Override
	public EntityPainting getHandle() {
		return (EntityPainting) entity;
	}

	@Override
	public String toString() {
		return "CraftPainting{art=" + getArt() + "}";
	}

	@Override
	public EntityType getType() {
		return EntityType.PAINTING;
	}
}
