use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project MagicPlugin by elBukkit.
the class CompatibilityUtils method addToWorld.
@Override
public boolean addToWorld(World world, Entity entity, CreatureSpawnEvent.SpawnReason reason) {
ServerLevel level = ((CraftWorld) world).getHandle();
net.minecraft.world.entity.Entity entityHandle = ((CraftEntity) entity).getHandle();
level.addFreshEntity(entityHandle, reason);
return true;
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelper_v1_8_R3 method hideEntity.
@Override
public void hideEntity(Player player, Entity entity, boolean keepInTabList) {
// Use Bukkit API for Player entities
if (entity instanceof Player) {
player.hidePlayer((Player) entity);
return;
}
CraftPlayer craftPlayer = (CraftPlayer) player;
EntityPlayer entityPlayer = craftPlayer.getHandle();
UUID playerUUID = player.getUniqueId();
if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity)) {
if (!hiddenEntities.containsKey(playerUUID)) {
hiddenEntities.put(playerUUID, new HashSet<UUID>());
}
Set hidden = hiddenEntities.get(playerUUID);
UUID entityUUID = entity.getUniqueId();
if (!hidden.contains(entityUUID)) {
hidden.add(entityUUID);
EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker;
net.minecraft.server.v1_8_R3.Entity other = ((CraftEntity) entity).getHandle();
EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId());
if (entry != null) {
entry.clear(entityPlayer);
}
}
}
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelper_v1_11_R1 method unhideEntity.
@Override
public void unhideEntity(Player player, Entity entity) {
// Use Bukkit API for Player entities
if (entity instanceof Player) {
player.showPlayer((Player) entity);
return;
}
CraftPlayer craftPlayer = (CraftPlayer) player;
EntityPlayer entityPlayer = craftPlayer.getHandle();
UUID playerUUID = player.getUniqueId();
if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity) && hiddenEntities.containsKey(playerUUID)) {
Set hidden = hiddenEntities.get(playerUUID);
UUID entityUUID = entity.getUniqueId();
if (hidden.contains(entityUUID)) {
hidden.remove(entityUUID);
EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker;
net.minecraft.server.v1_11_R1.Entity other = ((CraftEntity) entity).getHandle();
EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId());
if (entry != null && !entry.trackedPlayers.contains(entityPlayer)) {
entry.updatePlayer(entityPlayer);
}
}
}
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelper_v1_11_R1 method follow.
@Override
public void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander) {
if (target == null || follower == null) {
return;
}
final net.minecraft.server.v1_11_R1.Entity nmsEntityFollower = ((CraftEntity) follower).getHandle();
if (!(nmsEntityFollower instanceof EntityInsentient)) {
return;
}
final EntityInsentient nmsFollower = (EntityInsentient) nmsEntityFollower;
final NavigationAbstract 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.a(2F);
Location targetLocation = target.getLocation();
PathEntity path;
if (hasMax && !Utilities.checkLocation(targetLocation, follower.getLocation(), maxRange) && !target.isDead() && target.isOnGround()) {
if (!inRadius) {
follower.teleport(Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
} else {
inRadius = false;
path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
if (path != null) {
followerNavigation.a(path, 1D);
followerNavigation.a(2D);
}
}
} else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
if (path != null) {
followerNavigation.a(path, 1D);
followerNavigation.a(2D);
}
} else {
inRadius = true;
}
if (inRadius && !allowWander) {
followerNavigation.o();
}
nmsFollower.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
}
}.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelper_v1_11_R1 method rotate.
@Override
public void rotate(Entity entity, float yaw, float pitch) {
// it will appear to be online
if (entity instanceof Player && ((Player) entity).isOnline()) {
Location location = entity.getLocation();
location.setYaw(yaw);
location.setPitch(pitch);
entity.teleport(location);
} else if (entity instanceof LivingEntity) {
if (entity instanceof EnderDragon) {
yaw = normalizeYaw(yaw - 180);
}
look(entity, yaw, pitch);
} else {
net.minecraft.server.v1_11_R1.Entity handle = ((CraftEntity) entity).getHandle();
handle.yaw = yaw;
handle.pitch = pitch;
}
}
Aggregations