use of org.bukkit.entity.LivingEntity in project Citizens2 by CitizensDev.
the class CitizensNavigator method setTarget.
@Override
public void setTarget(Location target) {
if (!npc.isSpawned())
throw new IllegalStateException("npc is not spawned");
if (target == null) {
cancelNavigation();
return;
}
switchParams();
updatePathfindingRange();
PathStrategy newStrategy;
if (npc.isFlyable()) {
newStrategy = new FlyingAStarNavigationStrategy(npc, target, localParams);
} else if (localParams.useNewPathfinder() || !(npc.getEntity() instanceof LivingEntity)) {
newStrategy = new AStarNavigationStrategy(npc, target, localParams);
} else {
newStrategy = new MCNavigationStrategy(npc, target, localParams);
}
switchStrategyTo(newStrategy);
}
use of org.bukkit.entity.LivingEntity in project Citizens2 by CitizensDev.
the class CitizensNavigator method setTarget.
@Override
public void setTarget(Iterable<Vector> path) {
if (!npc.isSpawned())
throw new IllegalStateException("npc is not spawned");
if (path == null || Iterables.size(path) == 0) {
cancelNavigation();
return;
}
switchParams();
updatePathfindingRange();
PathStrategy newStrategy;
if (npc.isFlyable()) {
newStrategy = new FlyingAStarNavigationStrategy(npc, path, localParams);
} else if (localParams.useNewPathfinder() || !(npc.getEntity() instanceof LivingEntity)) {
newStrategy = new AStarNavigationStrategy(npc, path, localParams);
} else {
newStrategy = new MCNavigationStrategy(npc, path, localParams);
}
switchStrategyTo(newStrategy);
}
use of org.bukkit.entity.LivingEntity in project Citizens2 by CitizensDev.
the class MCTargetStrategy method update.
@Override
public boolean update() {
if (target == null || !target.isValid()) {
cancelReason = CancelReason.TARGET_DIED;
return true;
}
if (target.getWorld() != handle.getWorld()) {
cancelReason = CancelReason.TARGET_MOVED_WORLD;
return true;
}
if (cancelReason != null) {
return true;
}
if (!aggro && distanceSquared() <= parameters.distanceMargin()) {
stop();
return false;
} else if (updateCounter == -1 || updateCounter++ > parameters.updatePathRate()) {
targetNavigator.setPath();
updateCounter = 0;
}
targetNavigator.update();
NMS.look(handle, target);
if (aggro && canAttack()) {
AttackStrategy strategy = parameters.attackStrategy();
if (strategy != null && strategy.handle((LivingEntity) handle, (LivingEntity) getTarget())) {
} else if (strategy != parameters.defaultAttackStrategy()) {
parameters.defaultAttackStrategy().handle((LivingEntity) handle, (LivingEntity) getTarget());
}
attackTicks = parameters.attackDelayTicks();
}
if (attackTicks > 0) {
attackTicks--;
}
return false;
}
use of org.bukkit.entity.LivingEntity in project Citizens2 by CitizensDev.
the class Controllable method loadController.
private void loadController() {
EntityType type = npc.getEntity().getType();
if (explicitType != null) {
type = explicitType;
}
if (!(npc.getEntity() instanceof LivingEntity) && (explicitType == null || explicitType == EntityType.UNKNOWN || npc.getEntity().getType() == explicitType)) {
controller = new LookAirController();
return;
}
Class<? extends MovementController> clazz = controllerTypes.get(type);
if (clazz == null) {
controller = new GroundController();
return;
}
Constructor<? extends MovementController> innerConstructor = null;
try {
innerConstructor = clazz.getConstructor(Controllable.class);
innerConstructor.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
try {
if (innerConstructor == null) {
controller = clazz.newInstance();
} else {
controller = innerConstructor.newInstance(this);
}
} catch (Exception e) {
e.printStackTrace();
controller = new GroundController();
}
}
use of org.bukkit.entity.LivingEntity in project Citizens2 by CitizensDev.
the class NMSImpl method setHeadYaw.
@Override
public void setHeadYaw(org.bukkit.entity.Entity entity, float yaw) {
if (!(entity instanceof LivingEntity))
return;
EntityLiving handle = (EntityLiving) getHandle(entity);
yaw = Util.clampYaw(yaw);
handle.aP = yaw;
if (!(handle instanceof EntityHuman))
handle.aO = yaw;
handle.aQ = yaw;
}
Aggregations