/** * Check if a given LivingEntity is a boss. * * @param livingEntity The {@link LivingEntity} of the livingEntity to check * @return true if the livingEntity is a boss, false otherwise */ private static boolean isBoss(LivingEntity livingEntity) { switch (livingEntity.getType()) { case ENDER_DRAGON: case WITHER: return true; default: return false; } } }
protected static void addToTracker(LivingEntity livingEntity) { TrackedTamingEntity trackedEntity = new TrackedTamingEntity(livingEntity); if (!summonedEntities.containsKey(livingEntity.getType())) { summonedEntities.put(livingEntity.getType(), new ArrayList<TrackedTamingEntity>()); } summonedEntities.get(livingEntity.getType()).add(trackedEntity); }
/** * Finds the possible drops of an entity * * @param target * Targeted entity * @return possibleDrops List of ItemStack that can be dropped */ protected static List<ShakeTreasure> findPossibleDrops(LivingEntity target) { if (TreasureConfig.getInstance().shakeMap.containsKey(target.getType())) return TreasureConfig.getInstance().shakeMap.get(target.getType()); return null; }
protected static void removeFromTracker(TrackedTamingEntity trackedEntity) { summonedEntities.get(trackedEntity.getLivingEntity().getType()).remove(trackedEntity); } }
private void countTotalEntity() { int count = 0; for (World world : Bukkit.getWorlds()) { for (LivingEntity entity : world.getLivingEntities()) { if (entity instanceof Monster || entity instanceof Animals || entity instanceof Villager || entity.getType() == EntityType.SQUID || entity.getType() == EntityType.BAT) { count++; } } } this.cachedMobCount = count; this.lastCountTime = System.currentTimeMillis(); }
/** * Gets the minimum distance from the NPC's head to launch a projectile from (to avoid it colliding with the NPC's own collision box). */ public double firingMinimumRange() { EntityType type = getLivingEntity().getType(); if (type == EntityType.WITHER || type == EntityType.GHAST) { return 8; // Yikes! } return 2; }
/** * Award XP for taming. * * @param entity The LivingEntity to award XP for */ public void awardTamingXP(LivingEntity entity) { applyXpGain(ExperienceConfig.getInstance().getTamingXP(entity.getType()), XPGainReason.PVE); }
@EventHandler public void onEntityDeath(EntityDeathEvent e) { String type = e.getEntity().getType().toString(); if (PowerTranslocator.translocatorPlayerMap.getIfPresent(e.getEntity().getUniqueId()) != null) { e.getDrops().clear(); } Random random = new Random(); if (drops.containsKey(type)) { Set<Integer> items = drops.get(type); Iterator<Integer> it = items.iterator(); while (it.hasNext()) { int id = it.next(); RPGItem item = ItemManager.getItem(id).orElse(null); if (item == null) { it.remove(); continue; } double chance = item.getDropChances().get(type); if (random.nextDouble() < chance / 100d) { e.getDrops().add(item.toItemStack()); } } } }
protected TrackedTamingEntity(LivingEntity livingEntity) { this.livingEntity = livingEntity; this.id = livingEntity.getUniqueId(); int tamingCOTWLength = Config.getInstance().getTamingCOTWLength(livingEntity.getType()); if (tamingCOTWLength > 0) { this.length = tamingCOTWLength * Misc.TICK_CONVERSION_FACTOR; this.runTaskLater(mcMMO.p, length); } }
/** * Ongoing updates */ public void update() { if (getWorld() == null) { return; } // Update Spiders for (LivingEntity mob : getWorld().getLivingEntities()) { if (mob.getType() == EntityType.SPIDER || mob.getType() == EntityType.CAVE_SPIDER) { Spider spider = (Spider) mob; if (spider.getTarget() != null) { if (spider.getTarget().getType() == EntityType.PLAYER) { continue; } } for (Entity player : spider.getNearbyEntities(10, 10, 10)) { if (player.getType() == EntityType.PLAYER) { spider.setTarget((LivingEntity) player); } } } } }
/** * Called when any entity dies. */ @EventHandler(priority = EventPriority.LOW) public void whenSomethingDies(EntityDeathEvent event) { if (event.getEntity().getType() != EntityType.PLAYER && needsDropsClear.containsKey(event.getEntity().getUniqueId())) { event.getDrops().clear(); event.setDroppedExp(0); } targetingHelper.removeTarget(event.getEntity().getUniqueId()); }
/** * Marks that the NPC can see a target (Changes the state of som entity types, eg opening a shulker box). */ public void specialMarkVision() { if (SentinelPlugin.debugMe && !visionMarked) { debug("Target! I see you, " + (chasing == null ? "(Unknown)" : chasing.getName())); } if (SentinelTarget.v1_11 && getLivingEntity().getType() == EntityType.SHULKER) { NMS.setPeekShulker(getLivingEntity(), 100); } visionMarked = true; }
/** * Marks that the NPC can no longer see a target (Changes the state of som entity types, eg closing a shulker box). */ public void specialUnmarkVision() { if (SentinelPlugin.debugMe && visionMarked) { debug("Goodbye, visible target " + (chasing == null ? "(Unknown)" : chasing.getName())); } if (SentinelTarget.v1_11 && getLivingEntity().getType() == EntityType.SHULKER) { NMS.setPeekShulker(getLivingEntity(), 0); } visionMarked = false; }
switch (type) { case WOLF: if (entity.getType().equals(EntityType.WOLF) && checkConditions(playerID)) { playerData.subtract(); if (entity.getType().equals(EntityType.OCELOT) && checkConditions(playerID)) { playerData.subtract(); if (entity.getType().equals(EntityType.HORSE) && checkConditions(playerID)) { playerData.subtract();
private void checkAndCleanMobFarm() { for (World world : Bukkit.getWorlds()) { for (LivingEntity entity : world.getLivingEntities()) { if (entity instanceof Monster || entity instanceof Animals || entity instanceof Villager || entity.getType() == EntityType.SQUID) { if (NeverLagUtils.checkCustomNpc(entity)) { continue; } if (this.getNearbyEntityCount(entity, false) >= cm.mobCollisionLargeLimit || this.getNearbyEntityCount(entity, true) >= cm.mobCollisionSmallLimit) { entity.remove(); } } } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityBreed(EntityBreedEvent event) { if (!(event.getBreeder() instanceof Player)) { return; } Player player = (Player) event.getBreeder(); if (!shouldIncreaseBeTakenIntoAccountNoPermissions(player)) { return; } String mobName = event.getMother().getType().name().toLowerCase(); MultipleAchievements category = MultipleAchievements.BREEDING; if (!player.hasPermission(category.toPermName() + '.' + mobName)) { return; } Set<String> foundAchievements = findAchievementsByCategoryAndName(category, mobName); foundAchievements.forEach(achievement -> updateStatisticAndAwardAchievementsIfAvailable(player, category, achievement, 1)); } }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityDeath(EntityDeathEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof LivingEntity)) { return; } LivingEntity died = (LivingEntity)entity; String name = died.getCustomName(); if (name == null || name.isEmpty()) { EntityData mob = defaultMobs.get(died.getType()); if (mob != null && !died.hasMetadata("nodrops")) { mob.modifyDrops(controller, event); } return; } EntityData mob = mobsByName.get(name); if (mob == null) return; MagicMobDeathEvent deathEvent = new MagicMobDeathEvent(controller, mob, event); Bukkit.getPluginManager().callEvent(deathEvent); if (!died.hasMetadata("nodrops")) { mob.modifyDrops(controller, event); } // Prevent double-deaths .. gg Mojang? // Kind of hacky to use this flag for it, but seemed easiest died.setCustomNameVisible(false); died.setCustomName(null); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSilurianSpawn(CreatureSpawnEvent event) { if (!event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER)) { return; } if (!event.getLocation().getWorld().getName().equals("Siluria")) { return; } if (!event.getEntity().getType().equals(EntityType.SKELETON)) { return; } LivingEntity le = event.getEntity(); // it's a Silurian - disguise it! twaAPI.setSilurianEquipment(le, false); } }
/** * 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()); }); } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onDalekSpawn(CreatureSpawnEvent event) { if (!event.getSpawnReason().equals(SpawnReason.SPAWNER)) { return; } if (!event.getLocation().getWorld().getName().equals("Skaro")) { return; } if (!event.getEntity().getType().equals(EntityType.SKELETON)) { return; } LivingEntity le = event.getEntity(); // it's a Dalek - disguise it! twaAPI.setDalekEquipment(le); if (plugin.getPlanetsConfig().getBoolean("planets.Skaro.flying_daleks") && r.nextInt(100) < 10) { // make the Dalek fly EntityEquipment ee = le.getEquipment(); ee.setChestplate(new ItemStack(Material.ELYTRA, 1)); // teleport them straight up le.teleport(le.getLocation().add(0.0d, 20.0d, 0.0d)); plugin.getTardisHelper().setFallFlyingTag(le); } } }