All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bukkit.craftbukkit.entity.CraftTameableAnimal Maven / Gradle / Ivy

package org.bukkit.craftbukkit.entity;

import net.minecraft.server.EntityTameableAnimal;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Tameable;

import java.util.UUID;

public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creature {
  public CraftTameableAnimal(CraftServer server, EntityTameableAnimal entity) {
    super(server, entity);
  }

  @Override
  public EntityTameableAnimal getHandle() {
    return (EntityTameableAnimal) super.getHandle();
  }

  public UUID getOwnerUUID() {
    try {
      return UUID.fromString(getHandle().getOwnerUUID());
    } catch (IllegalArgumentException ex) {
      return null;
    }
  }

  public void setOwnerUUID(UUID uuid) {
    if (uuid == null) {
      getHandle().setOwnerUUID("");
    } else {
      getHandle().setOwnerUUID(uuid.toString());
    }
  }

  public AnimalTamer getOwner() {
    if (getOwnerUUID() == null) {
      return null;
    }

    AnimalTamer owner = getServer().getPlayer(getOwnerUUID());
    if (owner == null) {
      owner = getServer().getOfflinePlayer(getOwnerUUID());
    }

    return owner;
  }

  public void setOwner(AnimalTamer tamer) {
    if (tamer != null) {
      setTamed(true);
      getHandle().setGoalTarget(null, null, false);
      setOwnerUUID(tamer.getUniqueId());
    } else {
      setTamed(false);
      setOwnerUUID(null);
    }
  }

  public boolean isTamed() {
    return getHandle().isTamed();
  }

  public void setTamed(boolean tame) {
    getHandle().setTamed(tame);
    if (!tame) {
      setOwnerUUID(null);
    }
  }

  public boolean isSitting() {
    return getHandle().isSitting();
  }

  public void setSitting(boolean sitting) {
    getHandle().getGoalSit().setSitting(sitting);
  }

  @Override
  public String toString() {
    return getClass().getSimpleName() + "{owner=" + getOwner() + ",tamed=" + isTamed() + "}";
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy