protected TrackedEntity(LivingEntity livingEntity) { this.livingEntity = livingEntity; this.id = livingEntity.getUniqueId(); this.runTaskTimer(mcMMO.p, 12000, 12000); }
/** * Returns whether the NPC should target a specific entity. */ public boolean shouldTarget(LivingEntity entity) { if (entity.getUniqueId().equals(getLivingEntity().getUniqueId())) { return false; } return isTargeted(entity) && !isIgnored(entity); }
/** * Called when a target dies to remove them from the target list. */ @EventHandler public void whenAnEnemyDies(EntityDeathEvent event) { tempTarget.targetID = event.getEntity().getUniqueId(); targetingHelper.currentTargets.remove(tempTarget); targetingHelper.currentAvoids.remove(tempTarget); }
public void releaseFamiliar(Entity entity) { if (familiars != null) { List<LivingEntity> iterate = new ArrayList<>(familiars); for (LivingEntity familiar : iterate) { if (Objects.equals(familiar.getUniqueId(), entity.getUniqueId())) { familiar.remove(); familiars.remove(familiar); } } familiars = null; } }
@SuppressWarnings("unchecked") public static double getDamageToEntity(LivingEntity damager, LivingEntity victim) { for (MetadataValue value : victim.getMetadata("DamageCount")) { if (value.getOwningPlugin().getName().equals("MyPet")) { Map<UUID, Double> damageMap = (Map<UUID, Double>) value.value(); if (damageMap.containsKey(damager.getUniqueId())) { return damageMap.get(damager.getUniqueId()); } return 0; } } return 0; }
/** * Returns whether an entity is invisible to this NPC. */ public boolean isInvisible(LivingEntity entity) { SentinelCurrentTarget sct = new SentinelCurrentTarget(); sct.targetID = entity.getUniqueId(); return !currentTargets.contains(sct) && SentinelUtilities.isInvisible(entity); }
/** * Returns whether an entity is ignored by this NPC's ignore lists. */ public boolean isIgnored(LivingEntity entity) { if (isInvisible(entity)) { return true; } if (entity.getUniqueId().equals(getLivingEntity().getUniqueId())) { return true; } if (sentinel.getGuarding() != null && entity.getUniqueId().equals(sentinel.getGuarding())) { return true; } return sentinel.allIgnores.isTarget(entity, sentinel); }
/** * Adds a temporary target to this NPC (and squadmates if relevant). */ public void addTarget(UUID id) { if (id.equals(getLivingEntity().getUniqueId())) { return; } if (!(SentinelUtilities.getEntityForID(id) instanceof LivingEntity)) { return; } SentinelCurrentTarget target = new SentinelCurrentTarget(); target.targetID = id; target.ticksLeft = sentinel.enemyTargetTime; currentTargets.remove(target); currentTargets.add(target); }
public static String handleEntityPlaceHolder(LivingEntity e, String cmd) { cmd = cmd.replaceAll("\\{entity}", e.getName()); cmd = cmd.replaceAll("\\{entity\\.uuid}", e.getUniqueId().toString()); cmd = cmd.replaceAll("\\{entity\\.x}", Float.toString(e.getLocation().getBlockX())); cmd = cmd.replaceAll("\\{entity\\.y}", Float.toString(e.getLocation().getBlockY())); cmd = cmd.replaceAll("\\{entity\\.z}", Float.toString(e.getLocation().getBlockZ())); cmd = cmd.replaceAll("\\{entity\\.yaw}", Float.toString(90 + e.getEyeLocation().getYaw())); cmd = cmd.replaceAll("\\{entity\\.pitch}", Float.toString(-e.getEyeLocation().getPitch())); return cmd; }
@Override public Entity getEntityByUUID(UUID uuid) { for (World world : Bukkit.getServer().getWorlds()) { for (LivingEntity e : world.getLivingEntities()) { if (e.getUniqueId().equals(uuid)) { return e; } } } return null; } }
/** * Check for arrow retrieval. * * @param livingEntity The entity hit by the arrows */ public static void arrowRetrievalCheck(LivingEntity livingEntity) { for (Iterator<TrackedEntity> entityIterator = trackedEntities.iterator(); entityIterator.hasNext();) { TrackedEntity trackedEntity = entityIterator.next(); if (trackedEntity.getID() == livingEntity.getUniqueId()) { Misc.dropItems(livingEntity.getLocation(), new ItemStack(Material.ARROW), trackedEntity.getArrowCount()); entityIterator.remove(); return; } } }
@SuppressWarnings("unchecked") public static double getDamageToEntityPercent(LivingEntity damager, LivingEntity victim) { if (victim.hasMetadata("DamageCount")) { UUID damagerUUID = damager.getUniqueId(); for (MetadataValue value : victim.getMetadata("DamageCount")) { if (value.getOwningPlugin().getName().equals("MyPet")) { Map<UUID, Double> damageMap = (Map<UUID, Double>) value.value(); double allDamage = 0; double damagerDamage = damageMap.containsKey(damagerUUID) ? damageMap.get(damagerUUID) : 0; for (UUID entity : damageMap.keySet()) { allDamage += damageMap.get(entity); } return damagerDamage / allDamage; } } } return 0; }
/** * 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()); }
/** * Returns whether an entity is targeted by this target list on a specific Sentinel NPC. * Does not include target-list-specific handling, such as current temporary targets. */ public boolean isTarget(LivingEntity entity, SentinelTrait sentinel) { checkRecalculateTargetsCache(); if (targetsProcessed.contains(SentinelTarget.OWNER) && entity.getUniqueId().equals(sentinel.getNPC().getTrait(Owner.class).getOwnerId())) { return true; } return isTarget(entity); }
@EventHandler public void onPlayerQuit(PlayerQuitEvent e) { if (e.getPlayer().getUniqueId().equals(entity.getUniqueId())) { player.removePassenger(entity); entity.leaveVehicle(); } } };
@Override public void run() { if (ticks >= maxTicks || player.getPassengers().isEmpty() || entity.isDead()) { cancel(); if (finalListener != null) { HandlerList.unregisterAll(finalListener); } if (!player.getPassengers().isEmpty() && player.getPassengers().get(0).getUniqueId().equals(entity.getUniqueId())) { player.getPassengers().get(0).leaveVehicle(); } } ticks++; } }.runTaskTimer(RPGItems.plugin, 1, 1);
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); } }
@Override public PowerResult<Double> hit(Player player, ItemStack stack, LivingEntity entity, double damage, EntityDamageByEntityEvent event) { if (!checkCooldown(this, player, cooldown, true, true)) return PowerResult.cd(); if (random.nextInt(chance) == 0) { if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); stucked.put(entity.getUniqueId(), System.currentTimeMillis()); entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, duration, 10), true); entity.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, duration, 128), true); return PowerResult.ok(damage); } return PowerResult.noop(); }
@EventHandler(priority = EventPriority.NORMAL) public void onLingeringPotionDamage(AreaEffectCloudApplyEvent e) { if (e.getEntity() != null && thrownPotions.containsKey(e.getEntity().getEntityId())) { User user = User.getInstance(thrownPotions.get(e.getEntity().getEntityId())); // Run through affected entities and delete them if they are safe e.getAffectedEntities().removeIf(le -> !le.getUniqueId().equals(user.getUniqueId()) && blockPVP(user, le, e, getFlag(e.getEntity().getWorld()))); } }
@Override public PowerResult<Void> rightClick(Player player, ItemStack stack, PlayerInteractEvent event) { if (!checkCooldown(this, player, cooldown, true, true)) return PowerResult.cd(); if (!getItem().consumeDurability(stack, costAoe)) return PowerResult.cost(); List<LivingEntity> entities = getLivingEntitiesInCone(getNearestLivingEntities(this, player.getEyeLocation(), player, range, 0), player.getLocation().toVector(), facing, player.getLocation().getDirection()); entities.forEach(entity -> { if (!getItem().consumeDurability(stack, costPerEntity)) return; stucked.put(entity.getUniqueId(), System.currentTimeMillis()); entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, duration, 10), true); entity.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, duration, 128), true); } ); return PowerResult.ok(); }