/** * Gets the EntityType of the Entity involved in this event. * * @return EntityType of the Entity involved in this event */ public EntityType getEntityType() { return entity.getType(); } }
/** * Gets the name of an entity. * * @param entity an entity * @return the first of the following that exists and is non-empty: {@code * entity.getCustomName()}, {@code entity.getName()}, {@code * entity.getType().getName()} */ public static String getName(Entity entity) { String customName = entity.getCustomName(); if (customName != null && !customName.isEmpty()) { return customName; } String name = entity.getName(); if (name == null || name.isEmpty()) { name = entity.getType().getName(); } return name; }
/** * Evaluates a condition for an entity. * * @param entity the entity * @param condition the condition string to evaluate * @return true if the condition is satisfied; false otherwise */ public static boolean conditionValue(GlowLivingEntity entity, String condition) { if (condition.equals("ENTITY_ONFIRE")) { return entity.getFireTicks() > 0; } if (condition.startsWith("ENTITY_KILLER_")) { EntityType type = EntityType.valueOf(condition.substring("ENTITY_KILLER_".length())); return entity.getLastDamager() != null && entity.getLastDamager().getType() == type; } if (condition.contains(".")) { return (boolean) process(entity, condition); } // todo: more conditions, reflection return false; }
@Override public void start(GlowLivingEntity entity) { target = null; List<Entity> nearbyEntities = entity.getNearbyEntities(RANGE, RANGE / 2, RANGE); double nearestSquared = Double.MAX_VALUE; for (Entity nearbyEntity : nearbyEntities) { if (nearbyEntity.getType() != EntityType.PLAYER) { continue; } double dist = nearbyEntity.getLocation().distanceSquared(entity.getLocation()); if (dist < nearestSquared) { target = (GlowPlayer) nearbyEntity; nearestSquared = dist; } } }
@Override public void start(GlowLivingEntity entity) { target = null; List<Entity> nearbyEntities = entity.getNearbyEntities(RANGE, RANGE / 2, RANGE); double nearestSquared = Double.MAX_VALUE; for (Entity nearbyEntity : nearbyEntities) { if (nearbyEntity.getType() != EntityType.PLAYER) { continue; } double dist = nearbyEntity.getLocation().distanceSquared(entity.getLocation()); if (dist < nearestSquared) { target = (GlowPlayer) nearbyEntity; nearestSquared = dist; } } }
continue; if (!types.contains(entity.getType())) { continue; continue; if (gameModes != null && entity.getType() != EntityType.PLAYER) { continue; continue; if (maxLevel != null && entity.getType() != EntityType.PLAYER) { continue; continue; if (minLevel != null && entity.getType() != EntityType.PLAYER) { continue;
private GlowItem getFirstDroppedItem(Location location) { for (Entity entity : location.getChunk().getEntities()) { if (location.getBlockX() != entity.getLocation().getBlockX() || location.getBlockY() != entity.getLocation().getBlockY() || location.getBlockZ() != entity.getLocation().getBlockZ()) { continue; } if (entity.getType() != EntityType.DROPPED_ITEM) { continue; } return ((GlowItem) entity); } return null; }
if (source == null || source.getType() == EntityType.PRIMED_TNT) { damageCause = DamageCause.BLOCK_EXPLOSION; } else {
switch (entity.getType()) { case PLAYER: case ARMOR_STAND:
if (e instanceof Creature && (e.getType() != EntityType.PIG_ZOMBIE || ((PigZombie) e) .isAngry()) && isWithinDistance(e, block.getRelative(BlockFace.DOWN), 8, 5, 8)) { GlowstoneMessages.Bed.MOB.send(player);
public static boolean isUndead(final Entity entity) { if (entity == null) { return false; } else if (entity.getType() == EntityType.ZOMBIE || entity.getType() == EntityType.BLAZE || entity.getType() == EntityType.GIANT || entity.getType() == EntityType.IRON_GOLEM || entity.getType() == EntityType.MAGMA_CUBE || entity.getType() == EntityType.PIG_ZOMBIE || entity.getType() == EntityType.SKELETON || entity.getType() == EntityType.SLIME || entity.getType() == EntityType.SNOWMAN || entity.getType() == EntityType.ZOMBIE) { return true; } return false; }
public EntityData(Entity ent, MinigamePlayer modifier, boolean created){ this.ent = ent; entType = ent.getType(); entLocation = ent.getLocation(); player = modifier; this.created = created; }
private static boolean isFollowing(Entity entity) { switch (entity.getType()) { case WOLF: return !((Wolf) entity).isSitting(); case OCELOT: return !((Ocelot) entity).isSitting(); } return false; }
/** * Fix issues with death messages caused by the mob healthbars. * * @param deathMessage The original death message * @param player The player who died * @return the fixed death message */ public static String fixDeathMessage(String deathMessage, Player player) { EntityDamageEvent lastDamageCause = player.getLastDamageCause(); String replaceString = lastDamageCause instanceof EntityDamageByEntityEvent ? StringUtils.getPrettyEntityTypeString(((EntityDamageByEntityEvent) lastDamageCause).getDamager().getType()) : "a mob"; return deathMessage.replaceAll("(?:\u00A7(?:[0-9A-FK-ORa-fk-or]){1}(?:[\u2764\u25A0]{1,10})){1,2}", replaceString); }
private void debugNestedVehicleEnter(Player player) { debug(player, "Vehicle enter: Skip on nested vehicles, possibly with multiple players involved, who would do that?"); List<String> vehicles = new LinkedList<String>(); Entity tempVehicle = player.getVehicle(); while (tempVehicle != null) { vehicles.add(tempVehicle.getType().toString()); tempVehicle = tempVehicle.getVehicle(); } if (!vehicles.isEmpty()) { debug(player, "Vehicle enter: Nested vehicles: " + StringUtil.join(vehicles, ", ")); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { //treat it the same as interacting with an entity in general if(event.getRightClicked().getType() == EntityType.ARMOR_STAND) { this.onPlayerInteractEntity((PlayerInteractEntityEvent)event); } }
@EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { Player player = event.getPlayer(); Entity entity = event.getRightClicked(); if (PROTECTED_ENTITIES.contains(entity.getType())) { if (!bitQuest.canBuild(entity.getLocation(), player)) { event.setCancelled(true); } } }
/** * Handles placing items into ItemFrames * @param e - event */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerHitEntity(PlayerInteractEntityEvent e) { if (e.getRightClicked().getType().equals(EntityType.ITEM_FRAME)) { checkIsland(e, e.getRightClicked().getLocation(), Flags.PLACE_BLOCKS); } }
public void masterAngler(FishHook hook) { Player player = getPlayer(); Location location = hook.getLocation(); double biteChance = hook.getBiteChance(); hookLocation = location; if (Fishing.masterAnglerBiomes.contains(location.getBlock().getBiome())) { biteChance = biteChance * AdvancedConfig.getInstance().getMasterAnglerBiomeModifier(); } if (player.isInsideVehicle() && player.getVehicle().getType() == EntityType.BOAT) { biteChance = biteChance * AdvancedConfig.getInstance().getMasterAnglerBoatModifier(); } hook.setBiteChance(Math.min(biteChance, 1.0)); }