下面列出了怎么用org.bukkit.entity.Silverfish的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler(priority = EventPriority.HIGHEST)
public void onHit(EntityDamageEvent event) {
if (event.isCancelled()) return;
if (!balrogList.contains(event.getEntity())) return;
if (event.getFinalDamage() < 2) return;
spawnTrashMobs((Silverfish) event.getEntity());
spawnTrashMobs((Silverfish) event.getEntity());
}
@Override
public boolean effect(Event event, Player player) {
// List<String> lore = e.getBow().getItemMeta().getLore();
// if(!lore.contains(placeHolder)) {
// for(int i = descriptionSize; i != 0; i--)
// lore.remove(i);
// e.getProjectile().setMetadata("ce." + this.getOriginalName(), new FixedMetadataValue(main, writeType(lore)));
// player.setMetadata("ce.CanUnleashBeasts", null);
// } else
// e.getProjectile().setMetadata("ce." + this.getOriginalName(), null);
if(event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
if(e.getDamager() != player)
return false;
Entity ent = e.getEntity();
Location loc = ent.getLocation();
World w = ent.getWorld();
if(ent instanceof Silverfish || ent instanceof EnderDragon || ent instanceof Spider || ent instanceof Slime || ent instanceof Ghast || ent instanceof MagmaCube || ent instanceof CaveSpider || (ent instanceof Wolf && ((Wolf) ent).isAngry()) || ent instanceof PigZombie) {
e.setDamage(e.getDamage()*DamageMultiplication);
w.playEffect(loc, Effect.SMOKE, 50);
w.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 50);
EffectManager.playSound(loc, "BLOCK_PISTON_RETRACT", 1.3f, 3f);
return true;
} else if (ent instanceof Player) {
for(int i = 0; i < MaximumMobs; i++) {
if(rand.nextInt(100) < MobAppearanceChance) {
w.spawnEntity(loc, rand.nextInt(2) == 1 ? EntityType.SPIDER : EntityType.SLIME);
w.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 30);
w.playEffect(loc, Effect.SMOKE, 30);
EffectManager.playSound(loc, "BLOCK_ANVIL_BREAK", 0.3f, 0.1f);
}
}
}
}
return false;
}
private static void balrogVisualEffectLoop(Silverfish balrog) {
new BukkitRunnable() {
@Override
public void run() {
if (!balrog.isValid()) {
cancel();
return;
}
balrog.getWorld().spawnParticle(Particle.FLAME, balrog.getLocation(), 2, 0.1, 0.1, 0.1, 0.05);
balrog.getWorld().spawnParticle(Particle.SMOKE_LARGE, balrog.getLocation(), 4, 0.1, 0.1, 0.1, 0.05);
}
}.runTaskTimer(MetadataHandler.PLUGIN, 0, 1);
}
private static void trashMobVisualEffect(Silverfish raug) {
new BukkitRunnable() {
@Override
public void run() {
if (!raug.isValid() || raug.isDead()) {
cancel();
return;
}
raug.getWorld().spawnParticle(Particle.SMOKE_LARGE, raug.getLocation(), 1, 0.1, 0.1, 0.1, 0.05);
}
}.runTaskTimer(MetadataHandler.PLUGIN, 1, 1);
}
private static void intializeBalrog(Location location) {
int eliteLevel = ActionDynamicBossLevelConstructor.determineDynamicBossLevel(location);
ActionBossMobEntity bossMobEntity = new ActionBossMobEntity(EntityType.SILVERFISH, location, eliteLevel, ConfigValues.eventsConfig.getString(EventsConfig.BALROG_NAME), CreatureSpawnEvent.SpawnReason.NATURAL);
balrogList.add(bossMobEntity.getLivingEntity());
balrogVisualEffectLoop((Silverfish) bossMobEntity.getLivingEntity());
BossMobDeathCountdown.startDeathCountdown(bossMobEntity.getLivingEntity());
}
private static void spawnTrashMobs(Silverfish balrog) {
TrashMobEntity trashMobEntity = new TrashMobEntity(EntityType.SILVERFISH, balrog.getLocation(),
ChatColorConverter.convert(ConfigValues.eventsConfig.getString(EventsConfig.BALROG_TRASH_MOB_NAME)));
trashMobVisualEffect((Silverfish) trashMobEntity.getLivingEntity());
}