public static void playBleedEffect(LivingEntity livingEntity) { if (!Config.getInstance().getBleedEffectEnabled()) { return; } livingEntity.getWorld().playEffect(livingEntity.getEyeLocation(), Effect.STEP_SOUND, Material.REDSTONE_WIRE); }
public static void playCallOfTheWildEffect(LivingEntity livingEntity) { if (!Config.getInstance().getCallOfTheWildEffectEnabled()) { return; } livingEntity.getWorld().playEffect(livingEntity.getEyeLocation(), Effect.MOBSPAWNER_FLAMES, 1); }
@Override public boolean onHit(EntityDamageByEntityEvent e, LivingEntity n) { if (SlimefunManager.isItemSimiliar(Variables.arrows.get(e.getDamager().getUniqueId()), SlimefunItems.EXPLOSIVE_BOW, true)) { Vector vector = n.getVelocity(); vector.setY(0.6); n.setVelocity(vector); n.getWorld().createExplosion(n.getLocation(), 0F); n.getWorld().playSound(n.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F); return true; } else return false; } });
@Override public boolean onHit(EntityDamageByEntityEvent e, LivingEntity n) { if (SlimefunManager.isItemSimiliar(Variables.arrows.get(e.getDamager().getUniqueId()), SlimefunItems.ICY_BOW, true)) { n.getWorld().playEffect(n.getLocation(), Effect.STEP_SOUND, Material.ICE); n.getWorld().playEffect(n.getEyeLocation(), Effect.STEP_SOUND, Material.ICE); n.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20 * 2, 10)); n.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20 * 2, -10)); return true; } else return false; } });
public static void playGreaterImpactEffect(LivingEntity livingEntity) { if (!Config.getInstance().getGreaterImpactEffectEnabled()) { return; } Location location = livingEntity.getEyeLocation(); livingEntity.getWorld().createExplosion(location.getX(), location.getY(), location.getZ(), 0F, false, false); }
/** * Monitor EntityDeath events. * * @param event * The event to watch */ @EventHandler(priority = EventPriority.MONITOR) public void onEntityDeath(EntityDeathEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) return; LivingEntity entity = event.getEntity(); if (Misc.isNPCEntity(entity)) { return; } Archery.arrowRetrievalCheck(entity); }
/** * Handles some basics for when the NPC died. */ public void generalDeathHandler(LivingEntity entity) { if (spawnPoint != null) { npc.getTrait(CurrentLocation.class).setLocation(spawnPoint.clone()); } if (SentinelPlugin.instance.workaroundDrops) { for (ItemStack item : drops) { entity.getWorld().dropItemNaturally(entity.getLocation(), item.clone()); } } onDeath(); }
@EventHandler(priority = EventPriority.HIGH) public void onEntityDeath(EntityDeathEvent event) { WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(BukkitAdapter.adapt(event.getEntity().getWorld())); if (event instanceof PlayerDeathEvent && wcfg.disableDeathMessages) { ((PlayerDeathEvent) event).setDeathMessage(""); } }
/** * This is called when an entity creates a portal. * * @param event The event where an entity created a portal. */ @EventHandler public void entityPortalCreate(EntityCreatePortalEvent event) { if (event.isCancelled() || event.getBlocks().size() == 0) { return; } MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getEntity().getWorld()); // We have to do it like this due to a bug in 1.1-R3 if (world != null && !world.getAllowedPortals().isPortalAllowed(event.getPortalType())) { event.setCancelled(true); } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onCreatePortal(EntityCreatePortalEvent event) { ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld())); switch (event.getEntityType()) { case ENDER_DRAGON: if (wcfg.blockEnderDragonPortalCreation) event.setCancelled(true); break; } }
@EventHandler public void onEntityDeath(EntityDeathEvent event) { World world = event.getEntity().getWorld(); if (event.getEntity() instanceof LivingEntity) { LivingEntity entity = event.getEntity(); DGameWorld gameWorld = DGameWorld.getByWorld(world); if (gameWorld != null) { if (gameWorld.isPlaying()) { DMob dMob = DMob.getByEntity(entity); if (dMob != null) { dMob.onDeath(event); } } } } }
/** * Tracks the mob kills. * * @param event the death event */ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onMobDeath(EntityDeathEvent event) { LivingEntity entity = event.getEntity(); //killer is null if it's not a player Player killer = entity.getKiller(); //Check if it's not player because we are already handling it if (entity.getType() != EntityType.PLAYER && Settings.isActiveWorld(entity.getWorld().getName())) { database.getStats(killer).ifPresent(stats -> { //If the cache entry is loaded and the player isn't null, increase the mob kills stats.onMobKill(); ReplaceManager.getInstance().forceUpdate(killer, "mob", stats.getMobkills()); }); } }
public static void playSmokeEffect(LivingEntity livingEntity) { Location location = livingEntity.getEyeLocation(); World world = livingEntity.getWorld(); // Have to do it this way, because not all block directions are valid for smoke world.playEffect(location, Effect.SMOKE, BlockFace.SOUTH_EAST); world.playEffect(location, Effect.SMOKE, BlockFace.SOUTH); world.playEffect(location, Effect.SMOKE, BlockFace.SOUTH_WEST); world.playEffect(location, Effect.SMOKE, BlockFace.EAST); world.playEffect(location, Effect.SMOKE, BlockFace.SELF); world.playEffect(location, Effect.SMOKE, BlockFace.WEST); world.playEffect(location, Effect.SMOKE, BlockFace.NORTH_EAST); world.playEffect(location, Effect.SMOKE, BlockFace.NORTH); world.playEffect(location, Effect.SMOKE, BlockFace.NORTH_WEST); }
/** * Monitor EntityDeath events. * * @param event * The event to watch */ @EventHandler(priority = EventPriority.LOWEST) public void onEntityDeathLowest(EntityDeathEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) return; LivingEntity entity = event.getEntity(); if (Misc.isNPCEntity(entity)) { return; } if (entity.hasMetadata(mcMMO.customNameKey)) { entity.setCustomName(entity.getMetadata(mcMMO.customNameKey).get(0).asString()); entity.removeMetadata(mcMMO.customNameKey, plugin); } if (entity.hasMetadata(mcMMO.customVisibleKey)) { entity.setCustomNameVisible(entity.getMetadata(mcMMO.customVisibleKey).get(0).asBoolean()); entity.removeMetadata(mcMMO.customVisibleKey, plugin); } if (entity.hasMetadata(mcMMO.entityMetadataKey)) { entity.removeMetadata(mcMMO.entityMetadataKey, plugin); } }
/** * Monitor CreatureSpawn events. * * @param event * The event to watch */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCreatureSpawn(CreatureSpawnEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) return; LivingEntity entity = event.getEntity(); switch (event.getSpawnReason()) { case NETHER_PORTAL: case SPAWNER: case SPAWNER_EGG: entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); Entity passenger = entity.getPassenger(); if (passenger != null) { passenger.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); } return; case BREEDING: entity.setMetadata(mcMMO.bredMetadataKey, mcMMO.metadataValue); return; default: return; } }
/** * This handles end dragon spawning prevention * * @param e - event * @return true if dragon can spawn, false if not */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public boolean onDragonSpawn(CreatureSpawnEvent e) { if (!e.getEntityType().equals(EntityType.ENDER_DRAGON) || plugin.getIWM().isDragonSpawn(e.getEntity().getWorld())) { return true; } e.getEntity().setHealth(0); e.getEntity().remove(); e.setCancelled(true); return false; }
@Override public void setItemStack(MCItemStack stack) { ItemStack is = (ItemStack) stack.getHandle(); e.setCancelled(true); e.getItem().remove(); if(is != null && !is.getType().equals(Material.AIR)) { ((Player) e.getEntity()).getInventory().addItem(is); //and for added realism :) e.getEntity().getWorld().playSound(e.getItem().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1, 2); } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityShootBow(EntityShootBowEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) return; if(event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); /* WORLD GUARD MAIN FLAG CHECK */ if(WorldGuardUtils.isWorldGuardLoaded()) { if(!WorldGuardManager.getInstance().hasMainFlag(player)) return; } } Entity projectile = event.getProjectile(); if (!(projectile instanceof Arrow)) { return; } ItemStack bow = event.getBow(); if (bow != null && bow.containsEnchantment(Enchantment.ARROW_INFINITE)) { projectile.setMetadata(mcMMO.infiniteArrowKey, mcMMO.metadataValue); } projectile.setMetadata(mcMMO.bowForceKey, new FixedMetadataValue(plugin, Math.min(event.getForce() * AdvancedConfig.getInstance().getForceMultiplier(), 1.0))); projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, projectile.getLocation())); }
/** * Monitor EntityTame events. * * @param event * The event to watch */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityTame(EntityTameEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) return; if (event instanceof FakeEntityTameEvent) { return; } Player player = (Player) event.getOwner(); /* WORLD GUARD MAIN FLAG CHECK */ if(WorldGuardUtils.isWorldGuardLoaded()) { if(!WorldGuardManager.getInstance().hasMainFlag(player)) return; } LivingEntity entity = event.getEntity(); if (!UserManager.hasPlayerDataKey(player) || Misc.isNPCEntity(entity) || entity.hasMetadata(mcMMO.entityMetadataKey)) { return; } entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); UserManager.getPlayer(player).getTamingManager().awardTamingXP(entity); }