public void setTargetEntity(Entity entity) { target = new DynamicLocation(entity); }
/** * Set the Location this Effect is centered on. */ public void setDynamicOrigin(DynamicLocation location) { if (location == null) { throw new IllegalArgumentException("Origin Location cannot be null!"); } origin = location; if (offset != null) { origin.addOffset(offset); } if (relativeOffset != null) { origin.addRelativeOffset(relativeOffset); } origin.setDirectionOffset(yawOffset, pitchOffset); origin.setYaw(yaw); origin.setPitch(pitch); origin.setUpdateLocation(updateLocations); origin.setUpdateDirection(updateDirections); origin.updateDirection(); }
/** * Extending Effect classes can use this to determine the Entity this * Effect is targeted upon. This is probably a very rare case, such as * an Effect that "links" two Entities together somehow. (Idea!) * * This may return null, even for an Effect that was set with a target Entity, * if the Entity gets GC'd. */ public Entity getTargetEntity() { return target == null ? null : target.getEntity(); }
/** * Set the Location this Effect is targeting. */ public void setDynamicTarget(DynamicLocation location) { target = location; if (target != null && targetOffset != null) { target.addOffset(targetOffset); } if (target != null) { target.setUpdateLocation(updateLocations); target.setUpdateDirection(updateDirections); } }
public void update() { if (location == null || (!updateLocation && !updateDirection)) { return; } Entity entityReference = entity == null ? null : entity.get(); if (entityReference != null) { Location currentLocation = getEntityLocation(entityReference); if (updateDirection) { setDirection(currentLocation.getDirection()); } if (updateLocation) { updateFrom(currentLocation); } } }
public void setTarget(Location location) { if (target == null) { target = new DynamicLocation(location); } else { Location targetLocation = target.getLocation(); targetLocation.setX(location.getX()); targetLocation.setY(location.getY()); targetLocation.setZ(location.getZ()); } }
protected void startProjectileEffects(CastContext context, String effectKey) { Collection<EffectPlayer> projectileEffects = context.getEffects(effectKey); for (EffectPlayer apiEffectPlayer : projectileEffects) { if (effectLocation == null) { effectLocation = new DynamicLocation(actionContext.getTargetLocation()); effectLocation.setDirection(velocity); } if (activeProjectileEffects == null) { activeProjectileEffects = new ArrayList<>(); } // Hrm- this is ugly, but I don't want the API to depend on EffectLib. if (apiEffectPlayer instanceof com.elmakers.mine.bukkit.effect.EffectPlayer) { com.elmakers.mine.bukkit.effect.EffectPlayer effectPlayer = (com.elmakers.mine.bukkit.effect.EffectPlayer)apiEffectPlayer; effectPlayer.setEffectPlayList(activeProjectileEffects); if (projectileEffectsUseTarget) { Entity sourceEntity = actionContext.getEntity(); DynamicLocation sourceLocation = sourceEntity == null ? new DynamicLocation(actionContext.getLocation()) : new DynamicLocation(sourceEntity); effectPlayer.startEffects(sourceLocation, effectLocation); } else { effectPlayer.startEffects(effectLocation, null); } } } } }
public void startEffects(DynamicLocation origin, DynamicLocation target) { Location targetLocation = target == null ? null : target.getLocation(); Location originLocation = origin == null ? null : origin.getLocation(); if (targetLocation != null && originLocation != null && !originLocation.getWorld().equals(targetLocation.getWorld())) { targetLocation.setWorld(originLocation.getWorld()); this.origin.addRelativeOffset(originRelativeOffset); this.target.addRelativeOffset(targetRelativeOffset);
@SuppressWarnings("deprecation") protected void performEffects(DynamicLocation source, DynamicLocation target) { Location sourceLocation = source == null ? null : source.getLocation(); if (sourceLocation == null) return; Entity sourceEntity = source == null ? null : source.getEntity(); if (requireEntity && sourceEntity == null) return;
if (effectLocation != null) effectLocation.updateFrom(targetLocation); if (effectLocation != null) effectLocation.updateFrom(projectileLocation); effectLocation.setDirection(velocity);
/** * Extending Effect classes should use this method to obtain the * current "target" Location of the effect. * * Unlike getLocation, this may return null. */ public final Location getTarget() { return target == null ? null : target.getLocation(); }
protected final boolean validate() { // Check if the origin and target entities are present if (disappearWithOriginEntity && (origin != null && !origin.hasValidEntity())) { return false; } if (disappearWithTargetEntity && (target != null && !target.hasValidEntity())) { return false; } // Check for a valid Location updateLocation(); updateTarget(); Location location = getLocation(); if (location == null) { return false; } if (autoOrient) { Location targetLocation = target == null ? null : target.getLocation(); if (targetLocation != null) { Vector direction = targetLocation.toVector().subtract(location.toVector()); location.setDirection(direction); targetLocation.setDirection(direction.multiply(-1)); } } return true; }
public DynamicLocation(Entity entity) { if (entity != null) { this.entity = new WeakReference<Entity>(entity); this.location = getEntityLocation(entity); } else { this.entity = null; this.location = null; } this.originalLocation = location; }
public void setOrigin(Location location) { if (origin == null) { origin = new DynamicLocation(location); } else { Location originLocation = origin.getLocation(); originLocation.setX(location.getX()); originLocation.setY(location.getY()); originLocation.setZ(location.getZ()); } }
/** * Extending Effect classes should use this method to obtain the * current "root" Location of the effect. * * This method will not return null when called from onRun. Effects * with invalid locations will be cancelled. */ public final Location getLocation() { return origin == null ? null : origin.getLocation(); }
origin.addOffset(offset); previousOffset.add(offset);
public DynamicLocation(Location location, Entity entity) { if (location != null) { this.location = location.clone(); } else if (entity != null) { this.location = getEntityLocation(entity); } else { this.location = null; } if (entity != null) { this.entity = new WeakReference<Entity>(entity); this.entityOffset = this.location.toVector().subtract(getEntityLocation(entity).toVector()); } else { this.entity = null; } this.originalLocation = this.location == null ? null : this.location.clone(); }
public void setTargetLocation(Location location) { target = new DynamicLocation(location); }
/** * Extending Effect classes can use this to determine the Entity this * Effect is centered upon. * * This may return null, even for an Effect that was set with an Entity, * if the Entity gets GC'd. */ public Entity getEntity() { return origin == null ? null : origin.getEntity(); }