@EventHandler(priority = EventPriority.NORMAL) private void onProjectileHit(ProjectileHitEvent evt) { if (!(evt.getEntity() instanceof Arrow)) { return; } Arrow arrow = (Arrow) evt.getEntity(); if (arrow.hasMetadata("rocket")) { plugin .getServer() .getWorld("world") .createExplosion( arrow.getLocation().getX(), arrow.getLocation().getY(), arrow.getLocation().getZ(), 7, false, false); for (Entity nearby : arrow.getNearbyEntities(3, 3, 3)) { if (!(nearby instanceof Player)) { return; } Player player = (Player) nearby; if (player == (Player) arrow.getShooter()) { player.damage(2, arrow.getShooter()); } else { player.damage(8, arrow.getShooter()); } } plugin.getArrowsFired().remove(evt.getEntity()); arrow.remove(); } }
// when a vehicle is damaged @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onVehicleDamage(VehicleDamageEvent event) { // all of this is anti theft code if (!GriefPrevention.instance.config_claims_preventTheft) return; // determine which player is attacking, if any Player attacker = null; Entity damageSource = event.getAttacker(); if (damageSource instanceof Player) { attacker = (Player) damageSource; } else if (damageSource instanceof Arrow) { Arrow arrow = (Arrow) damageSource; if (arrow.getShooter() instanceof Player) { attacker = (Player) arrow.getShooter(); } } else if (damageSource instanceof ThrownPotion) { ThrownPotion potion = (ThrownPotion) damageSource; if (potion.getShooter() instanceof Player) { attacker = (Player) potion.getShooter(); } } // NOTE: vehicles can be pushed around. // so unless precautions are taken by the owner, a resourceful thief might find ways to steal // anyway Claim cachedClaim = null; PlayerData playerData = null; if (attacker != null) { playerData = this.dataStore.getPlayerData(attacker.getName()); cachedClaim = playerData.lastClaim; } Claim claim = this.dataStore.getClaimAt(event.getVehicle().getLocation(), false, cachedClaim); // if it's claimed if (claim != null) { // if damaged by anything other than a player, cancel the event if (attacker == null) { event.setCancelled(true); } // otherwise the player damaging the entity must have permission else { String noContainersReason = claim.allowContainers(attacker); if (noContainersReason != null) { event.setCancelled(true); GriefPrevention.sendMessage( attacker, TextMode.Err, Messages.NoDamageClaimedEntity, claim.getOwnerName()); } // cache claim for later if (playerData != null) { playerData.lastClaim = claim; } } } }
@EventHandler public void onProjectileHit(ProjectileHitEvent projectile) { Heroes.debug.startTask("HeroesSkillListener"); if (!(projectile.getEntity() instanceof Arrow)) { Heroes.debug.stopTask("HeroesSkillListener"); return; } Arrow arrow = (Arrow) projectile.getEntity(); if (!(arrow.getShooter() instanceof Player)) { Heroes.debug.stopTask("HeroesSkillListener"); return; } Player player = (Player) arrow.getShooter(); Hero hero = SkillExplodingArrow.this.plugin.getCharacterManager().getHero(player); if (!hero.hasEffect("ExplodingArrowBuff")) { Heroes.debug.stopTask("HeroesSkillListener"); return; } int radius = (int) Math.pow( SkillConfigManager.getUseSetting(hero, this.skill, "radius", 5, false), 2.0D); float damage = SkillConfigManager.getUseSetting(hero, this.skill, "DAMAGE", 5, false); float blockdamage = damage; int block_dmg = SkillConfigManager.getUseSetting(hero, this.skill, "block-dmg", 0, false); if (block_dmg == 0) { blockdamage = 0.0F; for (Entity t_entity : player.getWorld().getEntities()) { if ((t_entity instanceof Player)) { Player heroes = (Player) t_entity; if ((heroes.equals(player)) || (heroes.getLocation().distanceSquared(arrow.getLocation()) > radius)) continue; damageEntity( heroes, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION); } else if ((t_entity instanceof Creature)) { Creature mob = (Creature) t_entity; if (t_entity.getLocation().distanceSquared(arrow.getLocation()) <= radius) { damageEntity( mob, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION); } } } } arrow.getWorld().createExplosion(arrow.getLocation(), blockdamage); Heroes.debug.stopTask("HeroesSkillListener"); }
@EventHandler public void onPlayerShotEvent(EntityDamageByEntityEvent event) { if (event.getDamager() instanceof Arrow) { Arrow arrow = (Arrow) event.getDamager(); if (arrow.getShooter() instanceof Player) { Player player = (Player) arrow.getShooter(); if (event.getEntity().equals(player)) { event.setCancelled(true); } } } }
// @EventHandler(priority = EventPriority.NORMAL) public void explodingArrow(ProjectileHitEvent event) { Entity projectile = event.getEntity(); World w = projectile.getWorld(); Location hit = projectile.getLocation(); if (w.getName().equals(name)) { if (projectile instanceof Arrow) { Arrow arrow = (Arrow) projectile; Entity shooter = arrow.getShooter(); Location l = shooter.getLocation(); Block bl = l.getBlock(); Block b = bl.getRelative(BlockFace.DOWN, 2); Material mat = b.getType(); if (shooter instanceof Player) { Player p = (Player) shooter; ItemStack is = p.getItemInHand(); Material i = is.getType(); if (i == Material.BOW && mat == Material.SPONGE) { p.getInventory().removeItem(new ItemStack(Material.ARROW, 20)); w.createExplosion(hit, 8); int strikes = 0; while (strikes < 20) { strikes++; w.strikeLightning(hit); } } Bukkit.getWorld(name).playEffect(arrow.getLocation(), Effect.STEP_SOUND, 10); } } } }
/* (non-Javadoc) * @see org.bukkit.event.entity.EntityListener#onProjectileHit(org.bukkit.event.entity.ProjectileHitEvent) */ @EventHandler public void onProjectileHit(ProjectileHitEvent event) { if (event.getEntity() instanceof Arrow) { // The projectile is an arrow. Location loc = event.getEntity().getLocation(); Arrow arrow = (Arrow) event.getEntity(); if (arrow.getShooter() instanceof Player) { // Arrow was shot by a player. Player player = (Player) arrow.getShooter(); if (randomGenerator.nextInt(100) < plugin.getConfig().getInt("ChanceOfLighting", 10) && player.hasPermission("LightningArrow.use")) { // Lucky player that has permission. event.getEntity().getWorld().strikeLightning(loc); } } } }
@EventHandler(priority = EventPriority.HIGH) public void removeItemFromFrame(EntityDamageByEntityEvent event) { Entity victim = event.getEntity(); if (!victim.getType().equals(EntityType.ITEM_FRAME)) { return; } Player p; Entity attacker = event.getDamager(); // System.out.println("Attacker: "+attacker.getType().toString()); if (attacker.getType().toString().equals("PLAYER")) { p = (Player) attacker; OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation()); if (land == null) { return; } if (!land.hasPermTo(p, this)) { p.sendMessage( ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveWithMelee")); event.setCancelled(true); } } else if (attacker.getType().toString().equals("ARROW")) { Arrow a = (Arrow) attacker; if (a.getShooter() instanceof Player) { p = (Player) a.getShooter(); } else { return; } OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation()); if (land == null) { return; } if (!land.hasPermTo(p, this)) { p.sendMessage( ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveWithArrow")); event.setCancelled(true); } } }
@EventHandler(priority = EventPriority.HIGHEST) private void onProjectileLaunch(ProjectileLaunchEvent evt) { if (evt.getEntity() instanceof Arrow) { Arrow arrow = (Arrow) evt.getEntity(); if (arrow.getShooter() instanceof Player) { Player shooter = (Player) arrow.getShooter(); PlayerDataClass shooterData = plugin.getPlayerHandler().findPlayer(shooter.getDisplayName()); if (shooterData != null) { if (shooter.getInventory().contains(Material.ARROW)) { if (shooterData.getType().equalsIgnoreCase("sniper") && arrow.hasMetadata("charged")) { evt.setCancelled(true); // shooter.getInventory().removeItem(new ItemStack (Material.ARROW, 1)); // shooter.updateInventory(); // ItemStack is = shooter.getInventory().getItem(Material.ARROW.getId()); // is.setAmount(is.getAmount() - 1); // shooter.getInventory().setItem(Material.ARROW.getId(), is); // Location loc = shooter.getLocation(); // loc.add(0,1,0); Location arrowLocation = shooter.getEyeLocation(); arrowLocation.setY(arrowLocation.getY() + 0.1); Arrow sniperArrow = shooter .getWorld() .spawnArrow(arrowLocation, shooter.getLocation().getDirection(), 0.6f, 1); sniperArrow.setShooter(shooter); sniperArrow.setBounce(false); sniperArrow.setVelocity( shooter.getLocation().getDirection().normalize().multiply(10)); } if (shooterData.getType().equalsIgnoreCase("soldier")) { arrow.setMetadata("rocket", new FixedMetadataValue(plugin, true)); ArrowDataClass arrowData = new ArrowDataClass(); arrowData.setArrow(arrow); arrow.setTicksLived(30); arrowData.setVector(shooter.getLocation().getDirection()); plugin.getArrowsFired().add(arrowData); } } } } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void antiArrowSpam(ProjectileHitEvent event) { // Destroys the Arrows of the Minigun if (event.getEntityType().equals(EntityType.ARROW)) { Arrow arrow = (Arrow) event.getEntity(); ProjectileSource shooter = arrow.getShooter(); if (shooter instanceof Player) if (arrow.hasMetadata("ce.minigunarrow")) if (((Player) shooter).getGameMode().equals(GameMode.CREATIVE)) arrow.remove(); } }
@EventHandler public void onArrowHit(ProjectileHitEvent e) { if (e.getEntity() instanceof Arrow) { Arrow a = (Arrow) e.getEntity(); if (a.getShooter() instanceof Player) { Player p = (Player) a.getShooter(); if (plugin.getArenaManager().isInGame(p)) { if (plugin.ab.getAbilities().containsKey(p)) { if (plugin.ab.getAbilities().get(p).contains("explosive_arrows")) { World w = e.getEntity().getWorld(); Location loc = e.getEntity().getLocation(); if (plugin.prot.isInProtectedArena(loc)) { w.createExplosion(loc.getX(), loc.getY(), loc.getZ(), 1.18F, false, false); a.remove(); } } } } } } }
@EventHandler(priority = EventPriority.HIGH) public void destroyArmorStand(EntityDamageByEntityEvent event) { Entity victim = event.getEntity(); // System.out.println("Victim: "+victim); if (!victim.getType().equals(EntityType.ARMOR_STAND)) { return; } OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation()); if (land == null) { return; } if (event.getDamager().getType().equals(EntityType.PLAYER)) { Player attacker = (Player) event.getDamager(); // System.out.println(attacker.getName()); if (!land.hasPermTo(attacker, this)) { attacker.sendMessage( ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.breakArmorStandWithMelee")); event.setCancelled(true); } } if (event.getDamager().getType().equals(EntityType.ARROW)) { Arrow projectile = (Arrow) event.getDamager(); if (projectile.getShooter() instanceof Player) { Player attacker = (Player) projectile.getShooter(); if (!land.hasPermTo(attacker, this)) { attacker.sendMessage( ChatColor.RED + getPlugin() .getMessageConfig() .getString("event.build.breakArmorStandWithArrow")); event.setCancelled(true); } } } // System.out.println(event.getDamager().getType()); }
// Create damage logs @EventHandler(priority = EventPriority.MONITOR) public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if (!(event.getEntity() instanceof Player)) return; Player player = (Player) event.getEntity(); Player damager = null; if (event.getDamager() instanceof Player) { damager = (Player) event.getDamager(); } else if (event.getDamager() instanceof Wolf) { Wolf wolf = (Wolf) event.getDamager(); if (wolf.getOwner() instanceof Player) damager = (Player) wolf.getOwner(); } else if (event.getDamager() instanceof Arrow) { Arrow arrow = (Arrow) event.getDamager(); if (!(arrow.getShooter() instanceof Player)) return; damager = (Player) arrow.getShooter(); } if (damager == null || damager == player) return; recordDamage(player, damager, event.getDamage()); }
// Disable GM/GOD PVP @EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if (event.getEntity() instanceof Player) { if (event.getDamager() instanceof Player) { Player player = (Player) event.getDamager(); if (player.getGameMode() == GameMode.CREATIVE || FOPM_TFM_Util.inGod(player)) { TFM_Util.playerMsg(player, "NO GM / GOD PVP!", ChatColor.DARK_RED); event.setCancelled(true); } } if (event.getDamager() instanceof Arrow) { Arrow arrow = (Arrow) event.getDamager(); if (arrow.getShooter() instanceof Player) { Player player = (Player) arrow.getShooter(); if (player.getGameMode() == GameMode.CREATIVE || FOPM_TFM_Util.inGod(player)) { TFM_Util.playerMsg(player, "NO GM / GOD PVP!", ChatColor.DARK_RED); event.setCancelled(true); } } } } }
@Override public void onDefense(EntityDamageByEntityEvent event) { double damage = event.getDamage(); damage -= this.defense; if (damage < 0.5) { damage = 0.0; Player player = null; if (event.getDamager() instanceof Arrow) { Arrow arrow = (Arrow) event.getDamager(); if (arrow.getShooter() instanceof Player) { player = (Player) arrow.getShooter(); } } else if (event.getDamager() instanceof Player) { player = (Player) event.getDamager(); } if (player != null) { CivMessage.send(player, CivColor.LightGray + "Our attack was ineffective"); } } event.setDamage(damage); }
/** Damage * */ @EventHandler public void onDamageByEntity(EntityDamageByEntityEvent e) { if (e.getEntity() instanceof Chicken) { if (e.getDamager() instanceof Arrow) { /** Arrow * */ Arrow a = (Arrow) e.getDamager(); if (a.getShooter() instanceof Player) { /** Player * */ Player p = (Player) a.getShooter(); /** Remove from list * */ if (chickens.contains(e.getEntity())) chickens.remove(e.getEntity()); /** Remove * */ e.getEntity().remove(); /** Give player point * */ points.put(p.getName(), points.get(p.getName()) + 1); /** Play sound * */ p.playSound(p.getLocation(), Sound.NOTE_PLING, 1, 3); /** Title * */ Util.sendTitle(p, 5, 10, 5, "", "Getroffen!"); /** Level and exp * */ p.setLevel(points.get(p.getName())); p.setExp((1f / 15) * points.get(p.getName())); /** Check win * */ checkWin(); } } } }
@EventHandler(priority = EventPriority.HIGHEST) private void onPlayerDamage(EntityDamageByEntityEvent evt) { if (evt.getEntity() instanceof Player && evt.getDamager() instanceof Player) { Player player = (Player) evt.getEntity(); PlayerDataClass playerData = plugin.getPlayerHandler().findPlayer(player.getDisplayName()); Player attacker = (Player) evt.getDamager(); PlayerDataClass attackerData = plugin.getPlayerHandler().findPlayer(attacker.getDisplayName()); if (attackerData != null && playerData != null) { if (attackerData.getTeam() == playerData.getTeam()) { evt.setCancelled(true); return; } if (attackerData.getType().equals("spy")) { plugin.getLogger().info("Logged knife stab"); if (plugin .getUtilities() .checkPlayerInCone( player, attacker.getLocation(), 4, 80, (int) attacker.getLocation().getYaw())) { plugin.getLogger().info(attackerData.getName() + " behind " + playerData.getName()); } } } else { evt.setCancelled(true); } } if (evt.getDamager() instanceof Arrow) { Arrow arrow = (Arrow) evt.getDamager(); Player attacker = (Player) arrow.getShooter(); PlayerDataClass attackerData = plugin.getPlayerHandler().findPlayer(attacker.getDisplayName()); Player player = (Player) evt.getEntity(); PlayerDataClass playerData = plugin.getPlayerHandler().findPlayer(player.getDisplayName()); if (attackerData != null && playerData != null) { if (attackerData.getTeam() == playerData.getTeam()) { evt.setCancelled(true); } } } }
public double prepareAttacker(EntityDamageByEntityEvent e) { // Variable Declarations/Initializations Arrow arrow = null; List<Spell> spellBook = null; double damage = 0; rpgMobAttacker = null; // Determine what the source of damage was. if (e.getDamager() instanceof Egg) { cancelRpgDamage = true; return 0; } else if (e.getDamager() instanceof Fish) { cancelRpgDamage = true; return 0; } else if (e.getDamager() instanceof Snowball) { cancelRpgDamage = true; return 0; } else if (e.getDamager() instanceof Fireball) { boolean success = false; Fireball fb = (Fireball) (e.getDamager()); if (fb.getShooter() == e.getEntity()) { cancelRpgDamage = true; return 0; } if (e.getEntity() instanceof Fireball || e.getEntity() instanceof LargeFireball) { cancelRpgDamage = true; return 0; } for (RpgPlayer rpgPlayer : FC_Rpg.rpgEntityManager.getOnlineRpgPlayers()) { if (rpgPlayer.summon_Owns(e.getDamager())) { // Variable Initializations rpgAttacker = rpgPlayer; spellBook = rpgAttacker.playerConfig.getRpgClass().getSpellBook(); damageType = 2; for (int i = 0; i < spellBook.size(); i++) { if (spellBook.get(i).effectID == SpellEffect.FIREBALL.getID()) { SpellCaster sc = new SpellCaster(); damage = sc.updatefinalSpellMagnitude( rpgAttacker, spellBook.get(i), (rpgAttacker.playerConfig.getSpellLevels().get(i) - 1)); break; } } success = true; break; } } if (success == false) { cancelRpgDamage = true; return 0; } } else if (e.getDamager() instanceof Arrow) { // Set damage type to arrow damageType = 1; // Store the arrow. arrow = (Arrow) e.getDamager(); // If the player shot the arrow, set damage to player stuff. if (arrow.getShooter() instanceof Player) { // Store the attacker playerAttacker = (Player) arrow.getShooter(); rpgAttacker = FC_Rpg.rpgEntityManager.getRpgPlayer(playerAttacker); } else { // Set the creature attacker. creatureAttacker = arrow.getShooter(); // Get the shooter entity monster and store. rpgMobAttacker = FC_Rpg.rpgEntityManager.getRpgMonster(arrow.getShooter()); // Set the damage to the monsters strength. if (rpgMobAttacker != null) damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack(); } // Remove all arrows. arrow.remove(); } else if (e.getDamager() instanceof LightningStrike) { // Initialize rpgMobAttacker; rpgMobAttacker = new RpgMonster(); damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack(); } // Melee player attacks else if (e.getDamager() instanceof Player) { // Store the attacker playerAttacker = (Player) e.getDamager(); rpgAttacker = FC_Rpg.rpgEntityManager.getRpgPlayer(playerAttacker); } // If the entity is a living entity we want to store it. else if (e.getDamager() instanceof LivingEntity) { // Set creature attacker. creatureAttacker = (LivingEntity) e.getDamager(); // Initialize rpgMobAttacker; rpgMobAttacker = FC_Rpg.rpgEntityManager.getRpgMonster(creatureAttacker); damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack(); if (creatureAttacker.getEquipment().getItemInHand() != null) damage = damage * FC_Rpg.battleCalculations.getWeaponModifier( creatureAttacker.getEquipment().getItemInHand(), 999999); } // Else if not it's an error and return the monster strength. else { FC_Rpg.plugin .getLogger() .info("Error: PrepareAttacker(), undefined entity type: " + e.getDamager().toString()); // Initialize rpgMobAttacker; rpgMobAttacker = new RpgMonster(); damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack(); } // Cancel damage for stunned stuff. if (rpgAttacker != null) { // If disabled cancel attack if (rpgAttacker.playerConfig.getStatusActiveRpgPlayer(SpellEffect.DISABLED.getID())) { cancelRpgDamage = true; return 0; } // Set damage of arrows. damage = rpgAttacker.getTotalAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack(); // Add weapon Bonus damage *= FC_Rpg.battleCalculations.getWeaponModifier( playerAttacker.getItemInHand(), rpgAttacker.getTotalAttack()); // If the player has the attack buff, then... if (rpgAttacker.playerConfig.getStatusActiveRpgPlayer(SpellEffect.DAMAGE_BONUS.getID())) damage *= rpgAttacker.playerConfig.getStatusMagnitude(SpellEffect.DAMAGE_BONUS.getID()); } else if (rpgMobAttacker != null) { if (rpgMobAttacker.getStatusActiveEntity(rpgMobAttacker.getStatusDisabled())) { cancelRpgDamage = true; return 0; } } else if (rpgAttacker == null) { MessageLib msgLib = new MessageLib(playerAttacker); msgLib.standardMessage("You need to pick a class before you can fight."); cancelRpgDamage = true; return 0; } return damage; }
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { Entity att = event.getDamager(); if (att instanceof Player) { Player attacker = (Player) att; if (plugin.isInArena(attacker)) { ItemStack itm = attacker.getItemInHand(); itm.setDurability((short) 0); } } if (!(event.getEntity() instanceof Player)) return; Player defender = (Player) event.getEntity(); if (!(att instanceof Player)) { if (att instanceof LivingEntity) { LivingEntity attacker = (LivingEntity) att; if (plugin.isInArena(attacker.getLocation())) { if (plugin.isInArena(defender.getLocation())) { event.setCancelled(false); } } } if (att instanceof Arrow) { Arrow attacker = (Arrow) att; if (attacker.getShooter() instanceof Player) { Player shooter = (Player) attacker.getShooter(); if ((plugin.isInArena(defender)) && (plugin.isInArena(shooter))) { event.setCancelled(false); Arena a = plugin.getArena(defender); if (shooter.getItemInHand().getType().equals(Material.BOW)) { shooter.getItemInHand().setDurability((short) 0); } if (plugin.getArenaPlayer(defender).team == plugin.getArenaPlayer(shooter).team) { if (!a.allowTeamKilling) { event.setCancelled(true); shooter.sendMessage(ChatColor.RED + "你不能伤到你的队友!"); } } } } return; } if (att instanceof Snowball) { Snowball attacker = (Snowball) att; if (attacker.getShooter() instanceof Player) { Player shooter = (Player) attacker.getShooter(); if ((plugin.isInArena(defender)) && (plugin.isInArena(shooter))) { event.setCancelled(false); Arena a = plugin.getArena(defender); if (plugin.getArenaPlayer(defender).team == plugin.getArenaPlayer(shooter).team) { if (!a.allowTeamKilling) { event.setCancelled(true); shooter.sendMessage(ChatColor.RED + "你不能伤到你的队友!"); } } } } return; } return; } else { Player attacker = (Player) att; if ((plugin.isInArena(defender)) && (plugin.isInArena(attacker))) { event.setCancelled(false); Arena a = plugin.getArena(defender); if (a.starttimer >= 0) { event.setCancelled(true); return; } if (plugin.getArenaPlayer(defender).team == plugin.getArenaPlayer(attacker).team) { if (!a.allowTeamKilling) { event.setCancelled(true); if (attacker.getItemInHand().getType().equals(Material.GOLD_AXE)) { defender.setHealth(defender.getHealth() + 2); attacker.sendMessage( ChatColor.GRAY + "你治愈了 " + ChatColor.GOLD + defender.getName() + ChatColor.GRAY + " 1颗心"); } else { attacker.sendMessage(ChatColor.RED + "你不能伤到你的队友!"); } } } } } }
@EventHandler public void onDamage(EntityDamageEvent ede) { if (!(ede.getEntity() instanceof Player)) { if (!(ede instanceof EntityDamageByEntityEvent)) { return; } EntityDamageByEntityEvent edbee = (EntityDamageByEntityEvent) ede; if (edbee.getDamager() == null || !(edbee.getDamager() instanceof Player)) { return; } Player player = (Player) edbee.getDamager(); Game game = Main.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() == GameState.WAITING) { ede.setCancelled(true); } return; } Player p = (Player) ede.getEntity(); Game g = Main.getInstance().getGameManager().getGameOfPlayer(p); if (g == null) { return; } if (g.getState() == GameState.STOPPED) { return; } if (g.getState() == GameState.RUNNING) { if (g.isSpectator(p)) { ede.setCancelled(true); return; } if (g.isProtected(p) && ede.getCause() != DamageCause.VOID) { ede.setCancelled(true); return; } if (Main.getInstance().getBooleanConfig("die-on-void", false) && ede.getCause() == DamageCause.VOID) { ede.setCancelled(true); p.setHealth(0); return; } if (ede instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent edbee = (EntityDamageByEntityEvent) ede; if (edbee.getDamager() instanceof Player) { Player damager = (Player) edbee.getDamager(); if (g.isSpectator(damager)) { ede.setCancelled(true); return; } g.setPlayerDamager(p, damager); } else if (edbee.getDamager().getType().equals(EntityType.ARROW)) { Arrow arrow = (Arrow) edbee.getDamager(); if (arrow.getShooter() instanceof Player) { Player shooter = (Player) arrow.getShooter(); if (g.isSpectator(shooter)) { ede.setCancelled(true); return; } g.setPlayerDamager(p, (Player) arrow.getShooter()); } } } if (!g.getCycle().isEndGameRunning()) { return; } else if (ede.getCause() == DamageCause.VOID) { p.teleport(g.getPlayerTeam(p).getSpawnLocation()); } } else if (g.getState() == GameState.WAITING) { if (ede.getCause() == EntityDamageEvent.DamageCause.VOID) { p.teleport(g.getLobby()); } } ede.setCancelled(true); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityDeath(EntityDeathEvent event) { Entity victimEntity = event.getEntity(); EntityDamageEvent lastDamageEvent = victimEntity.getLastDamageCause(); if (lastDamageEvent == null) return; if (victimEntity instanceof Player) { Player victim = (Player) victimEntity; if (Util.isExempt(victim)) return; if (lastDamageEvent instanceof EntityDamageByEntityEvent) { // + Player killed by entity Entity killerEntity = ((EntityDamageByEntityEvent) lastDamageEvent).getDamager(); if (killerEntity instanceof Arrow) { // | + Victim was shot Arrow arrow = (Arrow) killerEntity; if (arrow.getShooter() instanceof Player) { // | | + Player shot Player Player killer = (Player) arrow.getShooter(); if (Util.isExempt(killer)) return; VaultHook.transfer(victim, killer, Util.getPVPAmount(victim)); Message.send( killer, Settings.Message.KilledPlayer.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<PLAYER>", victim.getPlayerListName())); Message.send( victim, Settings.Message.KilledByPlayer.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<PLAYER>", killer.getPlayerListName())); } else if (arrow.getShooter() instanceof Creature) { // | | + Creature shot Player VaultHook.withdraw(victim, Util.getPVELoss(victim)); } } else if (killerEntity instanceof Player) { // | + Player killed Player Player killer = (Player) killerEntity; if (Util.isExempt(killer)) return; VaultHook.transfer(victim, killer, Util.getPVPAmount(victim)); Message.send( killer, Settings.Message.KilledPlayer.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<PLAYER>", victim.getPlayerListName())); Message.send( victim, Settings.Message.KilledByPlayer.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<PLAYER>", killer.getPlayerListName())); } else if (killerEntity instanceof Explosive) { // | + Player exploded VaultHook.withdraw(victim, Util.getOtherAmount(victim)); Message.send( victim, Settings.Message.KilledByWorld.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "")); } else if (killerEntity instanceof Creature) { // | + Creature killed Player VaultHook.withdraw(victim, Util.getPVELoss(victim)); Message.send( victim, Settings.Message.KilledByMob.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } else if (killerEntity instanceof Slime) { // | + Slime killed player VaultHook.withdraw(victim, Util.getPVELoss(victim)); Message.send( victim, Settings.Message.KilledByMob.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } else { // | + Player died VaultHook.withdraw(victim, Util.getOtherAmount(victim)); Message.send( victim, Settings.Message.KilledByWorld.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "")); } } else if (lastDamageEvent instanceof EntityDamageByBlockEvent) { // + Player killed by blocks VaultHook.withdraw(victim, Util.getOtherAmount(victim)); Message.send( victim, Settings.Message.KilledByWorld.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "")); } else { // + Player died VaultHook.withdraw(victim, Util.getOtherAmount(victim)); Message.send( victim, Settings.Message.KilledByWorld.getValue() .replace("<AMOUNT>", Util.getPVPAmount(victim) + "")); } } else { if (!(lastDamageEvent instanceof EntityDamageByEntityEvent)) return; Entity killerEntity = ((EntityDamageByEntityEvent) lastDamageEvent).getDamager(); if (killerEntity instanceof Arrow) { // + Player shot an entity Arrow arrow = (Arrow) killerEntity; if (!(arrow.getShooter() instanceof Player)) return; Player killer = (Player) arrow.getShooter(); if (victimEntity instanceof Creature) { // | + Player shot Creature Creature victim = (Creature) victimEntity; VaultHook.deposit(killer, Util.getPVEGain(killer, victim)); Message.send( killer, Settings.Message.KilledMob.getValue() .replace("<AMOUNT>", Util.getPVEGain(killer, victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } else if (victimEntity instanceof Slime) { // | + Player shot Slime Creature victim = (Creature) victimEntity; VaultHook.deposit(killer, Util.getPVEGain(killer, victim)); Message.send( killer, Settings.Message.KilledMob.getValue() .replace("<AMOUNT>", Util.getPVEGain(killer, victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } } else if (killerEntity instanceof Player) { // + Player killed an entity Player killer = (Player) killerEntity; if (victimEntity instanceof Creature) { // | + Player killed Creature Creature victim = (Creature) victimEntity; VaultHook.deposit(killer, Util.getPVEGain(killer, victim)); Message.send( killer, Settings.Message.KilledMob.getValue() .replace("<AMOUNT>", Util.getPVEGain(killer, victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } else if (victimEntity instanceof Slime) { // | + Player killed Slime Creature victim = (Creature) victimEntity; VaultHook.deposit(killer, Util.getPVEGain(killer, victim)); Message.send( killer, Settings.Message.KilledMob.getValue() .replace("<AMOUNT>", Util.getPVEGain(killer, victim) + "") .replace("<MOB>", killerEntity.getType().getName())); } } } }
// when an entity is damaged @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onEntityDamage(EntityDamageEvent event) { // only actually interested in entities damaging entities (ignoring environmental damage) if (!(event instanceof EntityDamageByEntityEvent)) return; // monsters are never protected if (event.getEntity() instanceof Monster) return; EntityDamageByEntityEvent subEvent = (EntityDamageByEntityEvent) event; // determine which player is attacking, if any Player attacker = null; Entity damageSource = subEvent.getDamager(); if (damageSource instanceof Player) { attacker = (Player) damageSource; } else if (damageSource instanceof Arrow) { Arrow arrow = (Arrow) damageSource; if (arrow.getShooter() instanceof Player) { attacker = (Player) arrow.getShooter(); } } else if (damageSource instanceof ThrownPotion) { ThrownPotion potion = (ThrownPotion) damageSource; if (potion.getShooter() instanceof Player) { attacker = (Player) potion.getShooter(); } } // if the attacker is a player and defender is a player (pvp combat) if (attacker != null && event.getEntity() instanceof Player) { // FEATURE: prevent pvp in the first minute after spawn, and prevent pvp when one or both // players have no inventory // doesn't apply when the attacker has the no pvp immunity permission // this rule is here to allow server owners to have a world with no spawn camp protection by // assigning permissions based on the player's world if (attacker.hasPermission("griefprevention.nopvpimmunity")) return; Player defender = (Player) (event.getEntity()); PlayerData defenderData = this.dataStore.getPlayerData(((Player) event.getEntity()).getName()); PlayerData attackerData = this.dataStore.getPlayerData(attacker.getName()); // otherwise if protecting spawning players if (GriefPrevention.instance.config_pvp_protectFreshSpawns) { if (defenderData.pvpImmune) { event.setCancelled(true); GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.ThatPlayerPvPImmune); return; } if (attackerData.pvpImmune) { event.setCancelled(true); GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.CantFightWhileImmune); return; } } // FEATURE: prevent players who very recently participated in pvp combat from hiding inventory // to protect it from looting // FEATURE: prevent players who are in pvp combat from logging out to avoid being defeated long now = Calendar.getInstance().getTimeInMillis(); defenderData.lastPvpTimestamp = now; defenderData.lastPvpPlayer = attacker.getName(); attackerData.lastPvpTimestamp = now; attackerData.lastPvpPlayer = defender.getName(); } // FEATURE: protect claimed animals, boats, minecarts // NOTE: animals can be lead with wheat, vehicles can be pushed around. // so unless precautions are taken by the owner, a resourceful thief might find ways to steal // anyway // if theft protection is enabled if (event instanceof EntityDamageByEntityEvent) { // if the entity is an non-monster creature (remember monsters disqualified above), or a // vehicle if ((subEvent.getEntity() instanceof Creature && GriefPrevention.instance.config_claims_protectCreatures)) { Claim cachedClaim = null; PlayerData playerData = null; if (attacker != null) { playerData = this.dataStore.getPlayerData(attacker.getName()); cachedClaim = playerData.lastClaim; } Claim claim = this.dataStore.getClaimAt(event.getEntity().getLocation(), false, cachedClaim); // if it's claimed if (claim != null) { // if damaged by anything other than a player, cancel the event if (attacker == null) { event.setCancelled(true); } // otherwise the player damaging the entity must have permission else { String noContainersReason = claim.allowContainers(attacker); if (noContainersReason != null) { event.setCancelled(true); GriefPrevention.sendMessage( attacker, TextMode.Err, Messages.NoDamageClaimedEntity, claim.getOwnerName()); } // cache claim for later if (playerData != null) { playerData.lastClaim = claim; } } } } } }
// -1, false, false are defaults, attackmob and attack player are only processed when damage = -1. public void entityAttack(EntityDamageByEntityEvent ed, double customDamage) { double damage = 0; event = ed; // Reset all globals. setGlobalDefaults(); // Set event damage to 0. ed.setDamage(0); LivingEntity entity; Entity eEntity = ed.getEntity(); if (eEntity instanceof Arrow) { Arrow ca = (Arrow) eEntity; entity = ca.getShooter(); } else if (eEntity instanceof LargeFireball) { LargeFireball cf = (LargeFireball) eEntity; entity = cf.getShooter(); } else if (eEntity instanceof ExperienceOrb) { return; } else if (eEntity instanceof Item) { return; } else { // Set entity equal to the entity that got hit. try { entity = (LivingEntity) ed.getEntity(); } catch (ClassCastException e) { FC_Rpg.plugin .getLogger() .info( "Failed to cast an entity to living entity, damage cancelled -> " + eEntity.toString() + " <- report to a FC_Rpg developer via a ticket please."); return; } } // Prepare the defender and attacker variables. prepareDefender(entity); // If a damage was passed in, then we don't want to set damage. Else, store new damage damage = prepareAttacker(ed); // When two players are fighting, then... boolean isPvp = false; // set whether in pvp or not. if (playerAttacker != null && playerDefender != null) isPvp = true; if (isPvp == true && cancelRpgDamage == true) { MessageLib msgLib = new MessageLib(playerAttacker); msgLib.standardMessage("This player can't be attacked currently."); return; } // Check player tiers. if (isPvp == true) { int attackerTier = getTier(rpgAttacker.playerConfig.getClassLevel()); int defenderTier = getTier(rpgDefender.playerConfig.getClassLevel()); if (attackerTier != defenderTier) { MessageLib msgLib = new MessageLib(playerAttacker); msgLib.infiniteMessage( "You can't fight this target because they are in tier ", defenderTier + "", " and you are in tier ", attackerTier + "", "!"); return; } } // If we are cancelling rpg damage, then return. if (cancelRpgDamage == true) return; if (customDamage > -1) damage = customDamage; /** * ********************************************************* * * <p>SET THE BASE DAMAGE BASED ON IF A PLAYER, MOB, OR ENVIROMENT CAUSED DAMAGE * * <p>********************************************************* */ // We do a sword check for atttackers. if (rpgAttacker != null) { // Check the attackers sword. rpgAttacker.swordAttackRequirementCheck(); // We handle spells on non-fireball player attacks. if (damageType != 2) { if (rpgAttacker.playerConfig.getAutoCast() == true) rpgAttacker.prepareSpell(false); double spellDamage = -1; // Attempt to cast a spell. if (rpgMobDefender != null) spellDamage = rpgAttacker.castSpell(rpgMobDefender.getEntity(), damage, damageType); else spellDamage = rpgAttacker.castSpell(rpgDefender.getPlayer(), damage, damageType); // If the spell failed to cast, then we want to do spells/enchantment stuff. if (spellDamage == -1) { // Cast auto spells/enchantment stuff. if (rpgMobDefender != null) spellDamage = rpgAttacker.autocastOffense(rpgMobDefender.getEntity(), damage); else spellDamage = rpgAttacker.autocastOffense(rpgDefender.getPlayer(), damage); } // If the spell damage isn't -1, then we want to store the spell damage. if (spellDamage != -1) damage = spellDamage; } } // Apply randomization to damage. damage = getRandomDamageModifier(damage); // We do a armor check for defenders. if (rpgDefender != null) { rpgDefender.fullArmorCheck(); // Cast armor enchantment stuff. rpgDefender.autocastDefense(); } if (rpgMobDefender != null) { // Prevent mobs from damaging friendly mobs. if (rpgMobAttacker != null) return; // If no player attacked, then we want to nuke the mob (enviromental damage). if (rpgAttacker == null) { edm.nukeMob(rpgMobDefender.getEntity()); return; } // Attack the mob defender if (edm.attackMobDefender(rpgMobDefender, rpgAttacker, damage, damageType) == false) { MessageLib msgLib = new MessageLib(playerAttacker); msgLib.standardMessage("Attack Missed."); } // Make creatures forcibly attack attacker. if (playerAttacker != null && mobDefender != null) { // Set wolves to angry. if (mobDefender instanceof Wolf) ((Wolf) mobDefender).setAngry(true); if (mobDefender instanceof Creature) { // Change aggro ((Creature) mobDefender).setTarget(playerAttacker); } } } else if (rpgDefender != null) { // Attack the player Defender. if (rpgAttacker != null) { if (edm.attackPlayerDefender( rpgDefender, rpgAttacker, null, damage, damageType, rpgAttacker.getPlayer().getName().substring(0, nameTrimEnd)) == false) { MessageLib msgLib = new MessageLib(playerAttacker); msgLib.standardMessage("Attack Missed."); } } else if (rpgMobAttacker != null) edm.attackPlayerDefender( rpgDefender, null, rpgMobAttacker, damage, damageType, rpgMobAttacker.getEntity().getType().toString()); } }
@Override public void run() { for (Location l : Storage.blackholes.keySet()) { for (Entity e : Utilities.getNearbyEntities(l, 10, 10, 10)) { if (e instanceof Player) { if (((Player) e).getGameMode().equals(CREATIVE)) { continue; } } if (Storage.blackholes.get(l)) { Vector v = l.clone().subtract(e.getLocation()).toVector(); v.setX(v.getX() + (-.5f + Storage.rnd.nextFloat()) * 10); v.setY(v.getY() + (-.5f + Storage.rnd.nextFloat()) * 10); v.setZ(v.getZ() + (-.5f + Storage.rnd.nextFloat()) * 10); e.setVelocity(v.multiply(.35f)); e.setFallDistance(0); } else { Vector v = e.getLocation().subtract(l.clone()).toVector(); v.setX(v.getX() + (-.5f + Storage.rnd.nextFloat()) * 2); v.setY(v.getY() + Storage.rnd.nextFloat()); v.setZ(v.getZ() + (-.5f + Storage.rnd.nextFloat()) * 2); e.setVelocity(v.multiply(.35f)); } } } // Arrows toRemove.clear(); for (Set<CustomArrow> pro : Storage.advancedProjectiles.values()) { for (CustomArrow a : pro) { a.onFlight(); a.tick++; if (a.entity.isDead() || a.tick > 600) { toRemove.add(a); } } } for (CustomArrow pro : toRemove) { Storage.advancedProjectiles.remove(pro.entity); pro.entity.remove(); } for (Block block : Storage.webs) { if (Storage.rnd.nextInt(175) == 0 && block.getChunk().isLoaded()) { block.setType(AIR); websToRemove.add(block); } } for (Block block : websToRemove) { Storage.webs.remove(block); } websToRemove.clear(); for (LivingEntity ent : Storage.derpingEntities) { Location loc = ent.getLocation(); loc.setYaw(Storage.rnd.nextFloat() * 360F); loc.setPitch(Storage.rnd.nextFloat() * 180F - 90F); ent.teleport(loc); } tick++; // Other stuff for (FallingBlock b : Storage.anthMobs2) { if (!Storage.anthVortex.contains(Storage.anthMobs.get(b))) { for (Entity e : b.getNearbyEntities(7, 7, 7)) { if (e instanceof LivingEntity) { LivingEntity lE = (LivingEntity) e; if (!(lE instanceof Player) && lE instanceof Monster) { b.setVelocity(e.getLocation().subtract(b.getLocation()).toVector().multiply(.25)); if (lE.getLocation().getWorld().equals(b.getLocation().getWorld())) { if (lE.getLocation().distance(b.getLocation()) < 1.2) { EntityDamageEvent evt = new EntityDamageEvent(lE, EntityDamageEvent.DamageCause.SUFFOCATION, 100); Bukkit.getPluginManager().callEvent(evt); lE.setLastDamageCause(evt); if (!evt.isCancelled()) { lE.damage(8f); } } } } } } } } boolean r = Storage.fallBool; Storage.fallBool = !Storage.fallBool; for (FallingBlock b : Storage.anthMobs.keySet()) { if (Storage.anthVortex.contains(Storage.anthMobs.get(b))) { Location loc = Storage.anthMobs.get(b).getLocation(); Vector v; if (b.getLocation().getWorld().equals(Storage.anthMobs.get(b).getLocation().getWorld())) { if (r && b.getLocation().distance(Storage.anthMobs.get(b).getLocation()) < 10) { v = b.getLocation().subtract(loc).toVector(); } else { int x = Storage.rnd.nextInt(12) - 6; int z = Storage.rnd.nextInt(12) - 6; Location tLoc = loc.clone(); tLoc.setX(tLoc.getX() + x); tLoc.setZ(tLoc.getZ() + z); v = tLoc.subtract(b.getLocation()).toVector(); } v.multiply(.05); boolean close = false; for (int x = -3; x < 0; x++) { if (b.getLocation().getBlock().getRelative(0, x, 0).getType() != AIR) { close = true; } } if (close) { v.setY(5); } else { v.setY(-.1); } b.setVelocity(v); } } } for (Arrow e : Storage.tracer.keySet()) { Entity close = null; double distance = 100; int level = Storage.tracer.get(e); level = level + 2; for (Entity e1 : e.getNearbyEntities(level, level, level)) { if (e1.getLocation().getWorld().equals(e.getLocation().getWorld())) { double d = e1.getLocation().distance(e.getLocation()); if (e.getLocation() .getWorld() .equals(((Entity) e.getShooter()).getLocation().getWorld())) { if (d < distance && e1 instanceof LivingEntity && !e1.equals(e.getShooter()) && e.getLocation().distance(((Entity) e.getShooter()).getLocation()) > 15) { distance = d; close = e1; } } } } if (close != null) { Location location = close.getLocation(); org.bukkit.util.Vector v = new org.bukkit.util.Vector(0D, 0D, 0D); Location pos = e.getLocation(); double its = Math.sqrt( (location.getBlockX() - pos.getBlockX()) * (location.getBlockX() - pos.getBlockX()) + (location.getBlockY() - pos.getBlockY()) * (location.getBlockY() - pos.getBlockY()) + (location.getBlockZ() - pos.getBlockZ()) * (location.getBlockZ() - pos.getBlockZ())); if (its == 0) { its = (double) 1; } v.setX((location.getBlockX() - pos.getBlockX()) / its); v.setY((location.getBlockY() - pos.getBlockY()) / its); v.setZ((location.getBlockZ() - pos.getBlockZ()) / its); e.setVelocity(v.multiply(2)); } } for (Guardian g : Storage.guardianMove.keySet()) { if (g.getLocation().distance(Storage.guardianMove.get(g).getLocation()) > 2 && g.getTicksLived() < 160) { g.setVelocity( Storage.guardianMove .get(g) .getLocation() .toVector() .subtract(g.getLocation().toVector())); } else { Storage.guardianMove.remove(g); } } for (Player player : Bukkit.getOnlinePlayers()) { Config config = Config.get(player.getWorld()); for (ItemStack stk : player.getInventory().getArmorContents()) { HashMap<CustomEnchantment, Integer> map = config.getEnchants(stk); for (CustomEnchantment ench : map.keySet()) { ench.onFastScan(player, map.get(ench)); } } HashMap<CustomEnchantment, Integer> map = config.getEnchants(player.getItemInHand()); for (CustomEnchantment ench : map.keySet()) { ench.onFastScanHand(player, map.get(ench)); } } HashSet<Player> toDelete = new HashSet<>(); for (Player player : Storage.hungerPlayers.keySet()) { if (Storage.hungerPlayers.get(player) < 1) { toDelete.add(player); } else { Storage.hungerPlayers.put(player, Storage.hungerPlayers.get(player) - 1); } } for (Player p : toDelete) { Storage.hungerPlayers.remove(p); } toDelete.clear(); for (Player player : Storage.moverBlockDecay.keySet()) { Storage.moverBlockDecay.put(player, Storage.moverBlockDecay.get(player) + 1); if (Storage.moverBlockDecay.get(player) > 5) { Storage.moverBlocks.remove(player); toDelete.add(player); } } for (Player p : toDelete) { Storage.moverBlockDecay.remove(p); } }
@EventHandler public void onEntityDeath(final EntityDeathEvent event) { int modifier = 1; event.setDroppedExp(0); String world = event.getEntity().getLocation().getWorld().getName(); if (world.equalsIgnoreCase("oilrig")) modifier = 3; if (world.equalsIgnoreCase("city")) modifier = 2; if (!(event.getEntity() instanceof Player)) { List<ItemStack> list = event.getDrops(); if (event.getEntity() instanceof Zombie || event.getEntity() instanceof PigZombie) { list.clear(); if (plugin.gen.nextInt(50) == 0) { Material random = drop.selector( plugin.gen.nextInt(2) + 1, plugin.gen.nextInt(5) + 1, plugin.gen.nextInt(4) + 1, plugin.gen.nextInt(5) + 1); ItemStack item = new ItemStack(random, 1); Integer enchamt = plugin.gen.nextInt(10); for (int i = 0; i < enchamt; i++) { int rand = plugin.gen.nextInt(21) + 1; Enchantment enchantment = drop.enchant(rand); int power = plugin.gen.nextInt(enchantment.getMaxLevel()) + 1; item.addUnsafeEnchantment(enchantment, power); } list.add(item); } if (plugin.gen.nextInt(25) == 0) { int[] iteml = {296, 297, 263, 264, 265, 266, 260, 289, 352, 287, 368}; Integer random = plugin.gen.nextInt(iteml.length); ItemStack item = new ItemStack(iteml[random], plugin.gen.nextInt(5) + 1); list.add(item); } if (plugin.gen.nextInt(30) == 0) { int[] iteml = {372, 376, 375, 377, 370, 378, 369, 262, 341, 367}; Integer random = plugin.gen.nextInt(iteml.length); ItemStack item = new ItemStack(iteml[random], 1); list.add(item); } if (event.getEntity() instanceof Zombie) { ArrayList<Player> l = new ArrayList<Player>(); for (Entity entity : event.getEntity().getNearbyEntities(10, 10, 10)) { if (entity instanceof Player) { Player killer = (Player) entity; killer.setLevel(killer.getLevel() + (1 * modifier)); l.add(killer); } } EntityDamageEvent e = event.getEntity().getLastDamageCause(); if (e instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent ev = (EntityDamageByEntityEvent) e; if (ev.getDamager() instanceof Arrow) { Arrow a = (Arrow) ev.getDamager(); if (a.getShooter() instanceof Player) { Player killer = (Player) a.getShooter(); if (!l.contains(killer)) { killer.setLevel(killer.getLevel() + (1 * modifier)); } } } } l.clear(); } if (event.getEntity() instanceof PigZombie) { ArrayList<Player> l = new ArrayList<Player>(); for (Entity entity : event.getEntity().getNearbyEntities(10, 10, 10)) { if (entity instanceof Player) { Player killer = (Player) entity; killer.setLevel(killer.getLevel() + (5 * modifier)); l.add(killer); } } EntityDamageEvent e = event.getEntity().getLastDamageCause(); if (e instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent ev = (EntityDamageByEntityEvent) e; if (ev.getDamager() instanceof Arrow) { Arrow a = (Arrow) ev.getDamager(); if (a.getShooter() instanceof Player) { Player killer = (Player) a.getShooter(); if (!l.contains(killer)) { killer.setLevel(killer.getLevel() + (5 * modifier)); } } } } l.clear(); } } if (event.getEntity() instanceof Giant) { ItemStack item = new ItemStack(57, 10); list.add(item); StringBuilder sb = new StringBuilder(); for (Entity entity : event.getEntity().getNearbyEntities(15, 15, 15)) { if (entity instanceof Player) { Player killer = (Player) entity; String name = killer.getName(); if (name.equalsIgnoreCase("deathmarin")) { name = "Deathmarine"; } sb.append(name + ", "); killer.setLevel(killer.getLevel() + (50 * modifier)); } } plugin.getServer().broadcastMessage(ChatColor.AQUA + sb.toString() + "killed the giant."); for (int i = 0; i < 50; i++) { event .getEntity() .getLocation() .getWorld() .spawn(event.getEntity().getLocation(), Zombie.class); } } if (plugin.gen.nextInt(16) == 0) { ItemStack item = new ItemStack(90, 1); list.add(item); } } }