SHARE
TWEET

Untitled

a guest May 15th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.minecraft.server;
  2.  
  3. // CraftBukkit start
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.craftbukkit.entity.CraftEnderPearl;
  7. import org.bukkit.craftbukkit.entity.CraftEntity;
  8. import org.bukkit.craftbukkit.event.CraftEventFactory;
  9. import org.bukkit.event.entity.EnderpearlLandEvent;
  10. import org.bukkit.event.player.PlayerTeleportEvent;
  11. import org.bukkit.material.Gate;
  12. import org.bukkit.util.BlockIterator;
  13. import org.bukkit.util.Vector;
  14. import org.github.paperspigot.PaperSpigotConfig;
  15. // CraftBukkit end
  16.  
  17. public class EntityEnderPearl extends EntityProjectile {
  18.  
  19.     public EntityEnderPearl (World world) {
  20.         super(world);
  21.         this.loadChunks = world.paperSpigotConfig.loadUnloadedEnderPearls; // PaperSpigot
  22.     }
  23.  
  24.     public EntityEnderPearl (World world, EntityLiving entityliving) {
  25.         super(world, entityliving);
  26.         this.loadChunks = world.paperSpigotConfig.loadUnloadedEnderPearls; // PaperSpigot
  27.     }
  28.  
  29.     protected void a (MovingObjectPosition movingobjectposition) {
  30.         Block block = this.world.getType(movingobjectposition.b, movingobjectposition.c, movingobjectposition.d);
  31.  
  32.         if (PaperSpigotConfig.enderpearlCollidesString && block == Blocks.TRIPWIRE) {
  33.             return;
  34.         }
  35.  
  36.         if (PaperSpigotConfig.enderpearlCollidesFenceGate && (block == Blocks.FENCE_GATE && BlockFenceGate.b(this.world.getData(movingobjectposition.b, movingobjectposition.c, movingobjectposition.d)))) {
  37.             BlockIterator bi = null;
  38.  
  39.             try {
  40.                 Vector l = new Vector(this.locX, this.locY, this.locZ);
  41.                 Vector l2 = new Vector(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ);
  42.                 Vector dir = new Vector(l2.getX() - l.getX(), l2.getY() - l.getY(), l2.getZ() - l.getZ()).normalize();
  43.                 bi = new BlockIterator(this.world.getWorld(), l, dir, 0, 1);
  44.             } catch (IllegalStateException e) {
  45.                 // Do nothing
  46.             }
  47.  
  48.             if (bi != null) {
  49.                 boolean open = true;
  50.                 while (bi.hasNext()) {
  51.                     org.bukkit.block.Block b = bi.next();
  52.                     if (b.getState().getData() instanceof Gate && !((Gate) b.getState().getData()).isOpen()) {
  53.                         open = false;
  54.                         break;
  55.                     }
  56.                 }
  57.                 if (open) {
  58.                     return;
  59.                 }
  60.             }
  61.         }
  62.  
  63.  
  64.         if (movingobjectposition.entity != null) {
  65.             movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.getShooter()), 0.0F);
  66.         }
  67.  
  68.         // PaperSpigot start - Remove entities in unloaded chunks
  69.         if (inUnloadedChunk && world.paperSpigotConfig.removeUnloadedEnderPearls) {
  70.             die();
  71.         }
  72.         // PaperSpigot end
  73.  
  74.         for (int i = 0; i < 32; ++i) {
  75.             this.world.addParticle("portal", this.locX, this.locY + this.random.nextDouble() * 2.0D, this.locZ, this.random.nextGaussian(), 0.0D, this.random.nextGaussian());
  76.         }
  77.  
  78.         if (!this.world.isStatic) {
  79.             if (this.getShooter() != null && this.getShooter() instanceof EntityPlayer) {
  80.                 EntityPlayer entityplayer = (EntityPlayer) this.getShooter();
  81.  
  82.                 if (entityplayer.playerConnection.b().isConnected() && entityplayer.world == this.world) {
  83.                     // CraftBukkit start - Fire PlayerTeleportEvent
  84.                     org.bukkit.craftbukkit.entity.CraftPlayer player = entityplayer.getBukkitEntity();
  85.  
  86.                     EnderpearlLandEvent.Reason reason = movingobjectposition.entity != null ? EnderpearlLandEvent.Reason.ENTITY : EnderpearlLandEvent.Reason.BLOCK;
  87.                     //EnderpearlLandEvent landEvent = new EnderpearlLandEvent((CraftEnderPearl) getBukkitEntity(), reason);
  88.                     CraftEntity bukkitHitEntity = movingobjectposition.entity != null ? movingobjectposition.entity.getBukkitEntity() : null; //TODO: Custom fix
  89.                     EnderpearlLandEvent landEvent = new EnderpearlLandEvent((CraftEnderPearl) getBukkitEntity(), reason, bukkitHitEntity);
  90.  
  91.                     Bukkit.getPluginManager().callEvent(landEvent);
  92.  
  93.                     if (landEvent.isCancelled()) {
  94.                         this.die();
  95.                         return;
  96.                     }
  97.  
  98.  
  99.                     org.bukkit.Location location = getBukkitEntity().getLocation();
  100.                     location.setPitch(player.getLocation().getPitch());
  101.                     location.setYaw(player.getLocation().getYaw());
  102.  
  103.                     PlayerTeleportEvent teleEvent = new PlayerTeleportEvent(player, player.getLocation(), location, PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
  104.                     Bukkit.getPluginManager().callEvent(teleEvent);
  105.  
  106.                     if (!teleEvent.isCancelled() && !entityplayer.playerConnection.isDisconnected()) {
  107.                         if (this.getShooter().am()) {
  108.                             this.getShooter().mount((Entity) null);
  109.                         }
  110.  
  111.                         entityplayer.playerConnection.teleport(teleEvent.getTo());
  112.                         this.getShooter().fallDistance = 0.0F;
  113.                         CraftEventFactory.entityDamage = this;
  114.                         this.getShooter().damageEntity(DamageSource.FALL, 5.0F);
  115.                         CraftEventFactory.entityDamage = null;
  116.                     }
  117.                     // CraftBukkit end
  118.                 }
  119.             }
  120.  
  121.             this.die();
  122.         }
  123.     }
  124. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top