org.bukkit.entity.AnimalTamer Java Examples

The following examples show how to use org.bukkit.entity.AnimalTamer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerInteractListener.java    From PetMaster with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Change the owner of a pet.
 * 
 * @param player
 * @param oldOwner
 * @param newOwner
 * @param tameable
 */
private void changeOwner(Player player, AnimalTamer oldOwner, Player newOwner, Tameable tameable) {
	if (chargePrice(player, changeOwnerPrice)) {
		// Change owner.
		tameable.setOwner(newOwner);
		player.sendMessage(plugin.getChatHeader()
				+ plugin.getPluginLang().getString("owner-changed", "This pet was given to a new owner!"));
		newOwner.sendMessage(plugin.getChatHeader()
				+ plugin.getPluginLang().getString("new-owner", "Player PLAYER gave you ownership of a pet!")
						.replace("PLAYER", player.getName()));

		// Create new event to allow other plugins to be aware of the ownership change.
		PlayerChangeAnimalOwnershipEvent playerChangeAnimalOwnershipEvent = new PlayerChangeAnimalOwnershipEvent(
				oldOwner, newOwner, tameable);
		Bukkit.getServer().getPluginManager().callEvent(playerChangeAnimalOwnershipEvent);
	}
}
 
Example #2
Source File: CraftTameableAnimal.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public AnimalTamer getOwner() {
    if (getOwnerUUID() == null) {
        return null;
    }

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

    return owner;
}
 
Example #3
Source File: CraftTameableAnimal.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public void setOwner(AnimalTamer tamer) {
    if (tamer != null) {
        setTamed(true);
        getHandle().setAttackTarget(null, null, false);
        setOwnerUUID(tamer.getUniqueId());
    } else {
        setTamed(false);
        setOwnerUUID(null);
    }
}
 
Example #4
Source File: CraftAbstractHorse.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setOwner(AnimalTamer owner) {
    if (owner != null) {
        setTamed(true);
        getHandle().setAttackTarget(null, null, false);
        setOwnerUUID(owner.getUniqueId());
    } else {
        setTamed(false);
        setOwnerUUID(null);
    }
}
 
Example #5
Source File: CraftHorse.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setOwner(AnimalTamer owner) {
    if (owner != null) {
        setTamed(true);
        getHandle().setPathToEntity(null);
        setOwnerUUID(owner.getUniqueId());
    } else {
        setTamed(false);
        setOwnerUUID(null);
    }
}
 
Example #6
Source File: CraftTameableAnimal.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public AnimalTamer getOwner() {
    if (getOwnerUUID() == null) {
        return null;
    }

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

    return owner;
}
 
Example #7
Source File: CraftTameableAnimal.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setOwner(AnimalTamer tamer) {
    if (tamer != null) {
        setTamed(true);
        getHandle().setPathToEntity(null);
        setOwnerUUID(tamer.getUniqueId());
    } else {
        setTamed(false);
        setOwnerUUID(null);
}
}
 
Example #8
Source File: PlayerInteractListener.java    From PetMaster with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
	if (shouldHandleEvent(event)) {
		Tameable tameable = (Tameable) event.getRightClicked();
		AnimalTamer currentOwner = tameable.getOwner();
		if (currentOwner == null || currentOwner.getName() == null) {
			return;
		}
		// Has the player clicked on one of his own pets?
		Player player = event.getPlayer();
		boolean isOwner = player.getUniqueId().equals(currentOwner.getUniqueId());
		// Retrieve new owner from the map and delete corresponding entry.
		Player newOwner = plugin.getSetOwnerCommand().collectPendingSetOwnershipRequest(player);
		// Has the player requested to free one of his pets?
		boolean freePet = plugin.getFreeCommand().collectPendingFreeRequest(player);

		// Cannot change ownership or free pet if not owner and no bypass permission.
		if ((newOwner != null || freePet) && !isOwner && !player.hasPermission("petmaster.admin")) {
			player.sendMessage(plugin.getChatHeader() + plugin.getPluginLang()
					.getString("not-owner", "You do not own this pet!").replace("PLAYER", player.getName()));
			return;
		}

		if (newOwner != null) {
			changeOwner(player, currentOwner, newOwner, tameable);
		} else if (freePet) {
			freePet(player, currentOwner, tameable);
		} else if ((displayToOwner || !isOwner) && player.hasPermission("petmaster.showowner")) {
			displayHologramAndMessage(player, currentOwner, tameable);
		}
	}
}
 
Example #9
Source File: EntityTameEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public EntityTameEvent(final LivingEntity entity, final AnimalTamer owner) {
    super(entity);
    this.owner = owner;
}
 
Example #10
Source File: CraftAbstractHorse.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AnimalTamer getOwner() {
    if (getOwnerUUID() == null) return null;
    return getServer().getOfflinePlayer(getOwnerUUID());
}
 
Example #11
Source File: CraftHorse.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AnimalTamer getOwner() {
    if (getOwnerUUID() == null) return null;
    return getServer().getOfflinePlayer(getOwnerUUID());
}
 
Example #12
Source File: PlayerInteractListener.java    From PetMaster with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Displays a hologram, and automatically delete it after a given delay.
 * 
 * @param player
 * @param owner
 * @param tameable
 */
@SuppressWarnings("deprecation")
private void displayHologramAndMessage(Player player, AnimalTamer owner, Tameable tameable) {
	if (hologramMessage) {
		double offset = HORSE_OFFSET;
		if (tameable instanceof Ocelot || version >= 14 && tameable instanceof Cat) {
			if (!displayCat || !player.hasPermission("petmaster.showowner.cat")) {
				return;
			}
			offset = CAT_OFFSET;
		} else if (tameable instanceof Wolf) {
			if (!displayDog || !player.hasPermission("petmaster.showowner.dog")) {
				return;
			}
			offset = DOG_OFFSET;
		} else if (version >= 11 && tameable instanceof Llama) {
			if (!displayLlama || !player.hasPermission("petmaster.showowner.llama")) {
				return;
			}
			offset = LLAMA_OFFSET;
		} else if (version >= 12 && tameable instanceof Parrot) {
			if (!displayParrot || !player.hasPermission("petmaster.showowner.parrot")) {
				return;
			}
			offset = PARROT_OFFSET;
		} else if (!displayHorse || !player.hasPermission("petmaster.showowner.horse")) {
			return;
		}

		Location eventLocation = tameable.getLocation();
		// Create location with offset.
		Location hologramLocation = new Location(eventLocation.getWorld(), eventLocation.getX(),
				eventLocation.getY() + offset, eventLocation.getZ());

		final Hologram hologram = HologramsAPI.createHologram(plugin, hologramLocation);
		hologram.appendTextLine(
				ChatColor.GRAY + plugin.getPluginLang().getString("petmaster-hologram", "Pet owned by ")
						+ ChatColor.GOLD + owner.getName());

		// Runnable to delete hologram.
		new BukkitRunnable() {

			@Override
			public void run() {

				hologram.delete();
			}
		}.runTaskLater(plugin, hologramDuration);
	}

	String healthInfo = "";
	if (showHealth) {
		Animals animal = (Animals) tameable;
		String currentHealth = String.format("%.1f", animal.getHealth());
		String maxHealth = version < 9 ? String.format("%.1f", animal.getMaxHealth())
				: String.format("%.1f", animal.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
		healthInfo = ChatColor.GRAY + ". " + plugin.getPluginLang().getString("petmaster-health", "Health: ")
				+ ChatColor.GOLD + currentHealth + "/" + maxHealth;
	}

	if (chatMessage) {
		player.sendMessage(plugin.getChatHeader() + plugin.getPluginLang().getString("petmaster-chat", "Pet owned by ")
				+ ChatColor.GOLD + owner.getName() + healthInfo);
	}

	if (actionBarMessage) {
		try {
			FancyMessageSender.sendActionBarMessage(player, "&o" + ChatColor.GRAY
					+ plugin.getPluginLang().getString("petmaster-action-bar", "Pet owned by ") + ChatColor.GOLD
					+ owner.getName() + healthInfo);
		} catch (Exception e) {
			plugin.getLogger().warning("Errors while trying to display action bar message for pet ownership.");
		}
	}
}
 
Example #13
Source File: EntityTameEvent.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the owning AnimalTamer
 *
 * @return the owning AnimalTamer
 */
public AnimalTamer getOwner() {
    return owner;
}