use of org.bukkit.event.entity.EntityTeleportEvent in project Denizen-For-Bukkit by DenizenScript.
the class TeleportCommand method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
dLocation location = (dLocation) scriptEntry.getObject("location");
List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
// Report to dB
dB.report(scriptEntry, getName(), aH.debugObj("location", location) + aH.debugObj("entities", entities.toString()));
for (dEntity entity : entities) {
// world event and other plugins
if (entity.isSpawned()) {
if (entity.getBukkitEntityType() != EntityType.PLAYER) {
Bukkit.getPluginManager().callEvent(new EntityTeleportEvent(entity.getBukkitEntity(), entity.getLocation(), location));
} else {
Bukkit.getPluginManager().callEvent(new PlayerTeleportEvent((Player) entity.getBukkitEntity(), entity.getLocation(), location));
}
}
entity.spawnAt(location);
}
}
use of org.bukkit.event.entity.EntityTeleportEvent in project InfernalMobs by NyaaCat.
the class AbilityEnder method onPlayerAttack.
@Override
public void onPlayerAttack(LivingEntity mobEntity, Mob mob, Player attacker, boolean isDirectAttack, EntityDamageByEntityEvent ev) {
if (mobEntity.isInsideVehicle())
return;
if (!isDirectAttack) {
if (Helper.possibility(0.5))
return;
EntityTeleportEvent event = new EntityTeleportEvent(mobEntity, mobEntity.getLocation(), attacker.getLocation());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
mobEntity.teleport(attacker.getLocation());
} else if (Helper.possibility(0.2)) {
double x = mobEntity.getLocation().getX() + Helper.rand(-5D, 5D);
double z = mobEntity.getLocation().getZ() + Helper.rand(-5D, 5D);
double y = mobEntity.getWorld().getHighestBlockYAt((int) x, (int) z) + 1;
EntityTeleportEvent event = new EntityTeleportEvent(mobEntity, mobEntity.getLocation(), new Location(mobEntity.getWorld(), x, y, z));
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
mobEntity.teleport(new Location(mobEntity.getWorld(), x, y, z));
}
}
use of org.bukkit.event.entity.EntityTeleportEvent in project InfernalMobs by NyaaCat.
the class AbilityEnder method onPlayerAttack.
@Override
public void onPlayerAttack(LivingEntity mobEntity, Mob mob, Player attacker, boolean isDirectAttack, EntityDamageByEntityEvent ev) {
if (mobEntity.isInsideVehicle())
return;
if (!isDirectAttack) {
if (Helper.possibility(0.5))
return;
} else if (Helper.possibility(0.8))
return;
double x = attacker.getLocation().getX() + Helper.rand(-5D, 5D);
double z = attacker.getLocation().getZ() + Helper.rand(-5D, 5D);
double y = attacker.getWorld().getHighestBlockYAt((int) x, (int) z) + 1;
Location to = new Location(mobEntity.getWorld(), x, y, z);
EntityTeleportEvent event = new EntityTeleportEvent(mobEntity, mobEntity.getLocation(), to);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
mobEntity.teleport(new Location(mobEntity.getWorld(), x, y, z));
}
use of org.bukkit.event.entity.EntityTeleportEvent in project InfernalMobs by NyaaCat.
the class AbilityEnder method onAttackPlayer.
@Override
public void onAttackPlayer(LivingEntity mobEntity, Mob mob, Player victim, boolean isDirectAttack, EntityDamageByEntityEvent ev) {
if (mobEntity.isInsideVehicle() || Helper.possibility(0.5))
return;
if (!isDirectAttack) {
EntityTeleportEvent event = new EntityTeleportEvent(mobEntity, mobEntity.getLocation(), victim.getLocation());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
mobEntity.teleport(victim.getLocation());
}
}
use of org.bukkit.event.entity.EntityTeleportEvent in project Glowstone by GlowstoneMC.
the class GlowEntity method teleport.
// //////////////////////////////////////////////////////////////////////////
// Internals
@Override
public boolean teleport(Location location) {
if (!(this instanceof GlowPlayer)) {
// TODO: Properly test when Enderman teleportation is implemented.
EntityTeleportEvent event = EventFactory.getInstance().callEvent(new EntityTeleportEvent(this, getLocation(), location));
if (event.isCancelled()) {
return false;
}
location = event.getTo();
}
checkNotNull(location, "location cannot be null");
checkNotNull(location.getWorld(), "location's world cannot be null");
worldLock.writeLock().lock();
try {
if (location.getWorld() != world) {
world.getEntityManager().unregister(this);
world = (GlowWorld) location.getWorld();
world.getEntityManager().register(this);
}
} finally {
worldLock.writeLock().unlock();
}
setRawLocation(location, false);
teleported = true;
return true;
}
Aggregations