Search in sources :

Example 1 with EntityTeleportEvent

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);
    }
}
Also used : Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)

Example 2 with EntityTeleportEvent

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));
    }
}
Also used : EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Location(org.bukkit.Location)

Example 3 with EntityTeleportEvent

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));
}
Also used : EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Location(org.bukkit.Location)

Example 4 with EntityTeleportEvent

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());
    }
}
Also used : EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)

Example 5 with EntityTeleportEvent

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;
}
Also used : EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)

Aggregations

EntityTeleportEvent (org.bukkit.event.entity.EntityTeleportEvent)6 Location (org.bukkit.Location)2 List (java.util.List)1 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)1 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)1 Player (org.bukkit.entity.Player)1 PlayerTeleportEvent (org.bukkit.event.player.PlayerTeleportEvent)1