@Override public void shoot(PlayerInteractEvent event) { if (event.getMaterial() == null) return; final List<String> itemLore = event.getItem().getItemMeta().getLore(); if (WeaponWatch.durability.get(itemLore) == null) WeaponWatch.durability.put(itemLore, 4); if (WeaponWatch.durability.get(itemLore) == 0) return; if (WeaponWatch.cooldown.contains(itemLore)) return; if (shotsLeft.get(itemLore) != null && shotsLeft.get(itemLore) == 0) { WeaponWatch.cooldown.add(itemLore); shotsLeft.remove(itemLore); new BukkitRunnable() { @Override public void run() { WeaponWatch.durability.put(itemLore, WeaponWatch.durability.get(itemLore) - 1); WeaponWatch.cooldown.remove(itemLore); } }.runTaskLater(DuckMain.getPlugin(), 80); } int shotsPerRound = 6; // @Balancing: Specify shots per round here if (shotsLeft.get(itemLore) == null) shotsLeft.put(itemLore, shotsPerRound); else shotsLeft.put(itemLore, shotsLeft.get(itemLore) - 1); DuckMain.getWorld().playSound(event.getPlayer().getLocation(), Sound.ENTITY_BLAZE_HURT, 10, 1); Arrow a = event .getPlayer() .launchProjectile(Arrow.class, event.getPlayer().getLocation().getDirection()); a.setShooter(event.getPlayer()); a.setVelocity(a.getVelocity().multiply(6)); a.setCustomName("MachineGun"); }
protected void triggersign(TriggerType type, Object args) { InputState is = this.getInput(1, (BlockRedstoneEvent) args); if (is == InputState.HIGH && !lastState) { lastState = true; Vector v = new Vector( to.getBlockX() - from.getBlockX(), to.getBlockY() - from.getBlockY(), to.getBlockZ() - from.getBlockZ()); v.normalize(); v.multiply(speed); while (from.getBlock().getType() != Material.AIR) { from = from.toVector().add(v.clone().normalize().multiply(.2)).toLocation(this.getWorld()); } for (int i = 0; i < arrows; i++) { Arrow a = this.getWorld().spawn(from, Arrow.class); a.setVelocity(v.clone().add(getVariance(variance))); this.main.cleaner.register(a, 5000); } this.getWorld().playEffect(from, org.bukkit.Effect.BOW_FIRE, 0); } else if ((is == InputState.LOW || is == InputState.DISCONNECTED) && lastState) { lastState = false; } else { return; } }
// @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); } } } }
// 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(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(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(); } }
@EventHandler public void arrowAway(ProjectileHitEvent event) { org.bukkit.entity.Entity projectile = event.getEntity(); Location location = projectile.getLocation(); if (location.getWorld().getName().equals(getName())) { if (projectile instanceof Arrow) { Arrow arrow = (Arrow) projectile; arrow.remove(); } } }
@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 public void DodgeHit(EntityDamageByEntityEvent e) { if (e.getCause() == DamageCause.PROJECTILE) { if (e.getEntity() instanceof Player) { Player p = (Player) e.getEntity(); if (PDUtils.getByName(p.getName()).getKit() != null && PDUtils.getByName(p.getName()).getKit().equalsIgnoreCase("Dodge")) { PData pd = PDUtils.getByName(p.getName()); Arrow a = p.launchProjectile(Arrow.class); a.setShooter(p); a.setVelocity(e.getDamager().getVelocity().multiply(-1)); e.setCancelled(true); } } } }
@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); } } } }
/* (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 public void ProjectileHit(ProjectileHitEvent e) { List<Entity> nbe = e.getEntity() .getNearbyEntities( e.getEntity().getLocation().getX(), e.getEntity().getLocation().getY(), e.getEntity().getLocation().getZ()); for (Entity ee : nbe) { if (ee instanceof Player) { Player ph = (Player) ee; PData pd = PDUtils.getByName(ph.getName()); if (pd.getKit() != null && pd.getKit().equalsIgnoreCase("Dodge")) { Arrow a = ph.launchProjectile(Arrow.class); a.setShooter(ph); a.setVelocity(e.getEntity().getShooter().getLocation().toVector()); } } } }
@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 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) 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 + "你不能伤到你的队友!"); } } } } } }
static void resitPlayer(Player player, Block block) { if (player.getVehicle() != null) player.getVehicle().remove(); Location arrowLocation = block.getLocation().add(0.5, 0.2, 0.5); Arrow chairArrow = player.getWorld().spawnArrow(arrowLocation, new Vector(1, 0, 0), 1, 1); chairArrow.setPassenger(player); }
@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); }
@Override public void run() { Arrow shot = player.launchProjectile(Arrow.class); shot.setVelocity(shot.getVelocity().multiply(2.0)); }
@EventHandler public void onProjectileHit(ProjectileHitEvent e) { if (!(e.getEntity() instanceof Arrow) && !(e.getEntity() instanceof Egg)) return; Projectile projectile = e.getEntity(); if (!(projectile.getShooter() instanceof Player)) return; SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(projectile.getShooter()); if (!player.isActive()) return; Game game = player.getGame(); if (projectile instanceof Arrow) { Arrow arrow = (Arrow) projectile; if (!game.getFlag(FlagType.BOWSPLEEF)) return; // Use BlockIterator to detect the hit block BlockIterator iterator = new BlockIterator(arrow.getWorld(), arrow.getLocation().toVector(), arrow.getVelocity().normalize(), 0, 4); Block hitBlock = null; while (iterator.hasNext()) { hitBlock = iterator.next(); if (hitBlock.getType() != Material.AIR) break; } if (!game.canSpleef(player, hitBlock.getLocation())) return; World world = arrow.getWorld(); if (hitBlock.getType() == Material.TNT) { return; } arrow.remove(); player.addBrokenBlock(hitBlock); FallingBlock block = world.spawnFallingBlock(hitBlock.getLocation(), hitBlock.getType(), hitBlock.getData()); block.setMetadata("bowspleef", new FixedMetadataValue(HeavySpleef.getInstance(), true)); if (game.getFlag(FlagType.BLOCKBREAKEFFECT)) { world.playEffect(hitBlock.getLocation(), Effect.STEP_SOUND, hitBlock.getType()); } hitBlock.setType(Material.AIR); } else if (projectile instanceof Egg) { Egg egg = (Egg) projectile; if (!game.getFlag(FlagType.SPLEGG)) return; // Use BlockIterator to detect the hit block World world = egg.getWorld(); BlockIterator iterator = new BlockIterator(egg.getWorld(), egg.getLocation().toVector(), egg.getVelocity().normalize(), 0, 4); egg.remove(); Block hitBlock = null; while (iterator.hasNext()) { hitBlock = iterator.next(); if (hitBlock.getType() != Material.AIR) break; } if (!game.canSpleef(player, hitBlock.getLocation())) return; player.addBrokenBlock(hitBlock); world.playSound(hitBlock.getLocation(), Sound.CHICKEN_EGG_POP, 0.7F, 1.0F); FuzzyReflection.playMobSpellEffect(hitBlock.getLocation().clone().add(0.5, 0.8, 0.5), 100, 0); hitBlock.setType(Material.AIR); } }
// -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()); } }
@EventHandler(ignoreCancelled = true) public void onEntityDamageEntity(EntityDamageByEntityEvent e) { if (e.getEntity() instanceof Player) { // Hit player Player damaged = (Player) e.getEntity(); if (e.getDamager() instanceof Player) { // Player Player damager = (Player) e.getDamager(); if (cancelBothIngame(damaged, damager)) { e.setCancelled(true); return; } if (checkForShadowBlade(damager)) { e.setCancelled(true); return; } if (pl.ingameList.get(damager).getAttackType() == 2) { if (damager.getItemInHand().getType().equals(Material.IRON_SWORD) || damager.getItemInHand().getType().equals(Material.DIAMOND_SWORD) || damager.getItemInHand().getType().equals(Material.GOLD_SWORD)) { e.setCancelled(true); return; } } if (!e.isCancelled()) { checkTeleport(damager); } } else if (e.getDamager() instanceof Projectile) { // Arrow Projectile proj = (Projectile) e.getDamager(); if (proj.getShooter() instanceof Player) { Player shooter = (Player) proj.getShooter(); if (cancelBothIngame(damaged, shooter)) { e.setCancelled(true); return; } if (pl.ingameList.get(shooter).getAttackType() == 1) { e.setCancelled(true); return; } if (checkForShadowBlade(shooter)) { e.setCancelled(true); return; } checkTeleport(shooter); if (!e.isCancelled()) { if (!checkIngame(damaged) && checkIngame(shooter)) { // spectator wont get hurt, and the arrow wont stop proj.setBounce(false); Vector vel = proj.getVelocity(); damaged.teleport(damaged.getLocation().add(0, 3, 0)); damaged.setFlying(true); Arrow newArrow = shooter.launchProjectile(Arrow.class); newArrow.setShooter(shooter); newArrow.setVelocity(vel); e.setCancelled(true); proj.remove(); } else if (checkIngame(damaged) && checkIngame(shooter)) { // e.setCancelled(true); // damaged.damage(e.getDamage()); checkTarrasque(damaged); checkTeleport(damaged); checkTeleport(shooter); pl.breakEffect(damaged.getLocation(), 3, 11); } } } } } else { // Hit a non-player if (e.getDamager() instanceof Player) { // Player Player damager = (Player) e.getDamager(); if (checkSpectator(damager)) { e.setCancelled(true); return; } if (checkForShadowBlade(damager)) { e.setCancelled(true); return; } if (pl.ingameList.get(damager).getAttackType() == 2) { if (damager.getItemInHand().getType().equals(Material.IRON_SWORD) || damager.getItemInHand().getType().equals(Material.DIAMOND_SWORD) || damager.getItemInHand().getType().equals(Material.GOLD_SWORD)) { e.setCancelled(true); return; } } checkTeleport(damager); } else if (e.getDamager() instanceof Projectile) { // Arrow Projectile proj = (Projectile) e.getDamager(); if (proj.getShooter() instanceof Player) { Player shooter = (Player) proj.getShooter(); if (!checkIngame(shooter)) { if (checkSpectator(shooter)) { e.setCancelled(true); return; } } else { if (pl.ingameList.get(shooter).getAttackType() == 1) { e.setCancelled(true); return; } if (checkForShadowBlade(shooter)) { e.setCancelled(true); return; } checkTeleport(shooter); } } } if (!e.isCancelled()) { pl.breakEffect(e.getEntity().getLocation(), 2, 55); } } }
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 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); } } }