private void forMelee(Creeper creeper) { Location lcreeper = creeper.getLocation(); LivingEntity player = creeper.getTarget(); Location lplayer = player.getLocation(); Vector vcreeper = new Vector(lcreeper.getX(), lcreeper.getY(), lcreeper.getZ()); Vector vplayer = new Vector(lplayer.getX(), lplayer.getY(), lplayer.getZ()); if (vplayer.isInSphere(vcreeper, 3d)) { switch (lplayer.getWorld().getDifficulty()) { case EASY: player.damage(3, creeper); case NORMAL: player.damage(4, creeper); case HARD: player.damage(6, creeper); } } }
/** On creeper death, drop fireworks and heads with a configurable chance. */ @EventHandler(ignoreCancelled = true) public void onCreeperDeath(EntityDeathEvent event) { if (!CONFIG.isAffectedWorld(event)) { return; } Entity entity = event.getEntity(); if (entity.getType() == EntityType.CREEPER && entity.hasMetadata(SPECIAL_KEY)) { Creeper creeper = (Creeper) entity; // Require recent player damage on the creeper for special drops. Long damageTime = getPlayerDamageTime(entity); if (damageTime != null) { Location loc = creeper.getLocation(); if (loc.getWorld().getFullTime() - damageTime < PLAYER_DAMAGE_TICKS) { if (Math.random() < CONFIG.FIREWORK_DROP_CHANCE) { // Replace the default drops. event.getDrops().clear(); final int amount = random(CONFIG.MIN_FIREWORK_DROPS, CONFIG.MAX_FIREWORK_DROPS); for (int i = 0; i < amount; ++i) { ItemStack firework = new ItemStack(Material.FIREWORK); FireworkMeta meta = (FireworkMeta) firework.getItemMeta(); meta.setPower(random(0, 3)); meta.addEffect(randomFireworkFffect(false)); firework.setItemMeta(meta); event.getDrops().add(firework); } } // Powered creepers may drop a creeper skull in addition to // fireworks. if (creeper.isPowered() && Math.random() < CONFIG.CHARGED_CREEPER_SKULL_CHANCE) { event.getDrops().add(new ItemStack(Material.SKULL_ITEM, 1, (short) 4)); } } } } } // onCreeperDeath