Advertisement
Guest User

FishingHook

a guest
Apr 30th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.47 KB | None | 0 0
  1. package me.filipenock.Addon.Habilidades;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
  6. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
  7. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSnowball;
  8. import org.bukkit.entity.Entity;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.entity.Snowball;
  11. import org.bukkit.util.Vector;
  12.  
  13. import net.minecraft.server.v1_8_R3.EntityFishingHook;
  14. import net.minecraft.server.v1_8_R3.EntityHuman;
  15. import net.minecraft.server.v1_8_R3.EntitySnowball;
  16. import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
  17. import net.minecraft.server.v1_8_R3.PlayerConnection;
  18.  
  19. public class CopyOfFishingHook extends EntityFishingHook {
  20.    
  21.     private Snowball sb;
  22.     private EntitySnowball controller;
  23.     public int a;
  24.     public EntityHuman owner;
  25.     public Entity hooked;
  26.     public boolean lastControllerDead;
  27.     public boolean isHooked;
  28.     public static Vector moveTo(Location entity, Location target, double defaultX, double defaultY, double defaultZ,
  29.             double addX, double addY, double addZ) {
  30.         double distance = target.distance(entity);
  31.         double x = (defaultX + (addX * distance)) * ((target.getX() - entity.getX()) / distance);
  32.         double y = (defaultY + (addY * distance)) * ((target.getY() - entity.getY()) / distance);
  33.         double z = (defaultZ + (addZ * distance)) * ((target.getZ() - entity.getZ()) / distance);
  34.         return new Vector(x, y, z);
  35.  
  36.     }
  37.     public CopyOfFishingHook(Player p,double force) {
  38.         super(((CraftPlayer) p).getHandle().getWorld(), ((CraftPlayer) p).getHandle());
  39.         owner = ((CraftPlayer) p).getHandle();
  40.         Location location = p.getEyeLocation();
  41.         sb = ((Snowball) p.launchProjectile(Snowball.class));
  42.         controller = ((CraftSnowball) sb).getHandle();
  43.         this.sb.setVelocity(location.getDirection().multiply(force));
  44.         PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] { controller.getId() });
  45.  
  46.         for (Player player : Bukkit.getOnlinePlayers()) {
  47.             try {
  48.                 try {
  49.                     PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
  50.                     connection.sendPacket(packet);
  51.                 } catch (Exception ex) {
  52.                 }
  53.             } catch (Exception ex) {
  54.             }
  55.         }
  56.         ((CraftWorld) location.getWorld()).getHandle().addEntity(this);
  57.  
  58.     }
  59.  
  60.     public void spawn(Location location) {
  61.  
  62.     }
  63.  
  64.     protected void c() {
  65.     }
  66.  
  67.     public void h() {
  68.         lastControllerDead = controller.dead;
  69.         for (Entity entity : controller.world.getWorld().getEntities()) {
  70.             if ((!(entity instanceof org.bukkit.entity.Firework))
  71.                     && (entity.getEntityId() != getBukkitEntity().getEntityId())
  72.                     && (entity.getEntityId() != owner.getBukkitEntity().getEntityId())
  73.                     && (entity.getEntityId() != controller.getBukkitEntity().getEntityId())
  74.                     && ((entity.getLocation().distance(controller.getBukkitEntity().getLocation()) < 2.0D)
  75.                             || (((entity instanceof Player)) && (((Player) entity).getEyeLocation()
  76.                                     .distance(controller.getBukkitEntity().getLocation()) < 2.0D)))) {
  77.                 controller.die();
  78.                 hooked = entity;
  79.                 isHooked = true;
  80.                 locX = entity.getLocation().getX();
  81.                 locY = entity.getLocation().getY();
  82.                 locZ = entity.getLocation().getZ();
  83.                 motX = 0.0D;
  84.                 motY = 0.04D;
  85.                 motZ = 0.0D;
  86.             }
  87.         }
  88.         try {
  89.             locX = hooked.getLocation().getX();
  90.             locY = hooked.getLocation().getY();
  91.             locZ = hooked.getLocation().getZ();
  92.             motX = 0.0D;
  93.             motY = 0.04D;
  94.             motZ = 0.0D;
  95.             isHooked = true;
  96.         } catch (Exception e) {
  97.             if (controller.dead) {
  98.                 isHooked = true;
  99.             }
  100.             locX = controller.locX;
  101.             locY = controller.locY;
  102.             locZ = controller.locZ;
  103.         }
  104.     }
  105.  
  106.     public void die() {
  107.     }
  108.  
  109.     public void remove() {
  110.         super.die();
  111.     }
  112.  
  113.     public boolean isHooked() {
  114.         return isHooked;
  115.     }
  116.  
  117.     public void setHookedEntity(Entity damaged) {
  118.         hooked = damaged;
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement