org.bukkit.entity.Cat Java Examples

The following examples show how to use org.bukkit.entity.Cat. 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: CatTrait.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean checkTrait(Entity original, Entity nearby) {
    if (original instanceof Cat) {
        return ((Cat) original).getCatType() != ((Cat) nearby).getCatType();
    }
    return false;
}
 
Example #2
Source File: CatData.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) {
	if (exprs.length > 0 && exprs[0] != null)
		race = ((Literal<Cat.Type>) exprs[0]).getSingle();
	return true;
}
 
Example #3
Source File: CatTrait.java    From StackMob-3 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void applyTrait(Entity original, Entity spawned) {
    if (original instanceof Cat) {
        ((Cat) spawned).setCatType(((Cat) original).getCatType());
    }
}
 
Example #4
Source File: BukkitCompat.java    From StackMob-3 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean checkFood(Entity entity, ItemStack food) {
    Material type = food.getType();
    switch (entity.getType()) {
        case COW:
        case SHEEP:
        case MUSHROOM_COW:
            return type == Material.WHEAT;
        case PIG:
            return (type == Material.CARROT || type == Material.BEETROOT || type == Material.POTATO);
        case CHICKEN:
            return type == Material.WHEAT_SEEDS
                    || type == Material.MELON_SEEDS
                    || type == Material.BEETROOT_SEEDS
                    || type == Material.PUMPKIN_SEEDS;
        case HORSE:
            return (type == Material.GOLDEN_APPLE || type == Material.GOLDEN_CARROT) && ((Horse)entity).isTamed();
        case WOLF:
            return (type == Material.BEEF
                    || type == Material.CHICKEN
                    || type == Material.COD
                    || type == Material.MUTTON
                    || type == Material.PORKCHOP
                    || type == Material.RABBIT
                    || type == Material.SALMON
                    || type == Material.COOKED_BEEF
                    || type == Material.COOKED_CHICKEN
                    || type == Material.COOKED_COD
                    || type == Material.COOKED_MUTTON
                    || type == Material.COOKED_PORKCHOP
                    || type == Material.COOKED_RABBIT
                    || type == Material.COOKED_SALMON)
                    && ((Wolf) entity).isTamed();
        case OCELOT:
            return (type == Material.SALMON
                    || type == Material.COD
                    || type == Material.PUFFERFISH
                    || type == Material.TROPICAL_FISH);
        case RABBIT:
            return type == Material.CARROT || type == Material.GOLDEN_CARROT || type == Material.DANDELION;
        case LLAMA:
            return type == Material.HAY_BLOCK;
        case TURTLE:
            return type == Material.SEAGRASS;
        case PANDA:
            return type == Material.BAMBOO;
        case FOX:
            return type == Material.SWEET_BERRIES;
        case CAT:
            return (type == Material.COD || type == Material.SALMON) && ((Cat) entity).isTamed();
    }
    return false;
}
 
Example #5
Source File: CatData.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean init(@Nullable Class<? extends Cat> c, @Nullable Cat cat) {
	race = (cat == null) ? Cat.Type.TABBY : cat.getCatType();
	return true;
}
 
Example #6
Source File: CatData.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void set(Cat entity) {
	Cat.Type type = race != null ? race : CollectionUtils.getRandom(Cat.Type.values());
	assert type != null;
	entity.setCatType(type);
}
 
Example #7
Source File: CatData.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean match(Cat entity) {
	return race == null || entity.getCatType() == race;
}
 
Example #8
Source File: CatData.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class<? extends Cat> getType() {
	return Cat.class;
}
 
Example #9
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.");
		}
	}
}