下面列出了怎么用org.bukkit.entity.Horse的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public boolean checkTrait(Entity original, Entity nearby) {
if(original instanceof Horse){
return (((Horse) original).getColor() != ((Horse) nearby).getColor());
}
return false;
}
@Override
public void applyTrait(Entity original, Entity spawned) {
if(original instanceof Horse){
((Horse) spawned).setColor(((Horse) original).getColor());
// another trait?
}
}
@Override
protected boolean init(final @Nullable Class<? extends Horse> c, final @Nullable Horse e) {
if (e != null) {
variant = e.getVariant();
color = e.getColor();
style = e.getStyle();
}
return true;
}
@Override
public void set(final Horse entity) {
if (variant != null)
entity.setVariant(variant);
if (color != null)
entity.setColor(color);
if (style != null)
entity.setStyle(style);
}
@Override
public void onDisable() {
for (final Player player : Bukkit.getOnlinePlayers()) {
if (player.isInsideVehicle()) {
final Entity vehicle = player.getVehicle();
if (vehicle.getType() == EntityType.HORSE && removeHorseArmour((Horse) vehicle)) {
player.sendMessage(messages.getRaw("dropped armour"));
}
}
}
}
protected boolean removeHorseArmour(Horse horse) {
final ItemStack armour = horse.getInventory().getArmor();
if (armour != null && armour.getType() != Material.AIR) {
// remove the armour and drop it into the world
horse.getInventory().setArmor(null);
horse.getWorld().dropItemNaturally(horse.getLocation(), armour);
return true;
}
return false;
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void on(EntityMountEvent event) {
if (isEnabled()) return;
if (event.getEntityType() != EntityType.PLAYER || event.getMount().getType() != EntityType.HORSE) return;
if (removeHorseArmour((Horse) event.getMount())) {
event.getEntity().sendMessage(messages.getRaw("dropped armour"));
}
}
public void setVariant(Horse.Variant variant) {
throw new UnsupportedOperationException("Not supported.");
}
@Override
public Horse.Variant getVariant() {
return Horse.Variant.LLAMA;
}
@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)
&& ((Ocelot) entity).isTamed();
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;
}
return false;
}
@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;
}
@Override
protected boolean match(final Horse entity) {
return (variant == null || variant == entity.getVariant())
&& (color == null || color == entity.getColor())
&& (style == null || style == entity.getStyle());
}
@Override
public Class<? extends Horse> getType() {
return Horse.class;
}
@Override
public void setStyle(Horse.Style bukkitStyle) {
getBukkitEntity().setStyle(bukkitStyle);
}
@Override
public void setColor(Horse.Color color) {
getBukkitEntity().setColor(color);
}
@Override
public Horse getBukkitEntity() {
return (Horse) super.getBukkitEntity();
}
@Override
public void setStyle(Horse.Style bukkitStyle) {
getBukkitEntity().setStyle(bukkitStyle);
}
@Override
public void setColor(Horse.Color color) {
getBukkitEntity().setColor(color);
}
@Override
public Horse getBukkitEntity() {
return (Horse) super.getBukkitEntity();
}
@Override
public void setStyle(Horse.Style bukkitStyle) {
getBukkitEntity().setStyle(bukkitStyle);
}
@Override
public void setColor(Horse.Color color) {
getBukkitEntity().setColor(color);
}
@Override
public Horse getBukkitEntity() {
return (Horse) super.getBukkitEntity();
}
@Override
public void setStyle(Horse.Style bukkitStyle) {
if (getBukkitEntity() instanceof Horse) {
((Horse) getBukkitEntity()).setStyle(bukkitStyle);
}
}
@Override
public void setColor(Horse.Color color) {
if (getBukkitEntity() instanceof Horse) {
((Horse) getBukkitEntity()).setColor(color);
}
}
@Override
public void setStyle(Horse.Style bukkitStyle) {
if (getBukkitEntity() instanceof Horse) {
((Horse) getBukkitEntity()).setStyle(bukkitStyle);
}
}
@Override
public void setColor(Horse.Color color) {
if (getBukkitEntity() instanceof Horse) {
((Horse) getBukkitEntity()).setColor(color);
}
}
@Override
public void setStyle(Horse.Style bukkitStyle) {
getBukkitEntity().setStyle(bukkitStyle);
}
@Override
public void setColor(Horse.Color color) {
getBukkitEntity().setColor(color);
}
@Override
public Horse getBukkitEntity() {
return (Horse) super.getBukkitEntity();
}
public static HorseJumpEvent callHorseJumpEvent(net.minecraft.entity.Entity horse, float power) {
HorseJumpEvent event = new HorseJumpEvent((Horse) horse.getBukkitEntity(), power);
horse.getBukkitEntity().getServer().getPluginManager().callEvent(event);
return event;
}