Sheep color

This commit is contained in:
Brianna O'Keefe 2019-02-21 06:46:54 -05:00
parent f4ce12ff8e
commit 9458e5bdf7

View File

@ -9,6 +9,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityBreedEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.SheepDyeWoolEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
@ -29,6 +30,25 @@ public class InteractListeners implements Listener {
this.instance = instance;
}
@EventHandler
public void onSheepDye(SheepDyeWoolEvent event) {
Entity entity = event.getEntity();
if (!instance.getEntityStackManager().isStacked(entity) || event.getColor() == ((Sheep) entity).getColor()) return;
EntityStack stack = instance.getEntityStackManager().getStack(entity);
Entity newEntity = entity.getWorld().spawnEntity(entity.getLocation(), entity.getType());
entity.setVelocity(getRandomVector());
Sheep sheep = ((Sheep) newEntity);
sheep.setSheared(sheep.isSheared());
sheep.setColor(sheep.getColor());
instance.getEntityStackManager().addStack(new EntityStack(newEntity, stack.getAmount() - 1));
stack.setAmount(1);
instance.getEntityStackManager().removeStack(entity);
}
@EventHandler
public void onInteract(PlayerInteractAtEntityEvent event) {
Player player = event.getPlayer();