下面列出了怎么用org.bukkit.entity.WitherSkeleton的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
@SuppressWarnings("deprecation") // We do a version check ;)
public SkeletonType getSkeletonType() {
if (Versioning.NMS_VERSION.compareTo(NmsVersion.v1_11_R1) >= 0) {
if (getBukkitEntity() instanceof WitherSkeleton) {
return SkeletonType.WITHER;
} else if (getBukkitEntity() instanceof Stray) {
return SkeletonType.STRAY;
} else {
return SkeletonType.NORMAL;
}
} else {
switch (getBukkitEntity().getSkeletonType()) {
case WITHER:
return SkeletonType.WITHER;
case STRAY:
return SkeletonType.STRAY;
case NORMAL:
return SkeletonType.NORMAL;
default:
throw new AssertionError("Unknown skeleton type!");
}
}
}
/**
* Comes AFTER the SpawnEvents{@link #onCreatureSpawn(CreatureSpawnEvent)} - so cancelled will have effect
* @param e
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent e) {
if (!spawnEnabled || e.getSpawnReason() != CreatureSpawnEvent.SpawnReason.NATURAL) {
return;
}
if (!plugin.getWorldManager().isSkyNether(e.getLocation().getWorld())) {
return;
}
if (e.getLocation().getBlockY() > plugin.getWorldManager().getNetherWorld().getMaxHeight()) {
// Block spawning above nether...
e.setCancelled(true);
return;
}
if (e.getEntity() instanceof PigZombie) {
Block block = e.getLocation().getBlock().getRelative(BlockFace.DOWN);
if (isNetherFortressWalkway(block)) {
e.setCancelled(true);
double p = RND.nextDouble();
if (p <= chanceWither && block.getRelative(BlockFace.UP, 3).getType() == Material.AIR) {
WitherSkeleton mob = (WitherSkeleton) e.getLocation().getWorld().spawnEntity(
e.getLocation(), EntityType.WITHER_SKELETON);
mob.getEquipment().setItemInMainHand(new ItemStack(Material.STONE_SWORD, 1));
} else if (p <= chanceWither+chanceBlaze) {
e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.BLAZE);
} else if (p <= chanceWither+chanceBlaze+chanceSkeleton) {
e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.SKELETON);
} else {
e.setCancelled(false); // Spawn PigZombie
}
}
}
}
@Override
public EntityKillHandler getItemHandler() {
return (e, entity, killer, item) -> {
Random random = ThreadLocalRandom.current();
if (e.getEntity() instanceof Zombie) {
if (random.nextInt(100) < chanceZombie.getValue()) {
e.getDrops().add(new ItemStack(Material.ZOMBIE_HEAD));
}
}
else if (e.getEntity() instanceof WitherSkeleton) {
if (random.nextInt(100) < chanceWitherSkeleton.getValue()) {
e.getDrops().add(new ItemStack(Material.WITHER_SKELETON_SKULL));
}
}
else if (e.getEntity() instanceof Skeleton) {
if (random.nextInt(100) < chanceSkeleton.getValue()) {
e.getDrops().add(new ItemStack(Material.SKELETON_SKULL));
}
}
else if (e.getEntity() instanceof Creeper) {
if (random.nextInt(100) < chanceCreeper.getValue()) {
e.getDrops().add(new ItemStack(Material.CREEPER_HEAD));
}
}
else if (e.getEntity() instanceof Player && random.nextInt(100) < chancePlayer.getValue()) {
ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
ItemMeta meta = skull.getItemMeta();
((SkullMeta) meta).setOwningPlayer((Player) e.getEntity());
skull.setItemMeta(meta);
e.getDrops().add(skull);
}
};
}