Search in sources :

Example 6 with CraftEntity

use of org.bukkit.craftbukkit.v.entity.CraftEntity in project Arclight by IzzelAliz.

the class EntityTeleportEventDispatcher method onTeleport.

@SubscribeEvent(receiveCanceled = true)
public void onTeleport(EnderTeleportEvent event) {
    if (!(event.getEntity() instanceof EndermanEntity)) {
        if (event.getEntity() instanceof ServerPlayerEntity) {
            CraftPlayer player = ((ServerPlayerEntityBridge) event.getEntity()).bridge$getBukkitEntity();
            PlayerTeleportEvent bukkitEvent = new PlayerTeleportEvent(player, player.getLocation(), new Location(player.getWorld(), event.getTargetX(), event.getTargetY(), event.getTargetZ()), PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
            Bukkit.getPluginManager().callEvent(bukkitEvent);
            event.setCanceled(bukkitEvent.isCancelled());
            event.setTargetX(bukkitEvent.getTo().getX());
            event.setTargetY(bukkitEvent.getTo().getY());
            event.setTargetZ(bukkitEvent.getTo().getZ());
        } else {
            CraftEntity entity = ((EntityBridge) event.getEntity()).bridge$getBukkitEntity();
            EntityTeleportEvent bukkitEvent = new EntityTeleportEvent(entity, entity.getLocation(), new Location(entity.getWorld(), event.getTargetX(), event.getTargetY(), event.getTargetZ()));
            Bukkit.getPluginManager().callEvent(bukkitEvent);
            event.setCanceled(bukkitEvent.isCancelled());
            event.setTargetX(bukkitEvent.getTo().getX());
            event.setTargetY(bukkitEvent.getTo().getY());
            event.setTargetZ(bukkitEvent.getTo().getZ());
        }
    }
}
Also used : EndermanEntity(net.minecraft.entity.monster.EndermanEntity) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftPlayer(org.bukkit.craftbukkit.v.entity.CraftPlayer) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) Location(org.bukkit.Location) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

CraftEntity (org.bukkit.craftbukkit.v.entity.CraftEntity)6 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)5 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 Location (org.bukkit.Location)4 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)3 Entity (net.minecraft.entity.Entity)3 EntityTeleportEvent (org.bukkit.event.entity.EntityTeleportEvent)3 InternalEntityBridge (io.izzel.arclight.common.bridge.entity.InternalEntityBridge)2 LivingEntityBridge (io.izzel.arclight.common.bridge.entity.LivingEntityBridge)2 MobEntityBridge (io.izzel.arclight.common.bridge.entity.MobEntityBridge)2 LivingEntity (net.minecraft.entity.LivingEntity)2 MobEntity (net.minecraft.entity.MobEntity)2 ItemEntity (net.minecraft.entity.item.ItemEntity)2 TameableEntity (net.minecraft.entity.passive.TameableEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 Vehicle (org.bukkit.entity.Vehicle)2 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 EndermanEntity (net.minecraft.entity.monster.EndermanEntity)1 EggEntity (net.minecraft.entity.projectile.EggEntity)1