use of com.google.cloud.videointelligence.v1.Entity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method follow.
@Override
public void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander, final boolean teleport) {
if (target == null || follower == null) {
return;
}
final net.minecraft.world.entity.Entity nmsEntityFollower = ((CraftEntity) follower).getHandle();
if (!(nmsEntityFollower instanceof Mob)) {
return;
}
final Mob nmsFollower = (Mob) nmsEntityFollower;
final PathNavigation followerNavigation = nmsFollower.getNavigation();
UUID uuid = follower.getUniqueId();
if (followTasks.containsKey(uuid)) {
followTasks.get(uuid).cancel();
}
final int locationNearInt = (int) Math.floor(lead);
final boolean hasMax = maxRange > lead;
followTasks.put(follower.getUniqueId(), new BukkitRunnable() {
private boolean inRadius = false;
public void run() {
if (!target.isValid() || !follower.isValid()) {
this.cancel();
}
followerNavigation.setSpeedModifier(2D);
Location targetLocation = target.getLocation();
Path path;
if (hasMax && !Utilities.checkLocation(targetLocation, follower.getLocation(), maxRange) && !target.isDead() && target.isOnGround()) {
if (!inRadius) {
if (teleport) {
follower.teleport(Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
} else {
cancel();
}
} else {
inRadius = false;
path = followerNavigation.createPath(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
if (path != null) {
followerNavigation.moveTo(path, 1D);
followerNavigation.setSpeedModifier(2D);
}
}
} else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
path = followerNavigation.createPath(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
if (path != null) {
followerNavigation.moveTo(path, 1D);
followerNavigation.setSpeedModifier(2D);
}
} else {
inRadius = true;
}
if (inRadius && !allowWander) {
followerNavigation.stop();
}
nmsFollower.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(speed);
}
}.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
use of com.google.cloud.videointelligence.v1.Entity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method sendShowPacket.
@Override
public void sendShowPacket(Player pl, Entity entity) {
if (entity instanceof Player) {
pl.showPlayer(Denizen.getInstance(), (Player) entity);
return;
}
CraftPlayer craftPlayer = (CraftPlayer) pl;
ServerPlayer entityPlayer = craftPlayer.getHandle();
if (entityPlayer.connection != null && !craftPlayer.equals(entity)) {
ChunkMap tracker = ((ServerLevel) craftPlayer.getHandle().level).getChunkSource().chunkMap;
net.minecraft.world.entity.Entity other = ((CraftEntity) entity).getHandle();
ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
if (entry != null) {
entry.removePlayer(entityPlayer);
entry.updatePlayer(entityPlayer);
}
}
}
Aggregations