下面列出了怎么用org.bukkit.entity.Llama的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public boolean checkTrait(Entity original, Entity nearby) {
if(original instanceof Llama){
return (((Llama) original).getColor() != ((Llama) nearby).getColor());
}
return false;
}
@Override
protected boolean init(@Nullable Class<? extends Llama> c, @Nullable Llama llama) {
if (TRADER_SUPPORT && c != null)
isTrader = c.isAssignableFrom(TraderLlama.class);
if (llama != null)
color = llama.getColor();
return true;
}
@Override
public Class<? extends Llama> getType() {
// If TraderLlama does not exist, this would ALWAYS throw ClassNotFoundException
// (no matter if isTrader == false)
if (TRADER_SUPPORT)
return isTrader ? TraderLlama.class : Llama.class;
assert !isTrader; // Shouldn't be possible on this version
return Llama.class;
}
@Override
public void applyTrait(Entity original, Entity spawned) {
if(original instanceof Llama){
((Llama) spawned).setColor(((Llama) original).getColor());
}
}
@Override
public void set(Llama entity) {
Color randomColor = color == null ? CollectionUtils.getRandom(Color.values()) : color;
assert randomColor != null;
entity.setColor(randomColor);
}
@Override
protected boolean match(Llama entity) {
return (TRADER_SUPPORT && isTrader == entity instanceof TraderLlama && (color == null || color == entity.getColor()))
|| color == null || color == entity.getColor();
}
/**
* 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.");
}
}
}